From 23c49f480a957bba8649dcc1832db796d17da2d8 Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:21:28 -0500 Subject: [PATCH 01/13] Shortened method name to fit with command --- src/cogs/management.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cogs/management.py b/src/cogs/management.py index 7b38be9..d0f9978 100644 --- a/src/cogs/management.py +++ b/src/cogs/management.py @@ -179,7 +179,7 @@ class Administration: pass @settings.command(name='deletecommands', aliases=['delcmds', 'delcmd']) - async def _settings_delete_commands(self, ctx): + async def _settings_deletecommands(self, ctx): if ctx.guild.id not in u.settings['del_ctx']: u.settings['del_ctx'].append(ctx.guild.id) else: From 4c58a9e1a771c7cdcd2f673519745a560aadf87f Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:22:38 -0500 Subject: [PATCH 02/13] WIP music cog --- src/cogs/music.py | 57 ++++++++++++++++++++++++++++++++++++++++++++ src/cogs/periodic.py | 8 +++++++ src/run.py | 8 +++---- src/temp/__init__.py | 0 src/utils/utils.py | 1 + 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 src/cogs/music.py create mode 100644 src/temp/__init__.py diff --git a/src/cogs/music.py b/src/cogs/music.py new file mode 100644 index 0000000..6f44964 --- /dev/null +++ b/src/cogs/music.py @@ -0,0 +1,57 @@ +import asyncio +import json +from datetime import datetime as dt +from urllib import parse +import re +from pprint import pprint + +import discord as d +from discord import errors as err +from discord.ext import commands as cmds +from discord.ext.commands import errors as errext +import gmusicapi as gpm +import googleapiclient as gapic +import apiclient as apic + +from misc import exceptions as exc +from misc import checks +from utils import utils as u + + +class Music: + + def __init__(self, bot): + self.bot = bot + + self.yt_service = apic.discovery.build('youtube', 'v3', developerKey=u.secrets['client_secrets']['client_secret']) + + @cmds.group(aliases=['pl'], brief='(G) Play music', description='Play music from YouTube, Soundcloud, or Google Play Music') + async def play(self, ctx): + print(ctx.invoked_subcommand) + + @play.command(name='youtube', aliases=['you', 'tube', 'yt', 'y']) + async def _play_youtube(self, ctx, *videos): + try: + if not videos: + raise exc.MissingArgument + + vids = [] + + for video in videos: + if 'http' in video and 'youtube' in video: + vids.append(parse.parse_qs(parse.urlparse(video).query)['v'][0]) + else: + vids.append(video) + + print(vids) + + response = self.yt_service.videos().list(part='snippet', id=','.join(vids)).execute() + pprint(response) + + except exc.MissingArgument: + await ctx.send('**Invalid youtube url or ID**', delete_after=7) + await ctx.message.add_reaction('\N{CROSS MARK}') + + @play.command(name='googleplaymusic', aliases=['googleplay', 'googlemusic', 'playmusic', 'play', 'gpm']) + async def _play_googleplaymusic(self, ctx, query): + pass diff --git a/src/cogs/periodic.py b/src/cogs/periodic.py index 49a85c5..1f36b88 100644 --- a/src/cogs/periodic.py +++ b/src/cogs/periodic.py @@ -23,3 +23,11 @@ class Post: async def _check_posts(self, user, channel): pass + + @cmds.group(aliases=['update', 'up', 'u']) + async def updates(self, ctx): + pass + + @updates.command(name='googleplaymusic', aliases=['googlemusic', 'playmusic', 'music', 'gpm']) + async def _updates_googleplaymusic(self, ctx): + pass diff --git a/src/run.py b/src/run.py index 933a153..ed72b9d 100644 --- a/src/run.py +++ b/src/run.py @@ -70,9 +70,11 @@ async def test(ctx): @bot.event async def on_ready(): if not checks.ready: - from cogs import booru, info, management, owner, tools + # d.opus.load_opus('opuslib') - for cog in (tools.Utils(bot), owner.Bot(bot), owner.Tools(bot), management.Administration(bot), info.Info(bot), booru.MsG(bot)): + from cogs import booru, info, management, music, owner, tools + + for cog in (tools.Utils(bot), owner.Bot(bot), owner.Tools(bot), management.Administration(bot), music.Music(bot), info.Info(bot), booru.MsG(bot)): bot.add_cog(cog) print(f'COG : {type(cog).__name__}') @@ -183,8 +185,6 @@ async def on_guild_remove(guild): print(f'STOPPED : {task} in #{channel.id}') u.dump(u.tasks, 'cogs/tasks.pkl') -# d.opus.load_opus('opus') - async def wait(voice): asyncio.sleep(5) diff --git a/src/temp/__init__.py b/src/temp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/utils/utils.py b/src/utils/utils.py index 4c865b0..55e1b9f 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -85,6 +85,7 @@ def dump(obj, filename, *, json=False): settings = setdefault('misc/settings.pkl', {'del_ctx': [], 'prefixes': {}}) tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_rev': [], 'periodic_gpm': []}) temp = setdefault('temp/temp.pkl', {'startup': ()}) +secrets = setdefault('secrets.json', {'client_secrets': {'client_id': '', 'client_secret': ''}}, json=True) RATE_LIMIT = 2.2 color = d.Color(0x1A1A1A) From 516902a206791e4dea609369a3c2c69c0c262738 Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:25:37 -0500 Subject: [PATCH 03/13] Added auto-hearting to tasks file (requires deleting tasks.pkl --- src/utils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/utils.py b/src/utils/utils.py index 55e1b9f..4c555fe 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -83,7 +83,7 @@ def dump(obj, filename, *, json=False): settings = setdefault('misc/settings.pkl', {'del_ctx': [], 'prefixes': {}}) -tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_rev': [], 'periodic_gpm': []}) +tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_hrt': [], 'auto_rev': [], 'periodic_gpm': []}) temp = setdefault('temp/temp.pkl', {'startup': ()}) secrets = setdefault('secrets.json', {'client_secrets': {'client_id': '', 'client_secret': ''}}, json=True) From 7ac6653353e908b6b5d8973d43383f7c89d0e9ed Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:26:08 -0500 Subject: [PATCH 04/13] WIP del_response setting --- src/run.py | 5 +++++ src/utils/utils.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/run.py b/src/run.py index ed72b9d..0c401dc 100644 --- a/src/run.py +++ b/src/run.py @@ -159,6 +159,11 @@ async def on_command_error(ctx, error): await ctx.message.add_reaction('\N{WARNING SIGN}') # u.notify('C O M M A N D E R R O R') +# @bot.event +# async def on_command(ctx): +# if ctx.guild.id in u.settings['del_resp']: +# pass + @bot.event async def on_command_completion(ctx): with suppress(err.NotFound): diff --git a/src/utils/utils.py b/src/utils/utils.py index 4c555fe..ebb30d1 100644 --- a/src/utils/utils.py +++ b/src/utils/utils.py @@ -82,7 +82,7 @@ def dump(obj, filename, *, json=False): jsn.dump(obj, outfile, indent=4, sort_keys=True) -settings = setdefault('misc/settings.pkl', {'del_ctx': [], 'prefixes': {}}) +settings = setdefault('misc/settings.pkl', {'del_ctx': [], 'del_resp': [], 'prefixes': {}}) tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_hrt': [], 'auto_rev': [], 'periodic_gpm': []}) temp = setdefault('temp/temp.pkl', {'startup': ()}) secrets = setdefault('secrets.json', {'client_secrets': {'client_id': '', 'client_secret': ''}}, json=True) From 3f73419f796c1b43d7b27061c18ef7b28e6e7178 Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:26:17 -0500 Subject: [PATCH 05/13] Formatting --- src/utils/scraper.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/scraper.py b/src/utils/scraper.py index ccb60fe..d03990a 100644 --- a/src/utils/scraper.py +++ b/src/utils/scraper.py @@ -15,6 +15,7 @@ async def get_post(url): filesize = int(image.headers['Content-Length']) if filesize > 8192 * 1024: raise exc.SizeError(size(filesize, system=alternative)) + except ValueError: raise exc.MissingArgument From 165d134b6de33c2b5392e2e172b54526bb7a0f95 Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:26:47 -0500 Subject: [PATCH 06/13] Added message attribute to Save exception --- src/misc/exceptions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/misc/exceptions.py b/src/misc/exceptions.py index ae9af19..965ebe9 100644 --- a/src/misc/exceptions.py +++ b/src/misc/exceptions.py @@ -39,9 +39,9 @@ class Right(Exception): class Save(Exception): - def __init__(self, user=None): + def __init__(self, user=None, message=None): self.user = user - + self.message = message class GoTo(Exception): pass From 70ec1bdb9c30951fe2608460bbc71a9b48bb11aa Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:28:58 -0500 Subject: [PATCH 07/13] Changed "stop" tasks command to be specific to each task (ie stop rev) --- src/cogs/booru.py | 26 ++++++++++++++------------ src/cogs/management.py | 6 +++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index 59ce58f..9ee8bf9 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -124,9 +124,9 @@ class MsG: while self.hearting: temp = await self.heartqueue.get() - await temp[0].send(embed=temp[1]) + await temp[0].send(embed=temp[1]) - await asyncio.sleep(self.RATE_LIMIT) + await asyncio.sleep(self.RATE_LIMIT) print('STOPPED : hearting') @@ -135,21 +135,23 @@ class MsG: if reaction.emoji == '\N{HEAVY BLACK HEART}' and reaction.message.id == message.id: raise exc.Save(user) return False + if 'stop h' in msg.content.lower(): - try: - await message.add_reaction('\N{HEAVY BLACK HEART}') - await asyncio.sleep(1) + try: + await message.add_reaction('\N{HEAVY BLACK HEART}') + await asyncio.sleep(1) - while self.hearting: - try: + while self.hearting: + try: await asyncio.gather(*[self.bot.wait_for('reaction_add', check=on_reaction, timeout=60 * 60), self.bot.wait_for('reaction_remove', check=on_reaction, timeout=60 * 60)]) - except exc.Save as e: + except exc.Save as e: await self.heartqueue.put((e.user, send)) - except asyncio.TimeoutError: - await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + except asyncio.TimeoutError: + await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + await ctx.send('**Already auto-hearting in {}.** Type `stop h(earting)` to stop.'.format(ctx.channel.mention), delete_after=7) # @cmds.command() # async def auto_post(self, ctx): @@ -518,7 +520,7 @@ class MsG: async def queue_for_reversification(self, channel): def check(msg): - if msg.content.lower() == 'stop' and msg.channel is channel and msg.author.guild_permissions.administrator: + if 'stop r' in msg.content.lower() and msg.channel is channel and msg.author.guild_permissions.administrator: raise exc.Abort 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 @@ -553,7 +555,7 @@ class MsG: print('STARTED : auto-reversifying in #{}'.format(ctx.channel.name)) await ctx.send('**Auto-reversifying all images in** {}'.format(ctx.channel.mention), delete_after=5) else: - await ctx.send('**Already auto-reversifying in {}.** Type `stop` to stop.'.format(ctx.channel.mention), delete_after=7) + await ctx.send('**Already auto-reversifying in {}.** Type `stop r(eversifying)` to stop.'.format(ctx.channel.mention), delete_after=7) await ctx.message.add_reaction('\N{CROSS MARK}') async def _get_pool(self, ctx, *, destination, booru='e621', query=[]): diff --git a/src/cogs/management.py b/src/cogs/management.py index d0f9978..287bbc7 100644 --- a/src/cogs/management.py +++ b/src/cogs/management.py @@ -128,7 +128,7 @@ class Administration: async def queue_for_deletion(self, channel): def check(msg): - if msg.content.lower() == 'stop' and msg.channel is channel and msg.author.guild_permissions.administrator: + if 'stop d' in msg.content.lower() 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 @@ -136,7 +136,7 @@ class Administration: try: async for message in channel.history(limit=None): - if message.content.lower() == 'stop' and message.author.guild_permissions.administrator: + if 'stop d' in message.content.lower() and message.author.guild_permissions.administrator: raise exc.Abort if not message.pinned: await self.queue.put(message) @@ -170,7 +170,7 @@ class Administration: raise exc.Exists except exc.Exists: - await ctx.send('**Already auto-deleting in {}.** Type `stop` to stop.'.format(ctx.channel.mention), delete_after=7) + await ctx.send('**Already auto-deleting in {}.** Type `stop d(eleting)` to stop.'.format(ctx.channel.mention), delete_after=7) await ctx.message.add_reaction('\N{CROSS MARK}') @cmds.group(aliases=['setting', 'set', 's']) From 7d9f9d971888469ef72e0cbb5452b239f2ba7771 Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:29:35 -0500 Subject: [PATCH 08/13] WIP del_response setting (command toggle) --- src/cogs/management.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/cogs/management.py b/src/cogs/management.py index 287bbc7..913a100 100644 --- a/src/cogs/management.py +++ b/src/cogs/management.py @@ -197,3 +197,13 @@ class Administration: del u.settings['prefixes'][ctx.guild.id] await ctx.send(f'**Prefix set to:** `{"` or `".join(prefixes if ctx.guild.id in u.settings["prefixes"] else u.config["prefix"])}`') + + @settings.command(name='deleteresponses', aliases=['delresps', 'delresp']) + async def _settings_deleteresponses(self, ctx): + if ctx.guild.id not in u.settings['del_resp']: + u.settings['del_resp'].append(ctx.guild.id) + else: + u.settings['del_resp'].remove(ctx.guild.id) + u.dump(u.settings, 'settings.pkl') + + await ctx.send(f'**Delete command responses:** `{ctx.guild.id in u.settings["del_resp"]}`') From b43b863c152fe269d34a8f42c544849f5229d45b Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:53:59 -0500 Subject: [PATCH 09/13] WIP conversion to group task commands --- src/cogs/management.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cogs/management.py b/src/cogs/management.py index 913a100..3bd4130 100644 --- a/src/cogs/management.py +++ b/src/cogs/management.py @@ -116,6 +116,10 @@ class Administration: await ctx.send('**Deletion timed out**', delete_after=7) await ctx.message.add_reaction('\N{CROSS MARK}') + @cmds.group(aliases=['task', 'tsk']) + async def tasks(self): + pass + async def delete(self): while self.deleting: message = await self.queue.get() From 3aac112ecb9a1e4b1ab02a11f603e288c673c2eb Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:54:37 -0500 Subject: [PATCH 10/13] Added auto-heart command --- src/cogs/booru.py | 71 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index 9ee8bf9..de9c72a 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -55,6 +55,11 @@ class MsG: print('STARTED : auto-reversifying in #{}'.format(temp.name)) self.reversifying = True self.bot.loop.create_task(self._reversify()) + if u.tasks['auto_hrt']: + for channel in u.tasks['auto_hrt']: + temp = self.bot.get_channel(channel) + self.bot.loop.create_task(self.queue_for_hearts(channel=temp)) + print(f'STARTED : auto-hearting in #{temp.name}') # if not self.updating: # self.updating = True # self.bot.loop.create_task(self._update_suggested()) @@ -124,34 +129,92 @@ class MsG: while self.hearting: temp = await self.heartqueue.get() + if isinstance(temp[1], d.Embed): await temp[0].send(embed=temp[1]) await asyncio.sleep(self.RATE_LIMIT) + elif isinstance(temp[1], d.Message): + for match in re.finditer('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', temp[1].content): + await temp[0].send(match) + + await asyncio.sleep(self.RATE_LIMIT) + + for attachment in temp[1].attachments: + await temp[0].send(attachment.url) + await asyncio.sleep(self.RATE_LIMIT) print('STOPPED : hearting') - async def queue_for_hearts(self, *, message, send): + async def queue_for_hearts(self, *, message=None, send=None, channel=None, reaction=True, timeout=60 * 60): def on_reaction(reaction, user): if reaction.emoji == '\N{HEAVY BLACK HEART}' and reaction.message.id == message.id: raise exc.Save(user) return False + def on_message(msg): if 'stop h' in msg.content.lower(): + raise exc.Abort + return msg.channel.id == channel.id and (re.search('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', msg.content) or msg.attachments) + if message: try: + if reaction: await message.add_reaction('\N{HEAVY BLACK HEART}') await asyncio.sleep(1) while self.hearting: try: - await asyncio.gather(*[self.bot.wait_for('reaction_add', check=on_reaction, timeout=60 * 60), - self.bot.wait_for('reaction_remove', check=on_reaction, timeout=60 * 60)]) + await self.bot.wait_for('reaction_add', check=on_reaction, timeout=timeout) except exc.Save as e: - await self.heartqueue.put((e.user, send)) + await self.heartqueue.put((e.user, send if send else message)) except asyncio.TimeoutError: await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') + else: + try: + async for message in channel.history(limit=300): + if re.search('(https?:\/\/[^ ]*\.(?:gif|png|jpg|jpeg))', message.content) or message.attachments: + self.bot.loop.create_task(self._wait_for_reaction(message)) + + while self.hearting: + message = await self.bot.wait_for('message', check=on_message) + self.bot.loop.create_task(self._wait_for_reaction(message)) + + except exc.Abort: + u.tasks['auto_hrt'].remove(channel.id) + u.dump(u.tasks, 'cogs/tasks.pkl') + print('STOPPED : auto-hearting in #{}'.format(channel.name)) + await channel.send('**Stopped queueing messages for hearting in** {}'.format(channel.mention), delete_after=5) + + async def _wait_for_reaction(self, message): + def on_reaction(reaction, user): + if reaction.emoji == '\N{HEAVY BLACK HEART}' and reaction.message.id == message.id: + raise exc.Save(user) + return False + + while self.hearting: + try: + await self.bot.wait_for('reaction_add', check=on_reaction) + + except exc.Save as e: + await self.heartqueue.put((e.user, message)) + + @cmds.command(name='autoheart', aliases=['autohrt']) + @cmds.has_permissions(administrator=True) + async def auto_heart(self, ctx): + try: + if ctx.channel.id not in u.tasks['auto_hrt']: + u.tasks['auto_hrt'].append(ctx.channel.id) + u.dump(u.tasks, 'cogs/tasks.pkl') + self.bot.loop.create_task(self.queue_for_hearts(channel=ctx.channel)) + print('STARTED : auto-hearting in #{}'.format(ctx.channel.name)) + await ctx.send('**Auto-hearting all messages in {}**'.format(ctx.channel.mention), delete_after=5) + else: + raise exc.Exists + + except exc.Exists: await ctx.send('**Already auto-hearting in {}.** Type `stop h(earting)` to stop.'.format(ctx.channel.mention), delete_after=7) + await ctx.message.add_reaction('\N{CROSS MARK}') # @cmds.command() # async def auto_post(self, ctx): From 003f4af690a6d354d6c3bd4bd39a9bfaf2c04392 Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:55:04 -0500 Subject: [PATCH 11/13] Removed aspect ratio from reverse embed --- src/cogs/booru.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index de9c72a..185f366 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -326,7 +326,7 @@ class MsG: embed = d.Embed( title=', '.join(post['artist']), url=f'https://e621.net/post/show/{post["id"]}', color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color) embed.set_thumbnail(url=post['file_url']) - embed.set_author(name=f'{u.get_aspectratio(post["width"], post["height"])} \N{ZERO WIDTH SPACE} {post["width"]} x {post["height"]}', + embed.set_author(name=f'{post["width"]} x {post["height"]}', url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=ctx.author.avatar_url) embed.set_footer(text=post['score'], icon_url=self._get_score(post['score'])) @@ -438,7 +438,7 @@ class MsG: embed = d.Embed( title=', '.join(post['artist']), url=f'https://e621.net/post/show/{post["id"]}', color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color) embed.set_image(url=post['file_url']) - embed.set_author(name=f'{u.get_aspectratio(post["width"], post["height"])} \N{ZERO WIDTH SPACE} {post["width"]} x {post["height"]}', + embed.set_author(name=f'{post["width"]} x {post["height"]}', url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=ctx.author.avatar_url) embed.set_footer(text=post['score'], icon_url=self._get_score(post['score'])) @@ -501,7 +501,7 @@ class MsG: embed = d.Embed( title=', '.join(post['artist']), url=f'https://e621.net/post/show/{post["id"]}', color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color) embed.set_image(url=post['file_url']) - embed.set_author(name=f'{u.get_aspectratio(post["width"], post["height"])} \N{ZERO WIDTH SPACE} {post["width"]} x {post["height"]}', + embed.set_author(name=f'{post["width"]} x {post["height"]}', url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=ctx.author.avatar_url) embed.set_footer( text=post['score'], icon_url=self._get_score(post['score'])) @@ -557,7 +557,7 @@ class MsG: embed = d.Embed( title=', '.join(post['artist']), url=f'https://e621.net/post/show/{post["id"]}', color=message.channel.guild.me.color if isinstance(message.channel, d.TextChannel) else u.color) embed.set_image(url=post['file_url']) - embed.set_author(name=f'{u.get_aspectratio(post["width"], post["height"])} \N{ZERO WIDTH SPACE} {post["width"]} x {post["height"]}', + embed.set_author(name=f'{post["width"]} x {post["height"]}', url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=message.author.avatar_url) embed.set_footer(text=post['score'], icon_url=self._get_score(post['score']['score'])) From bab99329498b0d4ee044f313eefa34ae9fb25ab8 Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:55:23 -0500 Subject: [PATCH 12/13] Fixed reference error --- src/cogs/booru.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index 185f366..cb5dcf8 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -560,7 +560,7 @@ class MsG: embed.set_author(name=f'{post["width"]} x {post["height"]}', url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=message.author.avatar_url) embed.set_footer(text=post['score'], - icon_url=self._get_score(post['score']['score'])) + icon_url=self._get_score(post['score'])) await message.channel.send('**Probable match from** {}'.format(message.author.display_name), embed=embed) From 709da02ffedf388a739f24602f7b300c28043bfa Mon Sep 17 00:00:00 2001 From: Myned Date: Sun, 31 Dec 2017 21:56:01 -0500 Subject: [PATCH 13/13] Moved sleep and message deletion to trigger on successful reverse --- src/cogs/booru.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/cogs/booru.py b/src/cogs/booru.py index cb5dcf8..f6b3192 100644 --- a/src/cogs/booru.py +++ b/src/cogs/booru.py @@ -566,18 +566,20 @@ class MsG: 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=7) await message.add_reaction('\N{CROSS MARK}') except exc.SizeError as e: await message.channel.send(f'`{e}` **too large.** Maximum is 8 MB', delete_after=7) await message.add_reaction('\N{CROSS MARK}') - - finally: - await asyncio.sleep(self.RATE_LIMIT) - - with suppress(err.NotFound): - await message.delete() + except Exception: + await message.channel.send(f'**An unknown error occurred.**', delete_after=7) + await message.add_reaction('\N{WARNING SIGN}') print('STOPPED : reversifying')