diff --git a/core/__init__.py b/core/__init__.py index f3b61d575..e69de29bb 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1,5 +0,0 @@ -from .owner import Owner - - -def setup(bot): - bot.add_cog(Owner()) \ No newline at end of file diff --git a/core/owner.py b/core/core_commands.py similarity index 56% rename from core/owner.py rename to core/core_commands.py index c066fd033..442dcb1d8 100644 --- a/core/owner.py +++ b/core/core_commands.py @@ -1,8 +1,6 @@ from discord.ext import commands from core import checks -from core.utils.chat_formatting import box import logging -import asyncio import importlib import os import discord @@ -10,8 +8,8 @@ import discord log = logging.getLogger("red") -class Owner: - """All owner-only commands that relate to debug bot operations.""" +class Core: + """Commands related to core functions""" @commands.command() @checks.is_owner() @@ -75,59 +73,3 @@ class Owner: print("Reloading " + path) m = importlib.import_module(path) importlib.reload(m) - - @commands.command(hidden=True) - @checks.is_owner() - async def debug(self, ctx, *, code): - """Evaluates code""" - author = ctx.message.author - channel = ctx.message.channel - - code = code.strip('` ') - result = None - - global_vars = globals().copy() - global_vars['bot'] = ctx.bot - global_vars['ctx'] = ctx - global_vars['message'] = ctx.message - global_vars['author'] = ctx.message.author - global_vars['channel'] = ctx.message.channel - global_vars['guild'] = ctx.message.guild - - try: - result = eval(code, global_vars, locals()) - except Exception as e: - await ctx.send('```py\n{}: {}```'.format(type(e).__name__, str(e)),) - return - - if asyncio.iscoroutine(result): - result = await result - - result = str(result) - - if ctx.message.guild is not None: - token = ctx.bot.http.token - r = "[EXPUNGED]" - result = result.replace(token, r) - result = result.replace(token.lower(), r) - result = result.replace(token.upper(), r) - - await ctx.send(box(result, lang="py")) - - @commands.command(hidden=True) - @checks.is_owner() - async def mock(self, ctx, user: discord.Member, *, command): - """Runs a command as if it was issued by a different user - - The prefix must not be entered""" - # Since we have stateful objects now this might be pretty bad - # Sorry Danny - old_author = ctx.author - old_content = ctx.message.content - ctx.message.author = user - ctx.message.content = ctx.prefix + command - - await ctx.bot.process_commands(ctx.message) - - ctx.message.author = old_author - ctx.message.content = old_content diff --git a/core/dev_commands.py b/core/dev_commands.py new file mode 100644 index 000000000..7c34b3898 --- /dev/null +++ b/core/dev_commands.py @@ -0,0 +1,65 @@ +from discord.ext import commands +from core.utils.chat_formatting import box +from core import checks +import asyncio +import discord + + +class Dev: + """Various development focused utilities""" + + @commands.command() + @checks.is_owner() + async def debug(self, ctx, *, code): + """Evaluates code""" + author = ctx.author + channel = ctx.channel + + code = code.strip('` ') + result = None + + global_vars = globals().copy() + global_vars['bot'] = ctx.bot + global_vars['ctx'] = ctx + global_vars['message'] = ctx.message + global_vars['author'] = ctx.author + global_vars['channel'] = ctx.channel + global_vars['guild'] = ctx.guild + + try: + result = eval(code, global_vars, locals()) + except Exception as e: + await ctx.send('```py\n{}: {}```'.format(type(e).__name__, str(e)),) + return + + if asyncio.iscoroutine(result): + result = await result + + result = str(result) + + if ctx.guild is not None: + token = ctx.bot.http.token + r = "[EXPUNGED]" + result = result.replace(token, r) + result = result.replace(token.lower(), r) + result = result.replace(token.upper(), r) + + await ctx.send(box(result, lang="py")) + + @commands.command() + @checks.is_owner() + async def mock(self, ctx, user: discord.Member, *, command): + """Runs a command as if it was issued by a different user + + The prefix must not be entered""" + # Since we have stateful objects now this might be pretty bad + # Sorry Danny + old_author = ctx.author + old_content = ctx.message.content + ctx.message.author = user + ctx.message.content = ctx.prefix + command + + await ctx.bot.process_commands(ctx.message) + + ctx.message.author = old_author + ctx.message.content = old_content diff --git a/core/utils/chat_formatting.py b/core/utils/chat_formatting.py index 5b7a5bde3..fd4cdc0ac 100644 --- a/core/utils/chat_formatting.py +++ b/core/utils/chat_formatting.py @@ -44,14 +44,14 @@ def pagify(text, delims=["\n"], *, escape=True, shorten_by=8, for d in delims]) closest_delim = closest_delim if closest_delim != -1 else page_length if escape: - to_send = escape_mass_mentions(in_text[:closest_delim]) + to_send = escape(in_text[:closest_delim], mass_mentions=True) else: to_send = in_text[:closest_delim] yield to_send in_text = in_text[closest_delim:] if escape: - yield escape_mass_mentions(in_text) + yield escape(in_text, mass_mentions=True) else: yield in_text diff --git a/main.py b/main.py index 7ad1c16b9..71cf08122 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,8 @@ from core.global_checks import init_global_checks from core.events import init_events from core.settings import parse_cli_flags from core.cli import interactive_config, confirm +from core.core_commands import Core +from core.dev_commands import Dev import asyncio import discord import logging.handlers @@ -58,9 +60,10 @@ if __name__ == '__main__': red = Red(cli_flags, description=description, pm_help=None) init_global_checks(red) init_events(red, cli_flags) - red.load_extension('core') + red.add_cog(Core()) + if cli_flags.dev: - pass # load dev cog here? + red.add_cog(Dev()) token = os.environ.get("RED_TOKEN", red.db.get_global("token", None)) prefix = cli_flags.prefix or red.db.get_global("prefix", [])