diff --git a/src/main/cogs/info.py b/src/main/cogs/info.py index d86435b..bea069c 100644 --- a/src/main/cogs/info.py +++ b/src/main/cogs/info.py @@ -1,7 +1,9 @@ import asyncio +import traceback as tb + import discord -import traceback from discord.ext import commands + from misc import exceptions as exc @@ -10,6 +12,19 @@ class Info: def __init__(self, bot): self.bot = bot + @commands.command(hidden=True) + async def hi(ctx): + user = ctx.message.author + + hello = 'Hewwo, {}.'.format(user.mention) + if user.id == checks.owner_id: + hello += '.. ***Master.*** uwu' + elif user.guild_permissions.administrator: + hello = '{} **Admin** {}'.format(hello[:7], hello[7:]) + elif user.guild_permissions.ban_members: + hello = '{} **Mod** {}'.format(hello[:7], hello[7:]) + await ctx.send(hello) + @commands.group(name='info', aliases=['i']) async def info(self, ctx): if invoked_subcommand is None: @@ -17,16 +32,8 @@ class Info: @info.command(aliases=['g', 'server', 's'], brief='Provides info about a guild', hidden=True) async def guild(self, ctx): - try: - guild = '' - except Exception: - await ctx.send(exc.base) - traceback.print_exc(limit=1) + pass @info.command(aliases=['u', 'member', 'm'], brief='Provides info about a user', hidden=True) async def user(self, ctx): - try: - user = '' - except Exception: - await ctx.send(exc.base) - traceback.print_exc(limit=1) + pass diff --git a/src/main/cogs/management.py b/src/main/cogs/management.py index 36aed10..642d747 100644 --- a/src/main/cogs/management.py +++ b/src/main/cogs/management.py @@ -1,13 +1,16 @@ import asyncio +import traceback as tb + import discord as d -import traceback from discord.ext import commands -from misc import checks + from misc import exceptions as exc +from misc import checks from utils import utils as u RATE_LIMIT = 2.1 + class Administration: def __init__(self, bot): @@ -94,7 +97,7 @@ class Administration: history.extend(await channel.history(limit=None).flatten()) await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await asyncio.sleep(RATE_LIMIT) - elif when =='before': + elif when == 'before': for channel in channels: history.extend(await channel.history(limit=None, before=ref.created_at).flatten()) await ch_sent.edit(content='🗄 **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) @@ -117,8 +120,10 @@ class Administration: await cont_sent.delete() del_sent = await ctx.send('🗑 **Deleting messages...**') for message in history: - try: await message.delete() - except d.NotFound: pass + try: + await message.delete() + except d.NotFound: + pass # print('Deleted {}/{} messages.'.format(history.index(message) + 1, len(history))) await del_sent.edit(content='🗑 **Deleted** `{}/{}` **messages.**'.format(history.index(message) + 1, len(history))) await asyncio.sleep(RATE_LIMIT) @@ -127,20 +132,19 @@ class Administration: await ctx.send('❌ **Deletion aborted.**', delete_after=10) except TimeoutError: await ctx.send('❌ **Deletion timed out.**', delete_after=10) - except Exception: - await ctx.send('{}\n```{}```'.format(exc.base, traceback.format_exc(limit=1))) - traceback.print_exc() async def delete(self): while True: message = await self.queue.get() await asyncio.sleep(RATE_LIMIT) - try: await message.delete() - except d.errors.NotFound: pass + try: + await message.delete() + except d.errors.NotFound: + pass async def on_message(self, channel): def check(msg): - if msg.content == 'stop' and msg.channel is channel and msg.author.guild_permissions.administrator: + if msg.content.lower() == 'stop' and msg.channel is channel and msg.author.guild_permissions.administrator: raise exc.Abort elif msg.channel is channel and not msg.pinned: return True @@ -153,14 +157,11 @@ class Administration: await self.queue.put(message) except exc.Abort: u.background['management']['auto_delete'].remove(channel.id) - u.update(u.background, 'background.json') + u.dump(u.background, 'background.pkl') print('Stopped looping {}'.format(channel.id)) await channel.send('✅ **Stopped deleting messages in** {}**.**'.format(channel.mention), delete_after=5) except AttributeError: pass - except Exception: - await channel.send(exc.base + '\n```' + traceback.format_exc(limit=1) + '```') - traceback.print_exc() @commands.command(name='autodelete', aliases=['autodel', 'ad']) @commands.has_permissions(administrator=True) @@ -171,13 +172,12 @@ class Administration: try: if channel.id not in u.background.setdefault('management', {}).setdefault('auto_delete', []): u.background['management']['auto_delete'].append(channel.id) - u.update(u.background, 'background.json') + u.dump(u.background, 'background.pkl') self.bot.loop.create_task(self.on_message(channel)) self.bot.loop.create_task(self.delete()) print('Looping {}'.format(channel.id)) await ctx.send('✅ **Auto-deleting all messages in this channel.**', delete_after=5) - else: raise exc.Exists - except exc.Exists: await ctx.send('❌ **Already auto-deleting in this channel.** Type `stop` to stop.', delete_after=10) - except Exception: - await channel.send(exc.base + '\n```' + traceback.format_exc(limit=1) + '```') - traceback.print_exc() + else: + raise exc.Exists + except exc.Exists: + await ctx.send('❌ **Already auto-deleting in this channel.** Type `stop` to stop.', delete_after=10) diff --git a/src/main/misc/checks.py b/src/main/misc/checks.py index 6876964..09daf75 100644 --- a/src/main/misc/checks.py +++ b/src/main/misc/checks.py @@ -1,7 +1,8 @@ import asyncio -import discord import json import traceback + +import discord from discord.ext import commands from discord.ext.commands import errors @@ -11,30 +12,43 @@ with open('config.json') as infile: owner_id = config['owner_id'] listed_ids = config['listed_ids'] + def is_owner(): async def predicate(ctx): return ctx.message.author.id == owner_id return commands.check(predicate) + + def is_admin(): def predicate(ctx): return ctx.message.author.guild_permissions.administrator return commands.check(predicate) + + def is_mod(): def predicate(ctx): return ctx.message.author.guild_permissions.ban_members return commands.check(predicate) + + def is_listed(): def predicate(ctx): return ctx.message.author.id in listed_ids return commands.check(predicate) + def owner(ctx): return ctx.message.author.id == owner_id + + def admin(ctx): return ctx.message.author.guild_permissions.administrator + + def mod(ctx): return ctx.message.author.guild_permissions.ban_members + def is_nsfw(): def predicate(ctx): if isinstance(ctx.message.channel, discord.TextChannel): @@ -42,6 +56,7 @@ def is_nsfw(): return True return commands.check(predicate) + def del_ctx(): async def predicate(ctx): if isinstance(ctx.message.channel, discord.TextChannel): diff --git a/src/main/misc/exceptions.py b/src/main/misc/exceptions.py index 8db2366..b772bd4 100644 --- a/src/main/misc/exceptions.py +++ b/src/main/misc/exceptions.py @@ -1,24 +1,93 @@ base = '⚠️ **An internal error has occurred.** Please notify my master! 🐺' -class Left(Exception): pass -class Right(Exception): pass -class Save(Exception): pass -class Exists(Exception): pass -class PostError(Exception): pass -class ImageError(Exception): pass -class MatchError(Exception): pass -class TagBlacklisted(Exception): pass -class BoundsError(Exception): pass -class TagBoundsError(Exception): pass -class TagExists(Exception): pass -class TagError(Exception): pass -class FlagError(Exception): pass -class BlacklistError(Exception): pass -class NotFound(Exception): pass -class Timeout(Exception): pass -class InvalidVideoFile(Exception): pass -class MissingAttachment(Exception): pass -class TooManyAttachments(Exception): pass -class CheckFail(Exception): pass -class Abort(Exception): pass -class Continue(Exception): pass + +class Left(Exception): + pass + + +class Right(Exception): + pass + + +class Save(Exception): + pass + + +class GoTo(Exception): + pass + + +class Exists(Exception): + pass + + +class PostError(Exception): + pass + + +class ImageError(Exception): + pass + + +class MatchError(Exception): + pass + + +class TagBlacklisted(Exception): + pass + + +class BoundsError(Exception): + pass + + +class TagBoundsError(Exception): + pass + + +class TagExists(Exception): + pass + + +class TagError(Exception): + pass + + +class FlagError(Exception): + pass + + +class BlacklistError(Exception): + pass + + +class NotFound(Exception): + pass + + +class Timeout(Exception): + pass + + +class InvalidVideoFile(Exception): + pass + + +class MissingAttachment(Exception): + pass + + +class TooManyAttachments(Exception): + pass + + +class CheckFail(Exception): + pass + + +class Abort(Exception): + pass + + +class Continue(Exception): + pass diff --git a/src/main/utils/formatter.py b/src/main/utils/formatter.py index f8ed334..3dc87d4 100644 --- a/src/main/utils/formatter.py +++ b/src/main/utils/formatter.py @@ -10,6 +10,7 @@ def tostring(i, *, random=False): o = ' ' return o + def tostring_commas(i): if i: o = ',' @@ -18,6 +19,7 @@ def tostring_commas(i): return o[:-1] return '' + def dict_tostring(i): o = '' if i: @@ -25,6 +27,7 @@ def dict_tostring(i): o += '**' + k + ':** `' + tostring(v) + '`\n' return o + def dictelem_tostring(i): o = '' if i: