Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

The bot function should not login itself to the gateway. #23

Open
Animeshz opened this issue Nov 15, 2020 · 0 comments
Open

The bot function should not login itself to the gateway. #23

Animeshz opened this issue Nov 15, 2020 · 0 comments

Comments

@Animeshz
Copy link

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):

    /**
     * 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() }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant