[V3 Core] Mentionable prefix (#1256)

* allow mentioning the bot as a fallback to a prefix

* make this toggleable
This commit is contained in:
Michael H 2018-01-23 18:43:51 -05:00 committed by Tobotimus
parent 55bbbe6268
commit 1b45397e67
2 changed files with 13 additions and 3 deletions

View File

@ -9,6 +9,7 @@ from pathlib import Path
import discord import discord
from discord.ext.commands.bot import BotBase from discord.ext.commands.bot import BotBase
from discord.ext.commands import GroupMixin from discord.ext.commands import GroupMixin
from discord.ext.commands import when_mentioned_or
from .cog_manager import CogManager from .cog_manager import CogManager
from . import ( from . import (
@ -76,7 +77,12 @@ class RedBase(BotBase, RpcMethodMixin):
if message.guild is None: if message.guild is None:
return global_prefix return global_prefix
server_prefix = await bot.db.guild(message.guild).prefix() server_prefix = await bot.db.guild(message.guild).prefix()
return server_prefix if server_prefix else global_prefix if cli_flags.mentionable:
return when_mentioned_or(*server_prefix)(bot, message) \
if server_prefix else \
when_mentioned_or(*global_prefix)(bot, message)
else:
return server_prefix if server_prefix else global_prefix
if "command_prefix" not in kwargs: if "command_prefix" not in kwargs:
kwargs["command_prefix"] = prefix_manager kwargs["command_prefix"] = prefix_manager

View File

@ -105,6 +105,10 @@ def parse_cli_flags(args):
parser.add_argument("--dev", parser.add_argument("--dev",
action="store_true", action="store_true",
help="Enables developer mode") help="Enables developer mode")
parser.add_argument("--mentionable",
action="store_true",
help="Allows mentioning the bot as an alternative "
"to using the bot prefix")
parser.add_argument("--rpc", parser.add_argument("--rpc",
action="store_true", action="store_true",
help="Enables the built-in RPC server. Please read the docs" help="Enables the built-in RPC server. Please read the docs"