1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-11-01 21:02:38 +00:00

Merge branch 'dev'

This commit is contained in:
Myned 2017-10-14 23:41:52 -04:00
commit cc40de0904
6 changed files with 36 additions and 8 deletions

View file

@ -37,7 +37,7 @@ class MsG:
for tag in tag_request.get('wolf', []): for tag in tag_request.get('wolf', []):
tags.append(tag[0]) tags.append(tag[0])
await ctx.send('✅ ``{}` **tags:**\n```\n{}```'.format(tag, formatter.tostring(tags))) await ctx.send('✅ `{}` **related tags:**\n```\n{}```'.format(tag, formatter.tostring(tags)))
@tags.error @tags.error
async def tags_error(self, ctx, error): async def tags_error(self, ctx, error):

View file

@ -81,8 +81,10 @@ class Administration:
for channel in channels: for channel in channels:
try: try:
ref = await channel.get_message(reference) ref = await channel.get_message(reference)
except err.NotFound: except err.NotFound:
continue continue
history = [] history = []
try: try:
pru_sent = await ctx.send('⌛️ **Pruning** <@{}>**\'s messages will take some time.**'.format(uid)) pru_sent = await ctx.send('⌛️ **Pruning** <@{}>**\'s messages will take some time.**'.format(uid))
@ -118,14 +120,18 @@ class Administration:
for message in history: for message in history:
try: try:
await message.delete() await message.delete()
except d.NotFound: except d.NotFound:
pass 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(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
await del_sent.edit(content='🗑 `{}` **of** <@{}>**\'s messages deleted from** {}**.**'.format(len(history), uid, ctx.guild.name)) await del_sent.edit(content='🗑 `{}` **of** <@{}>**\'s messages deleted from** {}**.**'.format(len(history), uid, ctx.guild.name))
except exc.CheckFail: except exc.CheckFail:
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)
@ -152,11 +158,13 @@ class Administration:
while not self.bot.is_closed(): while not self.bot.is_closed():
message = await self.bot.wait_for('message', check=check) message = await self.bot.wait_for('message', check=check)
await self.queue.put(message) await self.queue.put(message)
except exc.Abort: except exc.Abort:
u.tasks['management']['auto_delete'].remove(channel.id) u.tasks['management']['auto_delete'].remove(channel.id)
u.dump(u.tasks, 'cogs/tasks.pkl') u.dump(u.tasks, 'cogs/tasks.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
@ -176,5 +184,19 @@ class Administration:
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: else:
raise exc.Exists raise exc.Exists
except exc.Exists: except exc.Exists:
await ctx.send('❌ **Already auto-deleting in this channel.** Type `stop` to stop.', delete_after=10) await ctx.send('❌ **Already auto-deleting in this channel.** Type `stop` to stop.', delete_after=10)
@commands.command(name='deletecommands', aliases=['delcmds'])
@commands.has_permissions(administrator=True)
async def delete_commands(self, ctx):
guild = ctx.guild
if guild.id not in u.settings['del_ctx']:
u.settings['del_ctx'].append(guild.id)
else:
u.settings['del_ctx'].remove(guild.id)
u.dump(u.settings, 'settings.pkl')
await ctx.send('✅ **Delete command invocations:** `{}`'.format(guild.id in u.settings['del_ctx']))

View file

@ -27,7 +27,7 @@ class Bot:
@commands.is_owner() @commands.is_owner()
@checks.del_ctx() @checks.del_ctx()
async def die(self, ctx): async def die(self, ctx):
if isinstance(self.bot.get_channel(u.config['startup_channel']), d.TextChannel): if isinstance(self.bot.get_channel(u.config['shutdown_channel']), d.TextChannel):
await self.bot.get_channel(u.config['shutdown_channel']).send('**Shutting down. . .** 🌙') await self.bot.get_channel(u.config['shutdown_channel']).send('**Shutting down. . .** 🌙')
# loop = self.bot.loop.all_tasks() # loop = self.bot.loop.all_tasks()
# for task in loop: # for task in loop:
@ -43,7 +43,7 @@ class Bot:
@checks.del_ctx() @checks.del_ctx()
async def restart(self, ctx): async def restart(self, ctx):
print('\n| | | | | | | | | |\nR E S T A R T I N G\n| | | | | | | | | |\n') print('\n| | | | | | | | | |\nR E S T A R T I N G\n| | | | | | | | | |\n')
if isinstance(self.bot.get_channel(u.config['startup_channel']), d.TextChannel): if isinstance(self.bot.get_channel(u.config['shutdown_channel']), d.TextChannel):
await self.bot.get_channel(u.config['shutdown_channel']).send('**Restarting. . .** 💤') await self.bot.get_channel(u.config['shutdown_channel']).send('**Restarting. . .** 💤')
# u.notify('R E S T A R T I N G') # u.notify('R E S T A R T I N G')
# loop = self.bot.loop.all_tasks() # loop = self.bot.loop.all_tasks()

View file

@ -58,7 +58,7 @@ def is_nsfw():
def del_ctx(): def del_ctx():
async def predicate(ctx): async def predicate(ctx):
if isinstance(ctx.message.channel, discord.TextChannel): if ctx.me.permissions_in(ctx.channel).manage_messages is True and isinstance(ctx.message.channel, discord.TextChannel) and ctx.guild.id in u.settings['del_ctx']:
await ctx.message.delete() await ctx.message.delete()
return True return True
return commands.check(predicate) return commands.check(predicate)

View file

@ -9,6 +9,7 @@ import traceback as tb
import discord as d import discord as d
from discord import utils from discord import utils
from discord.ext import commands from discord.ext import commands
from discord.ext.commands import errors as errext
from misc import exceptions as exc from misc import exceptions as exc
from misc import checks from misc import checks
@ -40,7 +41,9 @@ async def on_ready():
@bot.event @bot.event
async def on_error(error): async def on_error(error, *args, **kwargs):
if isinstance(bot.get_channel(u.config['shutdown_channel']), d.TextChannel):
await bot.get_channel(u.config['shutdown_channel']).send('**__ERROR__** ⚠️ {}\n**Exiting. . .**'.format(error))
u.close() u.close()
await bot.logout() await bot.logout()
await bot.close() await bot.close()
@ -51,7 +54,9 @@ async def on_error(error):
@bot.event @bot.event
async def on_command_error(ctx, error): async def on_command_error(ctx, error):
if not isinstance(error, commands.errors.CommandNotFound): if isinstance(error, errext.CheckFailure):
await ctx.send('❌ **Insufficient permissions.**', delete_after=10)
elif not isinstance(error, errext.CommandNotFound):
print('\n! ! ! ! ! ! ! ! ! ! ! !\nC O M M A N D E R R O R : {}\n! ! ! ! ! ! ! ! ! ! ! !\n'.format( print('\n! ! ! ! ! ! ! ! ! ! ! !\nC O M M A N D E R R O R : {}\n! ! ! ! ! ! ! ! ! ! ! !\n'.format(
error), file=sys.stderr) error), file=sys.stderr)
tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr) tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr)

View file

@ -50,6 +50,7 @@ def dump(obj, filename):
pkl.dump(obj, outfile) pkl.dump(obj, outfile)
settings = setdefault('settings.pkl', {'del_ctx': []})
tasks = setdefault('cogs/tasks.pkl', {}) tasks = setdefault('cogs/tasks.pkl', {})