mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[Core] Added separate dev cog
This is enabled with the cli flag --dev
This commit is contained in:
parent
cf2925978b
commit
311339240f
@ -1,5 +0,0 @@
|
||||
from .owner import Owner
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Owner())
|
||||
@ -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
|
||||
65
core/dev_commands.py
Normal file
65
core/dev_commands.py
Normal file
@ -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
|
||||
@ -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
|
||||
|
||||
|
||||
7
main.py
7
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", [])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user