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

Merge branch 'master' into dev

This commit is contained in:
Myned 2017-10-15 02:18:10 -04:00
commit be1d861d1a
3 changed files with 19 additions and 12 deletions

View file

@ -16,12 +16,15 @@ class Administration:
self.bot = bot self.bot = bot
self.RATE_LIMIT = 2.1 self.RATE_LIMIT = 2.1
self.queue = asyncio.Queue() self.queue = asyncio.Queue()
self.deleting = False
for channel in u.tasks.get('management', {}).get('auto_delete', []): if u.tasks['auto_del']:
temp = self.bot.get_channel(channel) for channel in u.tasks['auto_del']:
self.bot.loop.create_task(self.queue_on_message(temp)) temp = self.bot.get_channel(channel)
self.bot.loop.create_task(self.queue_on_message(temp))
print('Looping #{}'.format(temp.name))
self.bot.loop.create_task(self.delete()) self.bot.loop.create_task(self.delete())
print('Looping #{}'.format(temp.name)) self.deleting = True
# @commands.group(aliases=['pr', 'clear', 'cl']) # @commands.group(aliases=['pr', 'clear', 'cl'])
# @commands.is_owner() # @commands.is_owner()
@ -136,7 +139,7 @@ class Administration:
await ctx.send('❌ **Deletion timed out.**', delete_after=10) await ctx.send('❌ **Deletion timed out.**', delete_after=10)
async def delete(self): async def delete(self):
while not self.bot.is_closed(): while self.deleting:
message = await self.queue.get() message = await self.queue.get()
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
try: try:
@ -164,8 +167,10 @@ class Administration:
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['auto_del'].remove(channel.id)
u.dump(u.tasks, 'cogs/tasks.pkl') u.dump(u.tasks, 'cogs/tasks.pkl')
if not u.tasks['auto_del']:
self.deleting = False
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)
@ -179,11 +184,13 @@ class Administration:
channel = ctx.channel channel = ctx.channel
try: try:
if channel.id not in u.tasks.setdefault('management', {}).setdefault('auto_delete', []): if channel.id not in u.tasks['auto_del']:
u.tasks['management']['auto_delete'].append(channel.id) u.tasks['auto_del'].append(channel.id)
u.dump(u.tasks, 'cogs/tasks.pkl') u.dump(u.tasks, 'cogs/tasks.pkl')
self.bot.loop.create_task(self.queue_on_message(channel)) self.bot.loop.create_task(self.queue_on_message(channel))
self.bot.loop.create_task(self.delete()) if not self.deleting:
self.bot.loop.create_task(self.delete())
self.deleting = True
print('Looping #{}'.format(channel.name)) print('Looping #{}'.format(channel.name))
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:

View file

@ -28,7 +28,7 @@ class Bot:
@checks.del_ctx() @checks.del_ctx()
async def die(self, ctx): async def die(self, ctx):
if isinstance(self.bot.get_channel(u.config['shutdown_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:
# task.cancel() # task.cancel()
@ -44,7 +44,7 @@ class Bot:
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['shutdown_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()
# for task in loop: # for task in loop:

View file

@ -51,7 +51,7 @@ def dump(obj, filename):
settings = setdefault('settings.pkl', {'del_ctx': []}) settings = setdefault('settings.pkl', {'del_ctx': []})
tasks = setdefault('cogs/tasks.pkl', {}) tasks = setdefault('cogs/tasks.pkl', {'auto_del': []})
async def clear(obj, interval=10 * 60, replace=None): async def clear(obj, interval=10 * 60, replace=None):