If the bot function logs itself in, the user won't be able to use any functionality from the CommandsProcessor.
As such we can't get the list of commands, and the structure of the bot becomes inside-out (restricted to event handling).
One of the use-case of this (not automatically logging in) could be listen for MessageCreateEvent/MessageUpdateEvent and filter out the messages which does not contains the command in it. To filter this, one need reference to CommandsProcessor.commands and CommandsProcessor.prefix but it is impossible to do so with the bot function.
(creating bot with BotBuilder manually instead of bot() function is an option, but it will create noise in the code).
Suggested Solution
Change the bot function signature (not backward compatible):
/**
* Creates a bot with the given [kord] instance, applying [configure] to the bot's configuration.
*/
suspend inline fun bot(kord: Kord, configure: KordProcessorBuilder.() -> Unit): CommandProcessor =
BotBuilder(kord).apply { processorBuilder.configure() }.build()
Doing this we can't assure the backward compatibility with the older function, but as this library wasn't stable and used much as of now we shall change the method signature.
Deprecate the current function and define new which can optionally login:
@Deprecated(
message = "Use bot(kord, login, configure) instead.",
replaceWith = ReplaceWith("bot(kord, login = true, configure)"),
level = DeprecationLevel.WARNING
)
suspend inline fun bot(kord: Kord, configure: KordProcessorBuilder.() -> Unit) {
bot(kord, true, configure)
}
suspend inline fun bot(
kord: Kord,
login: Boolean,
configure: KordProcessorBuilder.() -> Unit
): CommandProcessor =
BotBuilder(kord)
.apply { processorBuilder.configure() }
.build()
.also { if (login) kord.login() }
Description of problem
If the bot function logs itself in, the user won't be able to use any functionality from the CommandsProcessor. As such we can't get the list of commands, and the structure of the bot becomes inside-out (restricted to event handling).
One of the use-case of this (not automatically logging in) could be listen for MessageCreateEvent/MessageUpdateEvent and filter out the messages which does not contains the command in it. To filter this, one need reference to CommandsProcessor.commands and CommandsProcessor.prefix but it is impossible to do so with the bot function. (creating bot with BotBuilder manually instead of bot() function is an option, but it will create noise in the code).
Suggested Solution
Change the bot function signature (not backward compatible):
Doing this we can't assure the backward compatibility with the older function, but as this library wasn't stable and used much as of now we shall change the method signature.
Deprecate the current function and define new which can optionally login: