mirror of
https://github.com/myned/modufur.git
synced 2024-12-25 06:37:29 +00:00
Cleaned up formatting with autopep8
This commit is contained in:
parent
35e7091129
commit
2bd2808bfc
5 changed files with 149 additions and 55 deletions
|
@ -1,7 +1,9 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import traceback as tb
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import traceback
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from misc import exceptions as exc
|
from misc import exceptions as exc
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,6 +12,19 @@ class Info:
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = 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'])
|
@commands.group(name='info', aliases=['i'])
|
||||||
async def info(self, ctx):
|
async def info(self, ctx):
|
||||||
if invoked_subcommand is None:
|
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)
|
@info.command(aliases=['g', 'server', 's'], brief='Provides info about a guild', hidden=True)
|
||||||
async def guild(self, ctx):
|
async def guild(self, ctx):
|
||||||
try:
|
pass
|
||||||
guild = ''
|
|
||||||
except Exception:
|
|
||||||
await ctx.send(exc.base)
|
|
||||||
traceback.print_exc(limit=1)
|
|
||||||
|
|
||||||
@info.command(aliases=['u', 'member', 'm'], brief='Provides info about a user', hidden=True)
|
@info.command(aliases=['u', 'member', 'm'], brief='Provides info about a user', hidden=True)
|
||||||
async def user(self, ctx):
|
async def user(self, ctx):
|
||||||
try:
|
pass
|
||||||
user = ''
|
|
||||||
except Exception:
|
|
||||||
await ctx.send(exc.base)
|
|
||||||
traceback.print_exc(limit=1)
|
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import traceback as tb
|
||||||
|
|
||||||
import discord as d
|
import discord as d
|
||||||
import traceback
|
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from misc import checks
|
|
||||||
from misc import exceptions as exc
|
from misc import exceptions as exc
|
||||||
|
from misc import checks
|
||||||
from utils import utils as u
|
from utils import utils as u
|
||||||
|
|
||||||
RATE_LIMIT = 2.1
|
RATE_LIMIT = 2.1
|
||||||
|
|
||||||
|
|
||||||
class Administration:
|
class Administration:
|
||||||
|
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
|
@ -117,8 +120,10 @@ class Administration:
|
||||||
await cont_sent.delete()
|
await cont_sent.delete()
|
||||||
del_sent = await ctx.send('🗑 **Deleting messages...**')
|
del_sent = await ctx.send('🗑 **Deleting messages...**')
|
||||||
for message in history:
|
for message in history:
|
||||||
try: await message.delete()
|
try:
|
||||||
except d.NotFound: pass
|
await message.delete()
|
||||||
|
except d.NotFound:
|
||||||
|
pass
|
||||||
# print('Deleted {}/{} messages.'.format(history.index(message) + 1, len(history)))
|
# 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 del_sent.edit(content='🗑 **Deleted** `{}/{}` **messages.**'.format(history.index(message) + 1, len(history)))
|
||||||
await asyncio.sleep(RATE_LIMIT)
|
await asyncio.sleep(RATE_LIMIT)
|
||||||
|
@ -127,20 +132,19 @@ class Administration:
|
||||||
await ctx.send('❌ **Deletion aborted.**', delete_after=10)
|
await ctx.send('❌ **Deletion aborted.**', delete_after=10)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
await ctx.send('❌ **Deletion timed out.**', delete_after=10)
|
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):
|
async def delete(self):
|
||||||
while True:
|
while True:
|
||||||
message = await self.queue.get()
|
message = await self.queue.get()
|
||||||
await asyncio.sleep(RATE_LIMIT)
|
await asyncio.sleep(RATE_LIMIT)
|
||||||
try: await message.delete()
|
try:
|
||||||
except d.errors.NotFound: pass
|
await message.delete()
|
||||||
|
except d.errors.NotFound:
|
||||||
|
pass
|
||||||
|
|
||||||
async def on_message(self, channel):
|
async def on_message(self, channel):
|
||||||
def check(msg):
|
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
|
raise exc.Abort
|
||||||
elif msg.channel is channel and not msg.pinned:
|
elif msg.channel is channel and not msg.pinned:
|
||||||
return True
|
return True
|
||||||
|
@ -153,14 +157,11 @@ class Administration:
|
||||||
await self.queue.put(message)
|
await self.queue.put(message)
|
||||||
except exc.Abort:
|
except exc.Abort:
|
||||||
u.background['management']['auto_delete'].remove(channel.id)
|
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))
|
print('Stopped looping {}'.format(channel.id))
|
||||||
await channel.send('✅ **Stopped deleting messages in** {}**.**'.format(channel.mention), delete_after=5)
|
await channel.send('✅ **Stopped deleting messages in** {}**.**'.format(channel.mention), delete_after=5)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
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.command(name='autodelete', aliases=['autodel', 'ad'])
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
|
@ -171,13 +172,12 @@ class Administration:
|
||||||
try:
|
try:
|
||||||
if channel.id not in u.background.setdefault('management', {}).setdefault('auto_delete', []):
|
if channel.id not in u.background.setdefault('management', {}).setdefault('auto_delete', []):
|
||||||
u.background['management']['auto_delete'].append(channel.id)
|
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.on_message(channel))
|
||||||
self.bot.loop.create_task(self.delete())
|
self.bot.loop.create_task(self.delete())
|
||||||
print('Looping {}'.format(channel.id))
|
print('Looping {}'.format(channel.id))
|
||||||
await ctx.send('✅ **Auto-deleting all messages in this channel.**', delete_after=5)
|
await ctx.send('✅ **Auto-deleting all messages in this channel.**', delete_after=5)
|
||||||
else: raise exc.Exists
|
else:
|
||||||
except exc.Exists: await ctx.send('❌ **Already auto-deleting in this channel.** Type `stop` to stop.', delete_after=10)
|
raise exc.Exists
|
||||||
except Exception:
|
except exc.Exists:
|
||||||
await channel.send(exc.base + '\n```' + traceback.format_exc(limit=1) + '```')
|
await ctx.send('❌ **Already auto-deleting in this channel.** Type `stop` to stop.', delete_after=10)
|
||||||
traceback.print_exc()
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import discord
|
|
||||||
import json
|
import json
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.commands import errors
|
from discord.ext.commands import errors
|
||||||
|
|
||||||
|
@ -11,30 +12,43 @@ with open('config.json') as infile:
|
||||||
owner_id = config['owner_id']
|
owner_id = config['owner_id']
|
||||||
listed_ids = config['listed_ids']
|
listed_ids = config['listed_ids']
|
||||||
|
|
||||||
|
|
||||||
def is_owner():
|
def is_owner():
|
||||||
async def predicate(ctx):
|
async def predicate(ctx):
|
||||||
return ctx.message.author.id == owner_id
|
return ctx.message.author.id == owner_id
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def is_admin():
|
def is_admin():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
return ctx.message.author.guild_permissions.administrator
|
return ctx.message.author.guild_permissions.administrator
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def is_mod():
|
def is_mod():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
return ctx.message.author.guild_permissions.ban_members
|
return ctx.message.author.guild_permissions.ban_members
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def is_listed():
|
def is_listed():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
return ctx.message.author.id in listed_ids
|
return ctx.message.author.id in listed_ids
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def owner(ctx):
|
def owner(ctx):
|
||||||
return ctx.message.author.id == owner_id
|
return ctx.message.author.id == owner_id
|
||||||
|
|
||||||
|
|
||||||
def admin(ctx):
|
def admin(ctx):
|
||||||
return ctx.message.author.guild_permissions.administrator
|
return ctx.message.author.guild_permissions.administrator
|
||||||
|
|
||||||
|
|
||||||
def mod(ctx):
|
def mod(ctx):
|
||||||
return ctx.message.author.guild_permissions.ban_members
|
return ctx.message.author.guild_permissions.ban_members
|
||||||
|
|
||||||
|
|
||||||
def is_nsfw():
|
def is_nsfw():
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
if isinstance(ctx.message.channel, discord.TextChannel):
|
if isinstance(ctx.message.channel, discord.TextChannel):
|
||||||
|
@ -42,6 +56,7 @@ def is_nsfw():
|
||||||
return True
|
return True
|
||||||
return commands.check(predicate)
|
return commands.check(predicate)
|
||||||
|
|
||||||
|
|
||||||
def del_ctx():
|
def del_ctx():
|
||||||
async def predicate(ctx):
|
async def predicate(ctx):
|
||||||
if isinstance(ctx.message.channel, discord.TextChannel):
|
if isinstance(ctx.message.channel, discord.TextChannel):
|
||||||
|
|
|
@ -1,24 +1,93 @@
|
||||||
base = '⚠️ **An internal error has occurred.** Please notify my master! 🐺'
|
base = '⚠️ **An internal error has occurred.** Please notify my master! 🐺'
|
||||||
|
|
||||||
class Left(Exception): pass
|
|
||||||
class Right(Exception): pass
|
class Left(Exception):
|
||||||
class Save(Exception): pass
|
pass
|
||||||
class Exists(Exception): pass
|
|
||||||
class PostError(Exception): pass
|
|
||||||
class ImageError(Exception): pass
|
class Right(Exception):
|
||||||
class MatchError(Exception): pass
|
pass
|
||||||
class TagBlacklisted(Exception): pass
|
|
||||||
class BoundsError(Exception): pass
|
|
||||||
class TagBoundsError(Exception): pass
|
class Save(Exception):
|
||||||
class TagExists(Exception): pass
|
pass
|
||||||
class TagError(Exception): pass
|
|
||||||
class FlagError(Exception): pass
|
|
||||||
class BlacklistError(Exception): pass
|
class GoTo(Exception):
|
||||||
class NotFound(Exception): pass
|
pass
|
||||||
class Timeout(Exception): pass
|
|
||||||
class InvalidVideoFile(Exception): pass
|
|
||||||
class MissingAttachment(Exception): pass
|
class Exists(Exception):
|
||||||
class TooManyAttachments(Exception): pass
|
pass
|
||||||
class CheckFail(Exception): pass
|
|
||||||
class Abort(Exception): pass
|
|
||||||
class Continue(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
|
||||||
|
|
|
@ -10,6 +10,7 @@ def tostring(i, *, random=False):
|
||||||
o = ' '
|
o = ' '
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
def tostring_commas(i):
|
def tostring_commas(i):
|
||||||
if i:
|
if i:
|
||||||
o = ','
|
o = ','
|
||||||
|
@ -18,6 +19,7 @@ def tostring_commas(i):
|
||||||
return o[:-1]
|
return o[:-1]
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
def dict_tostring(i):
|
def dict_tostring(i):
|
||||||
o = ''
|
o = ''
|
||||||
if i:
|
if i:
|
||||||
|
@ -25,6 +27,7 @@ def dict_tostring(i):
|
||||||
o += '**' + k + ':** `' + tostring(v) + '`\n'
|
o += '**' + k + ':** `' + tostring(v) + '`\n'
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
def dictelem_tostring(i):
|
def dictelem_tostring(i):
|
||||||
o = ''
|
o = ''
|
||||||
if i:
|
if i:
|
||||||
|
|
Loading…
Reference in a new issue