Closed GiacomoLeopizzi closed 1 year ago
Thanks, I need some time to check all the changes. I will do this during off hours
@nerzh No problem! In my fork I made other two changes that perhaps might be interesting for you:
PatternCommandHandler
which allows to handle commands by using a pattern. A possible use is for creating the command used by the @music Telegram bot to download classical music pieces;public enum Connection {
case longPool(limit: Int? = nil, timeout: Int? = nil, allowedUpdates: [TGUpdate.CodingKeys]? = nil)
case webhook(uri: URI)
case custom(TGConnectionPrtcl)
}
This way instead of using
let connection = TGLongPollingConnection(app: app)
app.telegram.configuration = .init(connection: connection, botId: tgApi)
Is it possible to setup everything simply by doing
app.telegram.configuration = .init(connection: .longPool(), botId: tgApi)
Also please decide about the TGHandlerCallback
.
Temporarily, I defined it as:
public typealias TGHandlerCallback = (_ update: TGUpdate, _ bot: TGBotPrtcl) async throws -> Void
This way the callback might throw an error that technically is not handled (it is just printed to console), as the following snippets shows.
public func handle(update: TGUpdate, bot: TGBotPrtcl) async {
do {
try await callback(update, bot)
} catch {
TGBot.log.error(error.logMessage)
}
}
Two possible solutions, might be:
Defining TGHandlerCallback
as
public typealias TGHandlerCallback = (_ update: TGUpdate, _ bot: TGBotPrtcl) async -> Void
forcing the developers to handle throwing functions inside their definition of TGHandlerCallback
.
Leaving TGHandlerCallback
as it is, and adding a variable to TGBotPrtcl
to handle all the errors that are not handled in the callback. The new variable might be defined as:
var onError: ((Error) -> Void)? { get set }
Hello, there are a lot of changes in your pull request with which i agree and some i don't. If they were parts, then I would gladly accept some of them. Also, in your pull request, not all parts of the app were migrated to the new concurrency model. I really appreciate your contribution, but unfortunately I can not accept it. I updated the library a bit and added what users asked me about. I followed your advice and moved the logic to the NIO event loop for the dispatcher #9. If you make contributions in the future, please do it in parts, as it is easier to accept and, most importantly, it is easier to understand changes.
Dear Maintainers,
As you can see from the README examples, I'm sending a pull request that introduces the following:
app.telegram
).I would personally suggest, if you accept my pull request, to start a new major release (2.0.0), considering that because of point 1, the code is not compatible with the previous version.
Kind regards, Giacomo