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

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

Description

@Animeshz

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() }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions