Skip to content

Commit

Permalink
Generated new doc from server
Browse files Browse the repository at this point in the history
Added docs for: CommandHandler, Dispatcher, Filters, Handler, Updater
Updated queues names
  • Loading branch information
givip committed Jun 17, 2018
1 parent fe94781 commit efed948
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 10 deletions.
8 changes: 6 additions & 2 deletions API/generate_wrappers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ def generate_model_file(f, node)

current_node = current_node.next_element
description, current_node = fetch_description(current_node)

puts '################# Desciption'
puts description
puts '////################# Desciption'
puts '################# Curren Node'
puts current_node
puts '////################# Curren Node'
f.write "DESCRIPTION:\n#{description}\n"
description.each_line { |line|
out.write "/// #{line.strip}\n"
Expand Down Expand Up @@ -485,7 +490,6 @@ def main
}
}


puts 'Finished'
end

Expand Down
2 changes: 1 addition & 1 deletion Sources/Telegrammer/Bot/Methods/Bot+setWebhook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import HTTP

public extension Bot {

/// Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns true.
/// Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success.
/// If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else knows your bot‘s token, you can be pretty sure it’s us.
/// - Parameters:
/// - url: HTTPS url to send updates to. Use an empty string to remove webhook integration
Expand Down
6 changes: 5 additions & 1 deletion Sources/Telegrammer/Dispatcher/Dispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import HeliumLogger
import LoggerAPI
import HTTP

/**
This class dispatches all kinds of updates to its registered handlers.
It supports handlers for different kinds of data: Updates from Telegram, basic text commands and even arbitrary types.
*/
public class Dispatcher {

public let bot: Bot
Expand All @@ -21,7 +25,7 @@ public class Dispatcher {
public init(bot: Bot, worker: Worker = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)) {
self.bot = bot
self.worker = worker
self.updateQueue = DispatchQueue(label: "UPDATES-QUEUE",
self.updateQueue = DispatchQueue(label: "TLGRM-UPDATES-QUEUE",
qos: .default,
attributes: .concurrent,
autoreleaseFrequency: .inherit,
Expand Down
12 changes: 7 additions & 5 deletions Sources/Telegrammer/Dispatcher/HandlersQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import Foundation

/// Sorted by priority Handlers Queue
/// queue is thread safe, you can read, add and remove from any threads.
/// Note, that operations of adding/removing handlers to/from queue
/// will perform after all pending read operations finished
/**
Sorted by priority Handlers Queue
queue is thread safe, you can read, add and remove from any threads.
Note, that operations of adding/removing handlers to/from queue
will perform after all pending read operations finished
*/
public final class HandlersQueue {

public var handlers: [HandlerGroup: [Handler]] {
Expand All @@ -32,7 +34,7 @@ public final class HandlersQueue {
private var _handlersGroup: [[Handler]] = []
private var _errorHandlers: [ErrorHandler] = []

private let concurrentQueue = DispatchQueue(label: "Telegrammer Handlers Queue", attributes: .concurrent)
private let concurrentQueue = DispatchQueue(label: "TLGRM-HANDLERS-QUEUE", attributes: .concurrent)

public func add<T: Handler>(_ handler: T, to group: HandlerGroup) {
concurrentQueue.async(flags: .barrier) {
Expand Down
26 changes: 26 additions & 0 deletions Sources/Telegrammer/Filters/Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,37 @@

import Foundation


///Base protocol for atomic filter
public protocol Filter {
var name: String { get }
func filter(message: Message) -> Bool
}

/**
Class cluster for all filters.
Filters may be combined using bitwise operators:
- And:
````
(Filters.text && Filters.entity([.mention]))
````
- Or:
````
(Filters.audio || Filters.video)
````
- Not:
````
!Filters.command
````
Also works with more than two filters:
````
(Filters.text && (Filters.entity([.url, .mention]) || Filters.entity([.command])))
(Filters.text && !Filters.forwarded)
````
If you want to create your own filters create a struct conforming `Filter` protocol and implement a `filter` method that returns a boolean: `true`, if the message should be handled, `false` otherwise.
*/
public class Filters {

private enum Operation {
Expand Down
11 changes: 10 additions & 1 deletion Sources/Telegrammer/Handlers/CommandHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@

import HTTP

/**
Handler class to handle Telegram commands.
Commands are Telegram messages that start with /, optionally followed by an @ and the bot’s name
and/or some additional text.
- Options of this handler
- `editedUpdates` Determines whether the handler should also accept edited messages.
*/
public class CommandHandler: Handler {
public var name: String

Expand All @@ -17,7 +27,6 @@ public class CommandHandler: Handler {
self.rawValue = rawValue
}

///Determines whether the handler should also accept edited messages.
public static let editedUpdates = Options(rawValue: 1)
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/Telegrammer/Handlers/Handler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public protocol BotContext { }

public typealias HandlerCallback = (_ update: Update, _ context: BotContext?) throws -> Void

/**
Protocol for any update handler
Every handler must implement `check` and `handle` methods
*/
public protocol Handler {
var name: String { get }

Expand Down
6 changes: 6 additions & 0 deletions Sources/Telegrammer/Updater/Updater.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
import HTTP
import NIO

/**
This class purpose is to receive the updates from Telegram and to deliver them to said dispatcher.
It also runs in a separate thread, so the user can interact with the bot.
The updater can be started as a polling service or, for production, use a webhook to receive updates.
This is achieved using the Webhooks and Longpolling classes.
*/
public final class Updater {

public let bot: Bot
Expand Down

0 comments on commit efed948

Please sign in to comment.