Browse Source

And it's done!

Python 2 **can** keep using disco, because `disco.util.runner`
shouldn't be automatically imported.

Changelog:
+ Added two keys to the config.
    `commands_prefix_getter`
    `commands_prefix`
+ Added documentation.
+ Added a new utility file, `disco.util.runner`
pull/160/head
A5rocks 6 years ago
parent
commit
dd41abd298
  1. 10
      disco/bot/bot.py
  2. 2
      docs/bot_tutorial/programmatic_running.md

10
disco/bot/bot.py

@ -49,6 +49,9 @@ class BotConfig(Config):
commands_prefixes : list[string]
A list of string prefixes that are required for a message to be considered
for command parsing.
commands_prefix_getter : Optional[function]
A function which takes in a message object and returns an array of strings
(prefixes).
commands_allow_edit : bool
If true, the bot will re-parse an edited message if it was the last sent
message in a channel, and did not previously trigger a command. This is
@ -92,6 +95,7 @@ class BotConfig(Config):
}
commands_prefix = ''
commands_prefixes = []
commands_prefix_getter = None
commands_allow_edit = True
commands_level_getter = None
commands_group_abbrev = True
@ -243,7 +247,7 @@ class Bot(LoggingClass):
Computes all possible abbreviations for a command grouping.
"""
# For the first pass, we just want to compute each groups possible
# abbreviations that don't conflict with eachother.
# abbreviations that don't conflict with each other.
possible = {}
for group in groups:
for index in range(1, len(group)):
@ -407,12 +411,14 @@ class Bot(LoggingClass):
bool
Whether any commands where successfully triggered by the message.
"""
custom_message_prefixes = self.config.commands_prefix_getter(msg) if self.config.commands_prefix_getter else []
commands = list(self.get_commands_for_message(
self.config.commands_require_mention,
self.config.commands_mention_rules,
self.config.commands_prefix,
msg,
self.config.commands_prefixes,
self.config.commands_prefixes + custom_message_prefixes,
))
if not len(commands):

2
docs/bot_tutorial/programmatic_running.md

@ -52,7 +52,7 @@ def prefix_getter(message):
bot = runner.bot_creator({
'token': TOKEN,
'bot': {
'prefix_getter': prefix_getter,
'commands_prefix_getter': prefix_getter,
'require_mention': False,
'plugins': ['plugins.tutorial'] # this can be anything
}

Loading…
Cancel
Save