diff --git a/API/generate_wrappers.rb b/API/generate_wrappers.rb index 2fa6b1b..4d296b9 100755 --- a/API/generate_wrappers.rb +++ b/API/generate_wrappers.rb @@ -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" @@ -485,7 +490,6 @@ def main } } - puts 'Finished' end diff --git a/Sources/Telegrammer/Bot/Methods/Bot+setWebhook.swift b/Sources/Telegrammer/Bot/Methods/Bot+setWebhook.swift index 5f4cdf4..d57c8b7 100644 --- a/Sources/Telegrammer/Bot/Methods/Bot+setWebhook.swift +++ b/Sources/Telegrammer/Bot/Methods/Bot+setWebhook.swift @@ -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/. 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 diff --git a/Sources/Telegrammer/Dispatcher/Dispatcher.swift b/Sources/Telegrammer/Dispatcher/Dispatcher.swift index a31ed9b..5385f0b 100644 --- a/Sources/Telegrammer/Dispatcher/Dispatcher.swift +++ b/Sources/Telegrammer/Dispatcher/Dispatcher.swift @@ -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 @@ -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, diff --git a/Sources/Telegrammer/Dispatcher/HandlersQueue.swift b/Sources/Telegrammer/Dispatcher/HandlersQueue.swift index 5b34e83..ba63235 100644 --- a/Sources/Telegrammer/Dispatcher/HandlersQueue.swift +++ b/Sources/Telegrammer/Dispatcher/HandlersQueue.swift @@ -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]] { @@ -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(_ handler: T, to group: HandlerGroup) { concurrentQueue.async(flags: .barrier) { diff --git a/Sources/Telegrammer/Filters/Filter.swift b/Sources/Telegrammer/Filters/Filter.swift index 6f8ad62..6eb8c48 100644 --- a/Sources/Telegrammer/Filters/Filter.swift +++ b/Sources/Telegrammer/Filters/Filter.swift @@ -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 { diff --git a/Sources/Telegrammer/Handlers/CommandHandler.swift b/Sources/Telegrammer/Handlers/CommandHandler.swift index 5ef4396..1421e67 100644 --- a/Sources/Telegrammer/Handlers/CommandHandler.swift +++ b/Sources/Telegrammer/Handlers/CommandHandler.swift @@ -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 @@ -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) } diff --git a/Sources/Telegrammer/Handlers/Handler.swift b/Sources/Telegrammer/Handlers/Handler.swift index e5e2d2e..5da7cf8 100644 --- a/Sources/Telegrammer/Handlers/Handler.swift +++ b/Sources/Telegrammer/Handlers/Handler.swift @@ -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 } diff --git a/Sources/Telegrammer/Updater/Updater.swift b/Sources/Telegrammer/Updater/Updater.swift index 6ae7108..a34a307 100644 --- a/Sources/Telegrammer/Updater/Updater.swift +++ b/Sources/Telegrammer/Updater/Updater.swift @@ -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