From ba10b668a73579136042c5714ba15c783a092008 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 30 Oct 2017 15:48:00 -0400 Subject: [PATCH 1/6] Added restart/startup reaction to shutdown command --- src/main/cogs/owner.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/cogs/owner.py b/src/main/cogs/owner.py index 3670ee7..6063a72 100644 --- a/src/main/cogs/owner.py +++ b/src/main/cogs/owner.py @@ -29,6 +29,11 @@ class Bot: await ctx.message.add_reaction('🌙') await self.bot.get_channel(u.config['info_channel']).send('**Shutting down** 🌙 . . .') + + u.temp['restart_ch'] = ctx.channel.id + u.temp['restart_msg'] = ctx.message.id + u.dump(u.temp, 'temp.pkl') + # loop = self.bot.loop.all_tasks() # for task in loop: # task.cancel() From 801ee2be716ca80afc6cf460ff0abf022dfe0234 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 30 Oct 2017 23:28:37 -0400 Subject: [PATCH 2/6] Changed "restart_(ch to chan)" to "startup_" for clarity with shutdown --- src/main/cogs/owner.py | 8 ++++---- src/main/run.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/cogs/owner.py b/src/main/cogs/owner.py index 6063a72..9982a9e 100644 --- a/src/main/cogs/owner.py +++ b/src/main/cogs/owner.py @@ -30,8 +30,8 @@ class Bot: await self.bot.get_channel(u.config['info_channel']).send('**Shutting down** 🌙 . . .') - u.temp['restart_ch'] = ctx.channel.id - u.temp['restart_msg'] = ctx.message.id + u.temp['startup_chan'] = ctx.channel.id + u.temp['startup_msg'] = ctx.message.id u.dump(u.temp, 'temp.pkl') # loop = self.bot.loop.all_tasks() @@ -52,8 +52,8 @@ class Bot: await self.bot.get_channel(u.config['info_channel']).send('**Restarting** 💤 . . .') # u.notify('R E S T A R T I N G') - u.temp['restart_ch'] = ctx.channel.id - u.temp['restart_msg'] = ctx.message.id + u.temp['startup_chan'] = ctx.channel.id + u.temp['startup_msg'] = ctx.message.id u.dump(u.temp, 'temp.pkl') # loop = self.bot.loop.all_tasks() diff --git a/src/main/run.py b/src/main/run.py index 46be830..b958072 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -51,8 +51,8 @@ async def on_ready(): await bot.get_channel(u.config['info_channel']).send('**Started** ☀️ .') # u.notify('C O N N E C T E D') if u.temp: - channel = bot.get_channel(u.temp['restart_ch']) - message = await channel.get_message(u.temp['restart_msg']) + channel = bot.get_channel(u.temp['startup_chan']) + message = await channel.get_message(u.temp['startup_msg']) await message.add_reaction('✅') u.temp.clear() @@ -70,8 +70,8 @@ async def on_error(error, *args, **kwargs): await bot.get_user(u.config['owner_id']).send('**ERROR** ⚠\n```\n{}```'.format(error)) await bot.get_channel(u.config['info_channel']).send('**ERROR** ⚠\n```\n{}```'.format(error)) if u.temp: - channel = bot.get_channel(u.temp['restart_ch']) - message = await channel.get_message(u.temp['restart_msg']) + channel = bot.get_channel(u.temp['startup_chan']) + message = await channel.get_message(u.temp['startup_msg']) await message.add_reaction('⚠') u.temp.clear() # u.notify('E R R O R') From 17b8ccb895a3b35e40bbcea4e89ac08b80de3b50 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 30 Oct 2017 23:29:22 -0400 Subject: [PATCH 3/6] Changed formatter to use any order: tag --- src/main/utils/formatter.py | 58 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/utils/formatter.py b/src/main/utils/formatter.py index d2644cf..87f3f74 100644 --- a/src/main/utils/formatter.py +++ b/src/main/utils/formatter.py @@ -1,38 +1,38 @@ -def tostring(i, *, random=False): - o = '' - if i: - for v in i: - o += v + ' ' - o = o[:-1] - elif random is True: - o += 'order:random' - else: - o = ' ' - return o +def tostring(i, *, order=None): + o = '' + if i: + for v in i: + o += v + ' ' + o = o[:-1] + elif order: + o += order + else: + o = ' ' + return o def tostring_commas(i): - if i: - o = ',' - for v in i: - o += v + ',' - return o[:-1] - return '' + if i: + o = ',' + for v in i: + o += v + ',' + return o[:-1] + return '' def dict_tostring(i): - o = '' - if i: - for k, v in i.items(): - o += '**' + k + ':** `' + tostring(v) + '`\n' - return o + o = '' + if i: + for k, v in i.items(): + o += '**' + k + ':** `' + tostring(v) + '`\n' + return o def dictelem_tostring(i): - o = '' - if i: - for dic, elem in i.items(): - o += '**__' + dic + '__**\n' - for k, v in elem.items(): - o += '***' + k + ':*** `' + tostring(v) + '`\n' - return o + o = '' + if i: + for dic, elem in i.items(): + o += '**__' + dic + '__**\n' + for k, v in elem.items(): + o += '***' + k + ':*** `' + tostring(v) + '`\n' + return o From ba78274b36cf6949e4223abdb4809a240e0937f4 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 30 Oct 2017 23:32:55 -0400 Subject: [PATCH 4/6] Changed e621 icon to display score according to set ranges as emoji --- src/main/cogs/booru.py | 52 +++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index 6aaa6b4..e07ba61 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -483,6 +483,19 @@ class MsG: return args + def _get_score(self, score): + if score <= 0: + return 'https://emojipedia-us.s3.amazonaws.com/thumbs/320/mozilla/36/pile-of-poo_1f4a9.png' + elif 10 > score > 0: + return 'https://emojipedia-us.s3.amazonaws.com/thumbs/320/twitter/103/white-medium-star_2b50.png' + elif 50 > score >= 10: + return 'https://emojipedia-us.s3.amazonaws.com/thumbs/320/twitter/103/glowing-star_1f31f.png' + elif 100 > score >= 50: + return 'https://emojipedia-us.s3.amazonaws.com/thumbs/320/twitter/103/dizzy-symbol_1f4ab.png' + elif score >= 100: + return 'https://emojipedia-us.s3.amazonaws.com/thumbs/320/twitter/103/sparkles_2728.png' + return None + async def _get_pool(self, ctx, *, destination, booru='e621', query=[]): def on_reaction(reaction, user): if reaction.emoji == '🛑' and reaction.message.id == ctx.message.id and user is ctx.author: @@ -585,7 +598,8 @@ class MsG: except exc.Continue: continue if post['id'] not in posts.keys() and post['id'] not in previous.keys(): - posts[post['id']] = {'artist': ', '.join(post['artist']), 'url': post['file_url']} + posts[post['id']] = {'artist': ', '.join( + post['artist']), 'url': post['file_url'], 'score': post['score']} if len(posts) == limit: break @@ -640,8 +654,8 @@ class MsG: embed.set_image(url=values[c - 1]['url']) embed.set_author(name=pool['name'], url='https://e621.net/pool/show?id={}'.format(pool['id']), icon_url=ctx.author.avatar_url) - embed.set_footer(text='{} / {}'.format(c, len(posts)), - icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)), + icon_url=self._get_score(values[c - 1]['score'])) paginator = await dest.send(embed=embed) @@ -672,8 +686,8 @@ class MsG: c -= 1 embed.title = values[c - 1]['artist'] embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) - embed.set_footer(text='{} / {}'.format(c, len(posts)), - icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)), + icon_url=self._get_score(values[c - 1]['score'])) embed.set_image(url=values[c - 1]['url']) await paginator.edit(content='❤' if values[c - 1]['url'] in hearted else None, embed=embed) @@ -688,8 +702,8 @@ class MsG: await number.delete() embed.title = values[c - 1]['artist'] embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) - embed.set_footer(text='{} / {}'.format(c, len(posts)), - icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)), + icon_url=self._get_score(values[c - 1]['score'])) embed.set_image(url=values[c - 1]['url']) await paginator.edit(content='❤' if values[c - 1]['url'] in hearted else None, embed=embed) @@ -699,8 +713,8 @@ class MsG: c += 1 embed.title = values[c - 1]['artist'] embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) - embed.set_footer(text='{} / {}'.format(c, len(posts)), - icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)), + icon_url=self._get_score(values[c - 1]['score'])) embed.set_image(url=values[c - 1]['url']) await paginator.edit(content='❤' if values[c - 1]['url'] in hearted else None, embed=embed) @@ -783,8 +797,8 @@ class MsG: embed.set_image(url=values[c - 1]['url']) embed.set_author(name=formatter.tostring(tags, random=True), url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url) - embed.set_footer(text='{} / {}'.format(c, len(posts)), - icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)), + icon_url=self._get_score(values[c - 1]['score'])) paginator = await dest.send(embed=embed) @@ -815,8 +829,8 @@ class MsG: c -= 1 embed.title = values[c - 1]['artist'] embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) - embed.set_footer(text='{} / {}'.format(c, len(posts)), - icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)), + icon_url=self._get_score(values[c - 1]['score'])) embed.set_image(url=values[c - 1]['url']) await paginator.edit(content='❤' if values[c - 1]['url'] in hearted else None, embed=embed) @@ -831,8 +845,8 @@ class MsG: await number.delete() embed.title = values[c - 1]['artist'] embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) - embed.set_footer(text='{} / {}'.format(c, len(posts)), - icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)), + icon_url=self._get_score(values[c - 1]['score'])) embed.set_image(url=values[c - 1]['url']) await paginator.edit(content='❤' if values[c - 1]['url'] in hearted else None, embed=embed) @@ -849,8 +863,8 @@ class MsG: c += 1 embed.title = values[c - 1]['artist'] embed.url = 'https://e621.net/post/show/{}'.format(keys[c - 1]) - embed.set_footer(text='{} / {}'.format(c, len(posts)), - icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)), + icon_url=self._get_score(values[c - 1]['score'])) embed.set_image(url=values[c - 1]['url']) await paginator.edit(content='❤' if values[c - 1]['url'] in hearted else None, embed=embed) @@ -930,7 +944,7 @@ class MsG: embed.set_author(name=formatter.tostring(tags, random=True), url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url) embed.set_footer( - text=str(ident), icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + text=post['score'], icon_url=self._get_score(post['score'])) await dest.send(embed=embed) @@ -984,7 +998,7 @@ class MsG: embed.set_author(name=formatter.tostring(tags, random=True), url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url) embed.set_footer( - text=str(ident), icon_url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + text=post['score'], icon_url=self._get_score(post['score'])) await dest.send(embed=embed) From 8eee78a70d7ac5a2b2c84d0ccda7d249b5104202 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 30 Oct 2017 23:35:40 -0400 Subject: [PATCH 5/6] Added ability to switch order:random tag for another order: --- src/main/cogs/booru.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/cogs/booru.py b/src/main/cogs/booru.py index e07ba61..412f9e3 100644 --- a/src/main/cogs/booru.py +++ b/src/main/cogs/booru.py @@ -569,12 +569,14 @@ class MsG: if tag == 'swf' or tag == 'webm' or tag in blacklist: raise exc.TagBlacklisted(tag) + order = [tag for tag in tags if 'order:' in tag] + if order: + order = order[0] + tags.remove(order) + else: + order = 'order:random' + # Checks for blacklisted tags in endpoint blacklists - try/except is for continuing the parent loop - order = False - for tag in tags: - if 'order:' in tag: - order = True - tags = ','.join(['order:random'] + tags) if not order else ','.join(tags) posts = {} temposts = len(posts) empty = 0 @@ -582,7 +584,7 @@ class MsG: while len(posts) < limit: if c == limit * 5 + self.LIMIT: raise exc.Timeout - request = await u.fetch('https://{}.net/post/index.json'.format(booru), params={'tags': tags, 'limit': int(self.LIMIT * limit)}, json=True) + request = await u.fetch('https://{}.net/post/index.json'.format(booru), params={'tags': ','.join([order] + tags), 'limit': int(self.LIMIT * limit)}, json=True) if len(request) == 0: raise exc.NotFound(formatter.tostring(tags)) if len(request) < limit: @@ -613,7 +615,7 @@ class MsG: c += 1 if posts: - return posts + return posts, order else: raise exc.NotFound @@ -788,14 +790,14 @@ class MsG: await ctx.trigger_typing() - posts = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit) + posts, order = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit) keys = list(posts.keys()) values = list(posts.values()) embed = d.Embed( title=values[c - 1]['artist'], url='https://e621.net/post/show/{}'.format(keys[c - 1]), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color) embed.set_image(url=values[c - 1]['url']) - embed.set_author(name=formatter.tostring(tags, random=True), + embed.set_author(name=formatter.tostring(tags, order=order), url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url) embed.set_footer(text='{} {} / {}'.format(values[c - 1]['score'], c, len(posts)), icon_url=self._get_score(values[c - 1]['score'])) @@ -936,12 +938,12 @@ class MsG: await dest.trigger_typing() - posts = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit) + posts, order = await self._get_posts(ctx, booru='e621', tags=tags, limit=limit) for ident, post in posts.items(): embed = d.Embed(title=post['artist'], url='https://e621.net/post/show/{}'.format(ident), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=post['url']) - embed.set_author(name=formatter.tostring(tags, random=True), + embed.set_author(name=formatter.tostring(tags, order=order), url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url) embed.set_footer( text=post['score'], icon_url=self._get_score(post['score'])) @@ -990,12 +992,12 @@ class MsG: await dest.trigger_typing() - posts = await self._get_posts(ctx, booru='e926', tags=tags, limit=limit) + posts, order = await self._get_posts(ctx, booru='e926', tags=tags, limit=limit) for ident, post in posts.items(): embed = d.Embed(title=post['artist'], url='https://e926.net/post/show/{}'.format(ident), color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else self.color).set_image(url=post['url']) - embed.set_author(name=formatter.tostring(tags, random=True), + embed.set_author(name=formatter.tostring(tags, order=order), url='https://e621.net/post?tags={}'.format(','.join(tags)), icon_url=ctx.author.avatar_url) embed.set_footer( text=post['score'], icon_url=self._get_score(post['score'])) From 12490206e5c06ad610d95441b74b6d7ed5973ae1 Mon Sep 17 00:00:00 2001 From: Myned Date: Mon, 30 Oct 2017 23:36:28 -0400 Subject: [PATCH 6/6] Testinggggg --- src/main/run.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/run.py b/src/main/run.py index b958072..d3c685f 100644 --- a/src/main/run.py +++ b/src/main/run.py @@ -114,9 +114,13 @@ def after(voice, error): @bot.command(name=',test', hidden=True) @commands.is_owner() @checks.del_ctx() -async def test(ctx, message): - if '<:N_:368917475531816962>' in message: - await ctx.send('<:N_:368917475531816962>') +async def test(ctx): + embed = d.Embed( + title='title', url='http://lh6.ggpht.com/d3pNZNFCcJM8snBsRSdKUhR9AVBnJMcYYrR92RRDBOzCrxZMhuTeoGOQSmSEn7DAPQ=w300') + embed.add_field(name='name', value='value', inline=False) + await ctx.send(embed=embed) + # if '<:N_:368917475531816962>' in message: + # await ctx.send('<:N_:368917475531816962>') # logs = [] # async for entry in ctx.guild.audit_logs(limit=None, action=d.AuditLogAction.message_delete): # logs.append(