[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 (
@ -40,7 +41,7 @@ class RedBase(BotBase, RpcMethodMixin):
This exists because `Red` inherits from `discord.AutoShardedClient`, which This exists because `Red` inherits from `discord.AutoShardedClient`, which
is something other bot classes (namely selfbots) may not want to have as is something other bot classes (namely selfbots) may not want to have as
a parent class. a parent class.
Selfbots should inherit from this mixin along with `discord.Client`. Selfbots should inherit from this mixin along with `discord.Client`.
""" """
def __init__(self, cli_flags, bot_dir: Path=Path.cwd(), **kwargs): def __init__(self, cli_flags, bot_dir: Path=Path.cwd(), **kwargs):
@ -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
@ -236,7 +242,7 @@ class Red(RedBase, discord.AutoShardedClient):
""" """
async def shutdown(self, *, restart: bool=False): async def shutdown(self, *, restart: bool=False):
"""Gracefully quit Red. """Gracefully quit Red.
The program will exit with code :code:`0` by default. The program will exit with code :code:`0` by default.
Parameters Parameters

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"