|
|
|
@ -18,9 +18,12 @@
|
|
|
|
|
# Help paginator by Rapptz
|
|
|
|
|
# Edited by F4stZ4p
|
|
|
|
|
# Edited by Hamothy
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
|
import datetime
|
|
|
|
|
import io
|
|
|
|
|
import textwrap
|
|
|
|
|
import traceback
|
|
|
|
|
from contextlib import redirect_stdout
|
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
|
|
import discord
|
|
|
|
@ -619,6 +622,36 @@ def error_handling(self, author):
|
|
|
|
|
return ErrorHandlingEmbed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cleanup_code(content):
|
|
|
|
|
"""Automatically removes code blocks from the code."""
|
|
|
|
|
# remove ```py\n```
|
|
|
|
|
if content.startswith('```') and content.endswith('```'):
|
|
|
|
|
return '\n'.join(content.split('\n')[1:-1])
|
|
|
|
|
|
|
|
|
|
# remove `foo`
|
|
|
|
|
return content.strip('` \n')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def paginate(text: str):
|
|
|
|
|
"""Simple generator that paginates text."""
|
|
|
|
|
last = 0
|
|
|
|
|
pages = []
|
|
|
|
|
for curr in range(0, len(text)):
|
|
|
|
|
if curr % 1980 == 0:
|
|
|
|
|
pages.append(text[last:curr])
|
|
|
|
|
last = curr
|
|
|
|
|
appd_index = curr
|
|
|
|
|
if appd_index != len(text) - 1:
|
|
|
|
|
pages.append(text[last:curr])
|
|
|
|
|
return list(filter(lambda a: a != '', pages))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_syntax_error(e):
|
|
|
|
|
if e.text is None:
|
|
|
|
|
return f'```py\n{e.__class__.__name__}: {e}\n```'
|
|
|
|
|
return f'```py\n{e.text}{"^":>{e.offset}}\n{e.__class__.__name__}: {e}```'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set up the Cog
|
|
|
|
|
class Help(Cog):
|
|
|
|
|
"""Help Commands!"""
|
|
|
|
@ -690,6 +723,75 @@ class Help(Cog):
|
|
|
|
|
prefix = self.bot.get_prefix_for_guild(ctx.guild.id)
|
|
|
|
|
await self.bot.generate_embed(ctx, desc=f"**The current guild prefix is `{prefix}`**")
|
|
|
|
|
|
|
|
|
|
@command(name="eval", hidden=True)
|
|
|
|
|
@is_owner()
|
|
|
|
|
async def _eval(self, ctx, *, body):
|
|
|
|
|
"""
|
|
|
|
|
Evaluates python code
|
|
|
|
|
Gracefully yoinked from (https://github.com/fourjr/eval-bot)"""
|
|
|
|
|
|
|
|
|
|
env = {
|
|
|
|
|
'ctx': ctx,
|
|
|
|
|
'bot': self.bot,
|
|
|
|
|
'channel': ctx.channel,
|
|
|
|
|
'author': ctx.author,
|
|
|
|
|
'guild': ctx.guild,
|
|
|
|
|
'message': ctx.message,
|
|
|
|
|
'source': inspect.getsource
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
env.update(globals())
|
|
|
|
|
|
|
|
|
|
body = cleanup_code(body)
|
|
|
|
|
stdout = io.StringIO()
|
|
|
|
|
err = out = None
|
|
|
|
|
|
|
|
|
|
to_compile = f'async def func():\n{textwrap.indent(body, " ")}'
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
exec(to_compile, env)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
err = await ctx.send(f'```py\n{e.__class__.__name__}: {e}\n```')
|
|
|
|
|
return await ctx.message.add_reaction('\u2049')
|
|
|
|
|
|
|
|
|
|
func = env['func']
|
|
|
|
|
try:
|
|
|
|
|
with redirect_stdout(stdout):
|
|
|
|
|
ret = await func()
|
|
|
|
|
except Exception as e:
|
|
|
|
|
value = stdout.getvalue()
|
|
|
|
|
err = await ctx.send(f'```py\n{value}{traceback.format_exc()}\n```')
|
|
|
|
|
else:
|
|
|
|
|
value = stdout.getvalue()
|
|
|
|
|
if ret is None:
|
|
|
|
|
if value:
|
|
|
|
|
try:
|
|
|
|
|
out = await ctx.send(f'```py\n{value}\n```')
|
|
|
|
|
except:
|
|
|
|
|
paginated_text = paginate(value)
|
|
|
|
|
for page in paginated_text:
|
|
|
|
|
if page == paginated_text[-1]:
|
|
|
|
|
out = await ctx.send(f'```py\n{page}\n```')
|
|
|
|
|
break
|
|
|
|
|
await ctx.send(f'```py\n{page}\n```')
|
|
|
|
|
else:
|
|
|
|
|
try:
|
|
|
|
|
out = await ctx.send(f'```py\n{value}{ret}\n```')
|
|
|
|
|
except:
|
|
|
|
|
paginated_text = paginate(f"{value}{ret}")
|
|
|
|
|
for page in paginated_text:
|
|
|
|
|
if page == paginated_text[-1]:
|
|
|
|
|
out = await ctx.send(f'```py\n{page}\n```')
|
|
|
|
|
break
|
|
|
|
|
await ctx.send(f'```py\n{page}\n```')
|
|
|
|
|
|
|
|
|
|
if out:
|
|
|
|
|
await ctx.message.add_reaction('\u2705') # tick
|
|
|
|
|
elif err:
|
|
|
|
|
await ctx.message.add_reaction('\u2049') # x
|
|
|
|
|
else:
|
|
|
|
|
await ctx.message.add_reaction('\u2705')
|
|
|
|
|
|
|
|
|
|
@command(name="support")
|
|
|
|
|
async def support(self, ctx):
|
|
|
|
|
"""Joining Support Server And Sending Feedback"""
|
|
|
|
|