1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-23 22:27:27 +00:00

Merge branch 'dev'

This commit is contained in:
Myned 2017-10-28 16:32:13 -04:00
commit fc2880fe02
5 changed files with 188 additions and 224 deletions

View file

@ -23,7 +23,7 @@ class MsG:
self.bot = bot self.bot = bot
self.color = d.Color(0x1A1A1A) self.color = d.Color(0x1A1A1A)
self.LIMIT = 100 self.LIMIT = 100
self.HISTORY_LIMIT = 100 self.HISTORY_LIMIT = 150
self.RATE_LIMIT = u.RATE_LIMIT self.RATE_LIMIT = u.RATE_LIMIT
self.qualiqueue = asyncio.Queue() self.qualiqueue = asyncio.Queue()
self.qualitifying = False self.qualitifying = False
@ -36,34 +36,34 @@ class MsG:
if u.tasks['auto_qual']: if u.tasks['auto_qual']:
for channel in u.tasks['auto_qual']: for channel in u.tasks['auto_qual']:
temp = self.bot.get_channel(channel) temp = self.bot.get_channel(channel)
self.bot.loop.create_task(self.qualiqueue_for_qualitification(temp)) self.bot.loop.create_task(self.queue_for_qualitification(temp))
print('AUTO-QUALITIFYING : #{}'.format(temp.name)) print('AUTO-QUALITIFYING : #{}'.format(temp.name))
self.bot.loop.create_task(self._qualitify()) self.bot.loop.create_task(self._qualitify())
self.qualitifying = True self.qualitifying = True
async def get_post(self, channel): # async def get_post(self, channel):
post_request = await u.fetch('https://e621.net/post/index.json', json=True) # post_request = await u.fetch('https://e621.net/post/index.json', json=True)
#
@commands.command() # @commands.command()
async def auto_post(self, ctx): # async def auto_post(self, ctx):
try: # try:
if ctx.channel.id not in u.tasks['auto_post']: # if ctx.channel.id not in u.tasks['auto_post']:
u.tasks['auto_post'].append(ctx.channel.id) # u.tasks['auto_post'].append(ctx.channel.id)
u.dump(u.tasks, 'cogs/tasks.pkl') # u.dump(u.tasks, 'cogs/tasks.pkl')
self.bot.loop.create_task(self.qualiqueue_for_qualitification(ctx.channel)) # self.bot.loop.create_task(self.queue_for_qualitification(ctx.channel))
if not self.qualitifying: # if not self.qualitifying:
self.bot.loop.create_task(self._qualitify()) # self.bot.loop.create_task(self._qualitify())
self.qualitifying = True # self.qualitifying = True
#
print('AUTO-POSTING : #{}'.format(ctx.channel.name)) # print('AUTO-POSTING : #{}'.format(ctx.channel.name))
await ctx.send('**Auto-posting all images in {}.**'.format(ctx.channel.mention), delete_after=5) # await ctx.send('**Auto-posting all images in {}**'.format(ctx.channel.mention), delete_after=5)
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') # await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
else: # else:
raise exc.Exists # raise exc.Exists
#
except exc.Exists: # except exc.Exists:
await ctx.send('**Already auto-posting in {}.** Type `stop` to stop.'.format(ctx.channel.mention), delete_after=10) # await ctx.send('**Already auto-posting in {}.** Type `stop` to stop.'.format(ctx.channel.mention), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') # await ctx.message.add_reaction('\N{CROSS MARK}')
# Tag search # Tag search
@commands.command(aliases=['rel'], brief='e621 Search for related tags', description='e621 | NSFW\nReturn related tags for a number of given tags', usage='[related|rel]') @commands.command(aliases=['rel'], brief='e621 Search for related tags', description='e621 | NSFW\nReturn related tags for a number of given tags', usage='[related|rel]')
@ -173,7 +173,7 @@ class MsG:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.MissingArgument: except exc.MissingArgument:
await ctx.send('**Invalid url or file.**', delete_after=10) await ctx.send('**Invalid url or file**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
# Reverse image searches a linked image using the public iqdb # Reverse image searches a linked image using the public iqdb
@ -192,7 +192,7 @@ class MsG:
try: try:
await dest.trigger_typing() await dest.trigger_typing()
await dest.send('**Probable match:**\n{}'.format(await scraper.get_post(url))) await dest.send('**Probable match**\n{}'.format(await scraper.get_post(url)))
c += 1 c += 1
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
@ -204,7 +204,7 @@ class MsG:
try: try:
await dest.trigger_typing() await dest.trigger_typing()
await dest.send('**Probable match:**\n{}'.format(await scraper.get_post(attachment.url))) await dest.send('**Probable match**\n{}'.format(await scraper.get_post(attachment.url)))
c += 1 c += 1
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
@ -218,7 +218,7 @@ class MsG:
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.MissingArgument: except exc.MissingArgument:
await ctx.send('**Invalid url or file.**', delete_after=10) await ctx.send('**Invalid url or file**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@commands.command(name='quality', aliases=['qual', 'qrev', 'qis']) @commands.command(name='quality', aliases=['qual', 'qrev', 'qis'])
@ -238,7 +238,7 @@ class MsG:
post = await scraper.get_post(url) post = await scraper.get_post(url)
await dest.send('**Probable match:**\n{}'.format(await scraper.get_image(post))) await dest.send('**Probable match**\n{}'.format(await scraper.get_image(post)))
c += 1 c += 1
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
@ -252,7 +252,7 @@ class MsG:
post = await scraper.get_post(attachment.url) post = await scraper.get_post(attachment.url)
await dest.send('**Probable match:**\n{}'.format(await scraper.get_image(post))) await dest.send('**Probable match**\n{}'.format(await scraper.get_image(post)))
c += 1 c += 1
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
@ -266,7 +266,7 @@ class MsG:
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.MissingArgument: except exc.MissingArgument:
await ctx.send('**Invalid url or file.**', delete_after=10) await ctx.send('**Invalid url or file**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@commands.command(name='reversify', aliases=['revify', 'risify', 'rify']) @commands.command(name='reversify', aliases=['revify', 'risify', 'rify'])
@ -276,67 +276,57 @@ class MsG:
kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5) kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5)
dest, remove, limit = kwargs['destination'], kwargs['remove'], kwargs['limit'] dest, remove, limit = kwargs['destination'], kwargs['remove'], kwargs['limit']
urls = [] urls = []
attachments = [] c = 0
if not ctx.author.permissions_in(ctx.channel).manage_messages: if not ctx.author.permissions_in(ctx.channel).manage_messages:
dest = ctx.author dest = ctx.author
async for message in ctx.channel.history(limit=self.HISTORY_LIMIT * limit): async for message in ctx.channel.history(limit=self.HISTORY_LIMIT * limit):
if len(urls) + len(attachments) >= limit: if c >= limit:
break break
if message.author.id != self.bot.user.id and re.search('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None: if message.author.id != self.bot.user.id and (re.search('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None or message.embeds or message.attachments):
urls.append(message) for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') urls.append(match.group(0))
elif message.author.id != self.bot.user.id and message.attachments: for embed in message.embeds:
attachments.append(message) if embed.image.url is not d.Embed.Empty:
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') urls.append(embed.image.url)
for attachment in message.attachments:
urls.append(attachment.url)
if not urls and not attachments: await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
c += 1
if not urls:
raise exc.NotFound raise exc.NotFound
for message in urls: for url in urls:
for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content): try:
try: await dest.trigger_typing()
await dest.trigger_typing()
await dest.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_post(match.group(0)))) await dest.send('**Probable match from** {} `{} / {}`\n{}'.format(message.author.display_name, urls.index(url) + 1, len(urls), await scraper.get_post(url)))
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
if remove: if remove:
with suppress(err.NotFound): with suppress(err.NotFound):
await message.delete() await message.delete()
except exc.MatchError as e: except exc.MatchError as e:
await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10) await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10)
await message.add_reaction('\N{CROSS MARK}') await message.add_reaction('\N{CROSS MARK}')
c -= 1
for message in attachments: if c > 0:
for attachment in message.attachments: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
try: else:
await dest.trigger_typing() await ctx.message.add_reaction('\N{CROSS MARK}')
await dest.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_post(attachment.url)))
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
await asyncio.sleep(self.RATE_LIMIT)
if remove:
with suppress(err.NotFound):
await message.delete()
except exc.MatchError as e:
await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10)
await message.add_reaction('\N{CROSS MARK}')
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.NotFound: except exc.NotFound:
await ctx.send('**No matches found.**', delete_after=10) await ctx.send('**No matches found**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.BoundsError as e: except exc.BoundsError as e:
await ctx.send('`{}` **invalid limit.** Images limited to 20'.format(e), delete_after=10) await ctx.send('`{}` **invalid limit.** Query limited to 30'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@commands.command(name='qualitify', aliases=['qualify', 'qrevify', 'qrisify', 'qify']) @commands.command(name='qualitify', aliases=['qualify', 'qrevify', 'qrisify', 'qify'])
@ -346,103 +336,83 @@ class MsG:
kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5) kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5)
dest, remove, limit = kwargs['destination'], kwargs['remove'], kwargs['limit'] dest, remove, limit = kwargs['destination'], kwargs['remove'], kwargs['limit']
urls = [] urls = []
attachments = [] c = 0
if not ctx.author.permissions_in(ctx.channel).manage_messages: if not ctx.author.permissions_in(ctx.channel).manage_messages:
dest = ctx.author dest = ctx.author
async for message in ctx.channel.history(limit=self.HISTORY_LIMIT * limit): async for message in ctx.channel.history(limit=self.HISTORY_LIMIT * limit):
if len(urls) + len(attachments) >= limit: if c >= limit:
break break
if message.author.id != self.bot.user.id and re.search('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None: if message.author.id != self.bot.user.id and (re.search('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) is not None or message.embeds or message.attachments):
urls.append(message) for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') urls.append(match.group(0))
elif message.author.id != self.bot.user.id and message.attachments: for embed in message.embeds:
attachments.append(message) if embed.image.url is not d.Embed.Empty:
await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') urls.append(embed.image.url)
for attachment in message.attachments:
urls.append(attachment.url)
if not urls and not attachments: await message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
c += 1
if not urls:
raise exc.NotFound raise exc.NotFound
for message in urls: for url in urls:
for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content): try:
try: await dest.trigger_typing()
await dest.trigger_typing()
post = await scraper.get_post(match.group(0)) post = await scraper.get_post(url)
await dest.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_image(post))) await dest.send('**Probable match from** {} `{} / {}`\n{}'.format(message.author.display_name, urls.index(url) + 1, len(urls), await scraper.get_image(post)))
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
if remove: if remove:
with suppress(err.NotFound): with suppress(err.NotFound):
await message.delete() await message.delete()
except exc.MatchError as e: except exc.MatchError as e:
await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10) await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10)
await message.add_reaction('\N{CROSS MARK}') await message.add_reaction('\N{CROSS MARK}')
c -= 1
for message in attachments: if c > 0:
for attachment in message.attachments: await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
try: else:
await dest.trigger_typing() await ctx.message.add_reaction('\N{CROSS MARK}')
post = await scraper.get_post(attachment.url)
await dest.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_image(post)))
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
await asyncio.sleep(self.RATE_LIMIT)
if remove:
with suppress(err.NotFound):
await message.delete()
except exc.MatchError as e:
await ctx.send('**No probable match for:** `{}`'.format(e), delete_after=10)
await message.add_reaction('\N{CROSS MARK}')
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.NotFound: except exc.NotFound:
await ctx.send('**No matches found.**', delete_after=10) await ctx.send('**No matches found**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.BoundsError as e: except exc.BoundsError as e:
await ctx.send('`{}` **invalid limit.** Images limited to 20'.format(e), delete_after=10) await ctx.send('`{}` **invalid limit.** Query limited to 30'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
async def _qualitify(self): async def _qualitify(self):
while self.qualitifying: while self.qualitifying:
message = await self.qualiqueue.get() message = await self.qualiqueue.get()
urls = []
for match in re.finditer('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content): for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content):
try: urls.append(match.group(0))
await message.channel.trigger_typing() for embed in message.embeds:
if embed.image.url is not d.Embed.Empty:
post = await scraper.get_post(match.group(0)) urls.append(embed.image.url)
await message.channel.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_image(post)))
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
await asyncio.sleep(self.RATE_LIMIT)
with suppress(err.NotFound):
await message.delete()
except exc.MatchError as e:
await message.channel.send('**No probable match for:** `{}`'.format(e), delete_after=10)
await message.add_reaction('\N{CROSS MARK}')
for attachment in message.attachments: for attachment in message.attachments:
urls.append(attachment.url)
for url in urls:
try: try:
await message.channel.trigger_typing() await message.channel.trigger_typing()
post = await scraper.get_post(attachment.url) post = await scraper.get_post(url)
await message.channel.send('**Probable match from** {}**:**\n{}'.format(message.author.display_name, await scraper.get_image(post))) await message.channel.send('**Probable match from** {}\n{}'.format(message.author.display_name, await scraper.get_image(post)))
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') with suppress(err.NotFound):
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
@ -459,7 +429,7 @@ class MsG:
def check(msg): def check(msg):
if msg.content.lower() == '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 message.author.id != self.bot.user.id and (re.search('(http[a-z]?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', msg.content) is not None or msg.attachments): elif msg.channel is channel and msg.author.id != self.bot.user.id and (re.search('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', msg.content) is not None or msg.attachments or msg.embeds):
return True return True
return False return False
@ -475,7 +445,7 @@ class MsG:
if not u.tasks['auto_qual']: if not u.tasks['auto_qual']:
self.qualitifying = False self.qualitifying = False
print('STOPPED : qualitifying #{}'.format(channel.name)) print('STOPPED : qualitifying #{}'.format(channel.name))
await channel.send('**Stopped queueing messages for qualitification in** {}**.**'.format(channel.mention), delete_after=5) await channel.send('**Stopped queueing messages for qualitification in** {}'.format(channel.mention), delete_after=5)
@commands.command(name='autoqualitify', aliases=['autoqual']) @commands.command(name='autoqualitify', aliases=['autoqual'])
@commands.has_permissions(manage_channels=True) @commands.has_permissions(manage_channels=True)
@ -484,13 +454,13 @@ class MsG:
if ctx.channel.id not in u.tasks['auto_qual']: if ctx.channel.id not in u.tasks['auto_qual']:
u.tasks['auto_qual'].append(ctx.channel.id) u.tasks['auto_qual'].append(ctx.channel.id)
u.dump(u.tasks, 'cogs/tasks.pkl') u.dump(u.tasks, 'cogs/tasks.pkl')
self.bot.loop.create_task(self.qualiqueue_for_qualitification(ctx.channel)) self.bot.loop.create_task(self.queue_for_qualitification(ctx.channel))
if not self.qualitifying: if not self.qualitifying:
self.bot.loop.create_task(self._qualitify()) self.bot.loop.create_task(self._qualitify())
self.qualitifying = True self.qualitifying = True
print('AUTO-QUALITIFYING : #{}'.format(ctx.channel.name)) print('AUTO-QUALITIFYING : #{}'.format(ctx.channel.name))
await ctx.send('**Auto-qualitifying all images in {}.**'.format(ctx.channel.mention), delete_after=5) await ctx.send('**Auto-qualitifying all images in** {}'.format(ctx.channel.mention), delete_after=5)
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
else: else:
raise exc.Exists raise exc.Exists
@ -689,7 +659,7 @@ class MsG:
await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed)
else: else:
await paginator.edit(content='**First image.**') await paginator.edit(content='**First image**')
except exc.GoTo: except exc.GoTo:
await paginator.edit(content='**Enter image number...**') await paginator.edit(content='**Enter image number...**')
@ -724,9 +694,9 @@ class MsG:
await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed)
except IndexError: except IndexError:
await paginator.edit(content='**No more images found.**') await paginator.edit(content='**No more images found**')
except exc.NotFound: except exc.NotFound:
await paginator.edit(content='**No more images found.**') await paginator.edit(content='**No more images found**')
else: else:
kwargs = u.get_kwargs(ctx, args) kwargs = u.get_kwargs(ctx, args)
dest, query = kwargs['destination'], kwargs['remaining'] dest, query = kwargs['destination'], kwargs['remaining']
@ -782,7 +752,7 @@ class MsG:
await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed)
else: else:
await paginator.edit(content='**First image.**') await paginator.edit(content='**First image**')
except exc.GoTo: except exc.GoTo:
await paginator.edit(content='**Enter image number...**') await paginator.edit(content='**Enter image number...**')
@ -809,13 +779,13 @@ class MsG:
await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed) await paginator.edit(content='\N{HEAVY BLACK HEART}' if values[c - 1]['url'] in hearted else None, embed=embed)
else: else:
await paginator.edit(content='**Last image.**') await paginator.edit(content='**Last image**')
finally: finally:
return hearted return hearted
# Creates reaction-based paginator for linked pools # Creates reaction-based paginator for linked pools
@commands.command(name='poolp', aliases=['e621pp', 'e6pp', '6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format', hidden=True) @commands.command(name='poolpage', aliases=['poolp', 'pp', 'e621pp', 'e6pp', '6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format', hidden=True)
@checks.del_ctx() @checks.del_ctx()
async def pool_paginator(self, ctx, *args): async def pool_paginator(self, ctx, *args):
try: try:
@ -823,25 +793,25 @@ class MsG:
except exc.Abort: except exc.Abort:
try: try:
await paginator.edit(content='**Exited paginator.**') await paginator.edit(content='**Exited paginator**')
except UnboundLocalError: except UnboundLocalError:
await dest.send('**Exited paginator.**') await dest.send('**Exited paginator**')
if not hearted: if not hearted:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except asyncio.TimeoutError: except asyncio.TimeoutError:
try: try:
await paginator.edit(content='**Paginator timed out.**') await paginator.edit(content='**Paginator timed out**')
except UnboundLocalError: except UnboundLocalError:
await dest.send('**Paginator timed out.**') await dest.send('**Paginator timed out**')
if not hearted: if not hearted:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.NotFound: except exc.NotFound:
await ctx.send('**Pool not found.**', delete_after=10) await ctx.send('**Pool not found**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.Timeout: except exc.Timeout:
await ctx.send('**Request timed out.**') await ctx.send('**Request timed out**')
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
finally: finally:
@ -855,7 +825,7 @@ class MsG:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
@commands.command(name='e621p', aliases=['e6p', '6p']) @commands.command(name='e621page', aliases=['e621p', 'e6p', '6p'])
@checks.del_ctx() @checks.del_ctx()
@checks.is_nsfw() @checks.is_nsfw()
async def e621_paginator(self, ctx, *args): async def e621_paginator(self, ctx, *args):
@ -864,34 +834,34 @@ class MsG:
except exc.Abort: except exc.Abort:
try: try:
await paginator.edit(content='**Exited paginator.**') await paginator.edit(content='**Exited paginator**')
except UnboundLocalError: except UnboundLocalError:
await dest.send('**Exited paginator.**') await dest.send('**Exited paginator**')
if not hearted: if not hearted:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except asyncio.TimeoutError: except asyncio.TimeoutError:
try: try:
await paginator.edit(content='**Paginator timed out.**') await paginator.edit(content='**Paginator timed out**')
except UnboundLocalError: except UnboundLocalError:
await dest.send('**Paginator timed out.**') await dest.send('**Paginator timed out**')
if not hearted: if not hearted:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.NotFound as e: except exc.NotFound as e:
await ctx.send('`{}` **not found.**'.format(e), delete_after=10) await ctx.send('`{}` **not found**'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.TagBlacklisted as e: except exc.TagBlacklisted as e:
await ctx.send('\N{NO ENTRY SIGN} `{}` **blacklisted.**'.format(e), delete_after=10) await ctx.send('\N{NO ENTRY SIGN} `{}` **blacklisted**'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{NO ENTRY SIGN}') await ctx.message.add_reaction('\N{NO ENTRY SIGN}')
except exc.TagBoundsError as e: except exc.TagBoundsError as e:
await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e), delete_after=10) await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.FavoritesNotFound: except exc.FavoritesNotFound:
await ctx.send('**You have no favorite tags.**', delete_after=10) await ctx.send('**You have no favorite tags**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.Timeout: except exc.Timeout:
await ctx.send('**Request timed out.**') await ctx.send('**Request timed out**')
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
finally: finally:
@ -908,7 +878,7 @@ class MsG:
@e621_paginator.error @e621_paginator.error
async def e621_paginator_error(self, ctx, error): async def e621_paginator_error(self, ctx, error):
if isinstance(error, errext.CheckFailure): if isinstance(error, errext.CheckFailure):
await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel.**'.format(ctx.channel.mention), delete_after=10) await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel**'.format(ctx.channel.mention), delete_after=10)
return await ctx.message.add_reaction('\N{NO ENTRY}') return await ctx.message.add_reaction('\N{NO ENTRY}')
# Searches for and returns images from e621.net given tags when not blacklisted # Searches for and returns images from e621.net given tags when not blacklisted
@ -939,7 +909,7 @@ class MsG:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.TagBlacklisted as e: except exc.TagBlacklisted as e:
await ctx.send('`{}` **blacklisted.**'.format(e), delete_after=10) await ctx.send('`{}` **blacklisted**'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.BoundsError as e: except exc.BoundsError as e:
await ctx.send('`{}` **out of bounds.** Images limited to 3.'.format(e), delete_after=10) await ctx.send('`{}` **out of bounds.** Images limited to 3.'.format(e), delete_after=10)
@ -948,13 +918,13 @@ class MsG:
await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e), delete_after=10) await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.NotFound as e: except exc.NotFound as e:
await ctx.send('`{}` **not found.**'.format(e), delete_after=10) await ctx.send('`{}` **not found**'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.FavoritesNotFound: except exc.FavoritesNotFound:
await ctx.send('**You have no favorite tags.**', delete_after=10) await ctx.send('**You have no favorite tags**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.Timeout: except exc.Timeout:
await ctx.send('**Request timed out.**') await ctx.send('**Request timed out**')
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
# tools.command_dict.setdefault(str(ctx.author.id), {}).update( # tools.command_dict.setdefault(str(ctx.author.id), {}).update(
@ -963,7 +933,7 @@ class MsG:
@e621.error @e621.error
async def e621_error(self, ctx, error): async def e621_error(self, ctx, error):
if isinstance(error, errext.CheckFailure): if isinstance(error, errext.CheckFailure):
await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel.**'.format(ctx.channel.mention), delete_after=10) await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel**'.format(ctx.channel.mention), delete_after=10)
return await ctx.message.add_reaction('\N{NO ENTRY}') return await ctx.message.add_reaction('\N{NO ENTRY}')
# Searches for and returns images from e926.net given tags when not blacklisted # Searches for and returns images from e926.net given tags when not blacklisted
@ -993,7 +963,7 @@ class MsG:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.TagBlacklisted as e: except exc.TagBlacklisted as e:
await ctx.send('`{}` **blacklisted.**'.format(e), delete_after=10) await ctx.send('`{}` **blacklisted**'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.BoundsError as e: except exc.BoundsError as e:
await ctx.send('`{}` **out of bounds.** Images limited to 3.'.format(e), delete_after=10) await ctx.send('`{}` **out of bounds.** Images limited to 3.'.format(e), delete_after=10)
@ -1002,13 +972,13 @@ class MsG:
await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e), delete_after=10) await ctx.send('`{}` **out of bounds.** Tags limited to 5.'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.NotFound as e: except exc.NotFound as e:
await ctx.send('`{}` **not found.**'.format(e), delete_after=10) await ctx.send('`{}` **not found**'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.FavoritesNotFound: except exc.FavoritesNotFound:
await ctx.send('**You have no favorite tags.**', delete_after=10) await ctx.send('**You have no favorite tags**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.Timeout: except exc.Timeout:
await ctx.send('**Request timed out.**') await ctx.send('**Request timed out**')
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@commands.group(aliases=['fave', 'fav', 'f']) @commands.group(aliases=['fave', 'fav', 'f'])
@ -1063,7 +1033,7 @@ class MsG:
await ctx.send('**Favorites list currently limited to:** `5`', delete_after=10) await ctx.send('**Favorites list currently limited to:** `5`', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except exc.TagBlacklisted as e: except exc.TagBlacklisted as e:
await ctx.send('\N{NO ENTRY SIGN} `{}` **blacklisted.**', delete_after=10) await ctx.send('\N{NO ENTRY SIGN} `{}` **blacklisted**', delete_after=10)
await ctx.message.add_reaction('\N{NO ENTRY SIGN}') await ctx.message.add_reaction('\N{NO ENTRY SIGN}')
@_add_favorite.command(name='posts', aliases=['p']) @_add_favorite.command(name='posts', aliases=['p'])
@ -1093,7 +1063,7 @@ class MsG:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.TagError as e: except exc.TagError as e:
await ctx.send('`{}` **not in favorites.**'.format(e), delete_after=10) await ctx.send('`{}` **not in favorites**'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@_remove_favorite.command(name='posts', aliases=['p']) @_remove_favorite.command(name='posts', aliases=['p'])
@ -1112,7 +1082,7 @@ class MsG:
del self.favorites[ctx.author.id] del self.favorites[ctx.author.id]
u.dump(self.favorites, 'cogs/favorites.pkl') u.dump(self.favorites, 'cogs/favorites.pkl')
await dest.send('{}**\'s favorites cleared.**'.format(ctx.author.mention), delete_after=5) await dest.send('{}**\'s favorites cleared**'.format(ctx.author.mention), delete_after=5)
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
@_clear_favorite.command(name='posts', aliases=['p']) @_clear_favorite.command(name='posts', aliases=['p'])
@ -1130,12 +1100,12 @@ class MsG:
# @blacklist.error # @blacklist.error
# async def blacklist_error(self, ctx, error): # async def blacklist_error(self, ctx, error):
# if isinstance(error, KeyError): # if isinstance(error, KeyError):
# return await ctx.send('**Blacklist does not exist.**', delete_after=10) # return await ctx.send('**Blacklist does not exist**', delete_after=10)
@blacklist.group(name='get', aliases=['g']) @blacklist.group(name='get', aliases=['g'])
async def _get_blacklist(self, ctx): async def _get_blacklist(self, ctx):
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
await ctx.send('**Invalid blacklist.**', delete_after=10) await ctx.send('**Invalid blacklist**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@_get_blacklist.command(name='global', aliases=['gl', 'g']) @_get_blacklist.command(name='global', aliases=['gl', 'g'])
@ -1175,7 +1145,7 @@ class MsG:
@_get_blacklist.group(name='all', aliases=['a']) @_get_blacklist.group(name='all', aliases=['a'])
async def __get_all_blacklists(self, ctx): async def __get_all_blacklists(self, ctx):
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
await ctx.send('**Invalid blacklist.**') await ctx.send('**Invalid blacklist**')
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@__get_all_blacklists.command(name='guild', aliases=['g']) @__get_all_blacklists.command(name='guild', aliases=['g'])
@ -1200,7 +1170,7 @@ class MsG:
@blacklist.group(name='add', aliases=['a']) @blacklist.group(name='add', aliases=['a'])
async def _add_tags(self, ctx): async def _add_tags(self, ctx):
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
await ctx.send('**Invalid blacklist.**', delete_after=10) await ctx.send('**Invalid blacklist**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@_add_tags.command(name='global', aliases=['gl', 'g']) @_add_tags.command(name='global', aliases=['gl', 'g'])
@ -1275,7 +1245,7 @@ class MsG:
@blacklist.group(name='remove', aliases=['rm', 'r']) @blacklist.group(name='remove', aliases=['rm', 'r'])
async def _remove_tags(self, ctx): async def _remove_tags(self, ctx):
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
await ctx.send('**Invalid blacklist.**', delete_after=10) await ctx.send('**Invalid blacklist**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@_remove_tags.command(name='global', aliases=['gl', 'g']) @_remove_tags.command(name='global', aliases=['gl', 'g'])
@ -1298,7 +1268,7 @@ class MsG:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.TagError as e: except exc.TagError as e:
await ctx.send('`{}` **not in blacklist.**'.format(e), delete_after=10) await ctx.send('`{}` **not in blacklist**'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@_remove_tags.command(name='channel', aliases=['ch', 'c']) @_remove_tags.command(name='channel', aliases=['ch', 'c'])
@ -1324,7 +1294,7 @@ class MsG:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.TagError as e: except exc.TagError as e:
await ctx.send('`{}` **not in blacklist.**'.format(e), delete_after=10) await ctx.send('`{}` **not in blacklist**'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@_remove_tags.command(name='me', aliases=['m']) @_remove_tags.command(name='me', aliases=['m'])
@ -1346,13 +1316,13 @@ class MsG:
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.TagError as e: except exc.TagError as e:
await ctx.send('`{}` **not in blacklist.**'.format(e), delete_after=10) await ctx.send('`{}` **not in blacklist**'.format(e), delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@blacklist.group(name='clear', aliases=['cl', 'c']) @blacklist.group(name='clear', aliases=['cl', 'c'])
async def _clear_blacklist(self, ctx): async def _clear_blacklist(self, ctx):
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
await ctx.send('**Invalid blacklist.**', delete_after=10) await ctx.send('**Invalid blacklist**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
@_clear_blacklist.command(name='global', aliases=['gl', 'g']) @_clear_blacklist.command(name='global', aliases=['gl', 'g'])
@ -1363,7 +1333,7 @@ class MsG:
self.blacklists['global_blacklist'].clear() self.blacklists['global_blacklist'].clear()
u.dump(self.blacklists, 'cogs/blacklists.pkl') u.dump(self.blacklists, 'cogs/blacklists.pkl')
await dest.send('**Global blacklist cleared.**', delete_after=5) await dest.send('**Global blacklist cleared**', delete_after=5)
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
@_clear_blacklist.command(name='channel', aliases=['ch', 'c']) @_clear_blacklist.command(name='channel', aliases=['ch', 'c'])
@ -1378,7 +1348,7 @@ class MsG:
del self.blacklists['guild_blacklist'][guild.id][ctx.channel.id] del self.blacklists['guild_blacklist'][guild.id][ctx.channel.id]
u.dump(self.blacklists, 'cogs/blacklists.pkl') u.dump(self.blacklists, 'cogs/blacklists.pkl')
await dest.send('{} **blacklist cleared.**'.format(ctx.channel.mention), delete_after=5) await dest.send('{} **blacklist cleared**'.format(ctx.channel.mention), delete_after=5)
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
@_clear_blacklist.command(name='me', aliases=['m']) @_clear_blacklist.command(name='me', aliases=['m'])
@ -1389,5 +1359,5 @@ class MsG:
del self.blacklists['user_blacklist'][ctx.author.id] del self.blacklists['user_blacklist'][ctx.author.id]
u.dump(self.blacklists, 'cogs/blacklists.pkl') u.dump(self.blacklists, 'cogs/blacklists.pkl')
await dest.send('{}**\'s blacklist cleared.**'.format(ctx.author.mention), delete_after=5) await dest.send('{}**\'s blacklist cleared**'.format(ctx.author.mention), delete_after=5)
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')

View file

@ -50,7 +50,7 @@ class Administration:
history = [] history = []
try: try:
pru_sent = await ctx.send('\N{HOURGLASS} **Pruning** <@{}>**\'s messages will take some time.**'.format(user)) pru_sent = await ctx.send('\N{HOURGLASS} **Pruning** <@{}>**\'s messages will take some time**'.format(user))
ch_sent = await ctx.send('\N{FILE CABINET} **Caching channels...**') ch_sent = await ctx.send('\N{FILE CABINET} **Caching channels...**')
if when is None: if when is None:
@ -58,54 +58,54 @@ class Administration:
async for message in channel.history(limit=None): async for message in channel.history(limit=None):
if message.author.id == int(user): if message.author.id == int(user):
history.append(message) history.append(message)
await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels**'.format(channels.index(channel) + 1, len(channels)))
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
elif when == 'before': elif when == 'before':
for channel in channels: for channel in channels:
async for message in channel.history(limit=None, before=ref.created_at): async for message in channel.history(limit=None, before=ref.created_at):
if message.author.id == int(user): if message.author.id == int(user):
history.append(message) history.append(message)
await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels**'.format(channels.index(channel) + 1, len(channels)))
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
elif when == 'after': elif when == 'after':
for channel in channels: for channel in channels:
async for message in channel.history(limit=None, after=ref.created_at): async for message in channel.history(limit=None, after=ref.created_at):
if message.author.id == int(user): if message.author.id == int(user):
history.append(message) history.append(message)
await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels**'.format(channels.index(channel) + 1, len(channels)))
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
elif when == 'about': elif when == 'about':
for channel in channels: for channel in channels:
async for message in channel.history(limit=None, about=ref.created_at): async for message in channel.history(limit=None, about=ref.created_at):
if message.author.id == int(user): if message.author.id == int(user):
history.append(message) history.append(message)
await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels.**'.format(channels.index(channel) + 1, len(channels))) await ch_sent.edit(content='\N{FILE CABINET} **Cached** `{}/{}` **channels**'.format(channels.index(channel) + 1, len(channels)))
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
est_sent = await ctx.send('\N{STOPWATCH} **Estimated time to delete history:** `{}m {}s`'.format(int(self.RATE_LIMIT * len(history) / 60), int(self.RATE_LIMIT * len(history) % 60))) est_sent = await ctx.send('\N{STOPWATCH} **Estimated time to delete history:** `{}m {}s`'.format(int(self.RATE_LIMIT * len(history) / 60), int(self.RATE_LIMIT * len(history) % 60)))
cont_sent = await ctx.send('{} **Continue?** `Y` or `N`'.format(ctx.author.mention)) cont_sent = await ctx.send('{} **Continue?** `Y` or `N`'.format(ctx.author.mention))
await self.bot.wait_for('message', check=yes, timeout=10 * 60) await self.bot.wait_for('message', check=yes, timeout=10 * 60)
await cont_sent.delete() await cont_sent.delete()
del_sent = await ctx.send('\N{WASTEBASKET} **Deleting messages...**') del_sent = await ctx.send('\N{WASTEBASKET} **Deleting messages..**')
await del_sent.pin() await del_sent.pin()
c = 0 c = 0
for message in history: for message in history:
with suppress(err.NotFound): with suppress(err.NotFound):
await message.delete() await message.delete()
c += 1 c += 1
await del_sent.edit(content='\N{WASTEBASKET} **Deleted** `{}/{}` **messages.**'.format(history.index(message) + 1, len(history))) await del_sent.edit(content='\N{WASTEBASKET} **Deleted** `{}/{}` **messages**'.format(history.index(message) + 1, len(history)))
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
await del_sent.unpin() await del_sent.unpin()
await ctx.send('\N{WASTEBASKET} `{}` **of** <@{}>**\'s messages left in** {}**.**'.format(len(history) - c, user, ctx.guild.name)) await ctx.send('\N{WASTEBASKET} `{}` **of** <@{}>**\'s messages left in** {}****'.format(len(history) - c, user, ctx.guild.name))
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
except exc.CheckFail: except exc.CheckFail:
await ctx.send('**Deletion aborted.**', delete_after=10) await ctx.send('**Deletion aborted**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
except TimeoutError: except TimeoutError:
await ctx.send('**Deletion timed out.**', delete_after=10) await ctx.send('**Deletion timed out**', delete_after=10)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{CROSS MARK}')
async def delete(self): async def delete(self):
@ -143,9 +143,9 @@ class Administration:
if not u.tasks['auto_del']: if not u.tasks['auto_del']:
self.deleting = False self.deleting = False
print('STOPPED : deleting #{}'.format(channel.id)) print('STOPPED : deleting #{}'.format(channel.id))
await channel.send('**Stopped queueing messages for deletion in** {}**.**'.format(channel.mention), delete_after=5) await channel.send('**Stopped queueing messages for deletion in** {}'.format(channel.mention), delete_after=5)
@commands.command(name='autodelete', aliases=['autodel', 'ad']) @commands.command(name='autodelete', aliases=['autodel'])
@commands.has_permissions(administrator=True) @commands.has_permissions(administrator=True)
@checks.del_ctx() @checks.del_ctx()
async def auto_delete(self, ctx): async def auto_delete(self, ctx):
@ -158,7 +158,7 @@ class Administration:
self.bot.loop.create_task(self.delete()) self.bot.loop.create_task(self.delete())
self.deleting = True self.deleting = True
print('AUTO-DELETING : #{}'.format(ctx.channel.id)) print('AUTO-DELETING : #{}'.format(ctx.channel.id))
await ctx.send('**Auto-deleting all messages in {}.**'.format(ctx.channel.mention), delete_after=5) await ctx.send('**Auto-deleting all messages in {}**'.format(ctx.channel.mention), delete_after=5)
await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await ctx.message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
else: else:
raise exc.Exists raise exc.Exists

View file

@ -105,11 +105,11 @@ class Utils:
print('https://www.youtube.com/watch?v=' + youtube.videos().insert(part='snippet', print('https://www.youtube.com/watch?v=' + youtube.videos().insert(part='snippet',
body={'categoryId': '24', 'title': 'Test'}, media_body=http.MediaFileUpload(temp.name, chunksize=-1))) body={'categoryId': '24', 'title': 'Test'}, media_body=http.MediaFileUpload(temp.name, chunksize=-1)))
except exc.InvalidVideoFile as e: except exc.InvalidVideoFile as e:
await ctx.send('`' + str(e) + '` **not valid video type.**', delete_after=10) await ctx.send('`' + str(e) + '` **invalid video type**', delete_after=10)
except exc.TooManyAttachments as e: except exc.TooManyAttachments as e:
await ctx.send('`' + str(e) + '` **too many attachments.** Only one attachment is permitted to upload.', delete_after=10) await ctx.send('`' + str(e) + '` **too many attachments.** Only one attachment is permitted to upload.', delete_after=10)
except exc.MissingAttachment: except exc.MissingAttachment:
await ctx.send('**Missing attachment.**', delete_after=10) await ctx.send('**Missing attachment**', delete_after=10)
@upload.error @upload.error
async def upload_error(self, ctx, error): async def upload_error(self, ctx, error):

View file

@ -59,7 +59,7 @@ async def on_ready():
@bot.event @bot.event
async def on_message(message): async def on_message(message):
if message.author.bot or message.author is bot.user: if message.author is bot.user:
return return
await bot.process_commands(message) await bot.process_commands(message)
@ -84,11 +84,11 @@ async def on_error(error, *args, **kwargs):
@bot.event @bot.event
async def on_command_error(ctx, error): async def on_command_error(ctx, error):
if isinstance(error, errext.CheckFailure): if isinstance(error, errext.CheckFailure):
await ctx.send('\N{NO ENTRY} **Insufficient permissions.**', delete_after=10) await ctx.send('\N{NO ENTRY} **Insufficient permissions**', delete_after=10)
await ctx.message.add_reaction('\N{NO ENTRY}') await ctx.message.add_reaction('\N{NO ENTRY}')
elif isinstance(error, errext.CommandNotFound): elif isinstance(error, errext.CommandNotFound):
print('INVALID COMMAND : {}'.format(error), file=sys.stderr) print('INVALID COMMAND : {}'.format(error), file=sys.stderr)
await ctx.message.add_reaction('\N{CROSS MARK}') await ctx.message.add_reaction('\N{BLACK QUESTION MARK ORNAMENT}')
else: else:
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)

View file

@ -87,8 +87,6 @@ session = aiohttp.ClientSession()
def close(loop): def close(loop):
global session
if session: if session:
session.close() session.close()
@ -104,8 +102,6 @@ def close(loop):
async def fetch(url, *, params={}, json=False): async def fetch(url, *, params={}, json=False):
global session
async with session.get(url, params=params, headers={'User-Agent': 'Myned/Modumind/dev'}) as r: async with session.get(url, params=params, headers={'User-Agent': 'Myned/Modumind/dev'}) as r:
if json: if json:
return await r.json() return await r.json()
@ -121,19 +117,17 @@ def get_kwargs(ctx, args, *, limit=False):
rm = False rm = False
lim = 1 lim = 1
if '-d' in remaining or '-dm' in remaining: for flag in ('-d', '-dm'):
destination = ctx.author if flag in remaining:
destination = ctx.author
for flag in ('-d', '-dm'): remaining.remove(flag)
with suppress(ValueError):
remaining.remove(flag)
if ('-r' in remaining or '-rm' in remaining or '-remove' in remaining) and ctx.author.permissions_in(ctx.channel).manage_messages: for flag in ('-r', '-rm', '-remove', '-re', '-repl', '-replace'):
rm = True if flag in remaining and ctx.author.permissions_in(ctx.channel).manage_messages:
rm = True
for flag in ('-r', '-rm', '-remove'): remaining.remove(flag)
with suppress(ValueError):
remaining.remove(flag)
if limit: if limit:
for arg in remaining: for arg in remaining: