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-30 23:36:59 -04:00
commit 5434ff13c7
4 changed files with 95 additions and 70 deletions

View file

@ -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:
@ -556,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
@ -569,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:
@ -585,7 +600,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
@ -599,7 +615,7 @@ class MsG:
c += 1
if posts:
return posts
return posts, order
else:
raise exc.NotFound
@ -640,8 +656,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 +688,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 +704,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 +715,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)
@ -774,17 +790,17 @@ 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(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 +831,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 +847,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 +865,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)
@ -922,15 +938,15 @@ 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=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)
@ -976,15 +992,15 @@ 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=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)

View file

@ -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['startup_chan'] = ctx.channel.id
u.temp['startup_msg'] = ctx.message.id
u.dump(u.temp, 'temp.pkl')
# loop = self.bot.loop.all_tasks()
# for task in loop:
# task.cancel()
@ -47,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()

View file

@ -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')
@ -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(

View file

@ -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