1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-25 06:37:29 +00:00

Merge branch 'dev'

This commit is contained in:
Myned 2017-11-20 08:48:53 -05:00
commit 754dd3f9de
4 changed files with 67 additions and 37 deletions

View file

@ -662,7 +662,7 @@ class MsG:
try: try:
kwargs = u.get_kwargs(ctx, args) kwargs = u.get_kwargs(ctx, args)
dest, query = kwargs['destination'], kwargs['remaining'] dest, query = kwargs['destination'], kwargs['remaining']
hearted = [] hearted = {}
c = 1 c = 1
await dest.trigger_typing() await dest.trigger_typing()
@ -711,7 +711,7 @@ class MsG:
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_score(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['url']) embed.set_image(url=values[c - 1]['url'])
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 keys[c - 1] in hearted.keys() else None, embed=embed)
else: else:
await paginator.edit(content='**First image**') await paginator.edit(content='**First image**')
@ -728,7 +728,7 @@ class MsG:
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_score(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['url']) embed.set_image(url=values[c - 1]['url'])
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 keys[c - 1] in hearted.keys() else None, embed=embed)
except exc.Right: except exc.Right:
if c < len(keys): if c < len(keys):
@ -740,7 +740,7 @@ class MsG:
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_score(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['url']) embed.set_image(url=values[c - 1]['url'])
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 keys[c - 1] in hearted.keys() else None, embed=embed)
else: else:
await paginator.edit(content='**Last image**') await paginator.edit(content='**Last image**')
@ -767,10 +767,14 @@ class MsG:
if hearted: if hearted:
await ctx.message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') await ctx.message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
for embed in hearted: n = 1
for embed in hearted.values():
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
await ctx.author.send('`{} / {}`'.format(hearted.index(embed) + 1, len(hearted)), embed=embed) embed.footer.text = f'{n} / {len(hearted)}'
await ctx.author.send(embed=embed)
n += 1
@cmds.command(name='e621page', aliases=['e621p', 'e6p', '6p']) @cmds.command(name='e621page', aliases=['e621p', 'e6p', '6p'])
@checks.is_nsfw() @checks.is_nsfw()
@ -795,7 +799,7 @@ class MsG:
kwargs = u.get_kwargs(ctx, args) kwargs = u.get_kwargs(ctx, args)
dest, tags = kwargs['destination'], kwargs['remaining'] dest, tags = kwargs['destination'], kwargs['remaining']
limit = self.LIMIT / 5 limit = self.LIMIT / 5
hearted = [] hearted = {}
c = 1 c = 1
tags = self._get_favorites(ctx, tags) tags = self._get_favorites(ctx, tags)
@ -827,12 +831,12 @@ class MsG:
self.bot.wait_for('reaction_remove', check=on_reaction, timeout=7 * 60)]) self.bot.wait_for('reaction_remove', check=on_reaction, timeout=7 * 60)])
except exc.Save: except exc.Save:
if embed not in hearted: if keys[c - 1] not in hearted:
hearted.append(embed) hearted[keys[c - 1]] = embed
await paginator.edit(content='\N{HEAVY BLACK HEART}') await paginator.edit(content='\N{HEAVY BLACK HEART}')
else: else:
hearted.remove(embed) del hearted[keys[c - 1]]
await paginator.edit(content='\N{BROKEN HEART}') await paginator.edit(content='\N{BROKEN HEART}')
@ -846,7 +850,7 @@ class MsG:
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_score(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['url']) embed.set_image(url=values[c - 1]['url'])
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 keys[c - 1] in hearted.keys() else None, embed=embed)
else: else:
await paginator.edit(content='**First image**') await paginator.edit(content='**First image**')
@ -863,7 +867,7 @@ class MsG:
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_score(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['url']) embed.set_image(url=values[c - 1]['url'])
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 keys[c - 1] in hearted.keys() else None, embed=embed)
except exc.Right: except exc.Right:
try: try:
@ -884,7 +888,7 @@ class MsG:
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_score(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['url']) embed.set_image(url=values[c - 1]['url'])
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 keys[c - 1] in hearted.keys() else None, embed=embed)
else: else:
await paginator.edit(content='**No more images found**') await paginator.edit(content='**No more images found**')
@ -921,10 +925,14 @@ class MsG:
if hearted: if hearted:
await ctx.message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') await ctx.message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
for embed in hearted: n = 1
for embed in hearted.values():
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
await ctx.author.send('`{} / {}`'.format(hearted.index(embed) + 1, len(hearted)), embed=embed) embed.footer.text = f'{n} / {len(hearted)}'
await ctx.author.send(embed=embed)
n += 1
# @e621_paginator.error # @e621_paginator.error
# async def e621_paginator_error(self, ctx, error): # async def e621_paginator_error(self, ctx, error):
@ -954,7 +962,7 @@ class MsG:
kwargs = u.get_kwargs(ctx, args) kwargs = u.get_kwargs(ctx, args)
dest, tags = kwargs['destination'], kwargs['remaining'] dest, tags = kwargs['destination'], kwargs['remaining']
limit = self.LIMIT / 5 limit = self.LIMIT / 5
hearted = [] hearted = {}
c = 1 c = 1
tags = self._get_favorites(ctx, tags) tags = self._get_favorites(ctx, tags)
@ -1005,7 +1013,7 @@ class MsG:
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_score(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['url']) embed.set_image(url=values[c - 1]['url'])
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 keys[c - 1] in hearted.keys() else None, embed=embed)
else: else:
await paginator.edit(content='**First image**') await paginator.edit(content='**First image**')
@ -1022,7 +1030,7 @@ class MsG:
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_score(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['url']) embed.set_image(url=values[c - 1]['url'])
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 keys[c - 1] in hearted.keys() else None, embed=embed)
except exc.Right: except exc.Right:
try: try:
@ -1043,7 +1051,7 @@ class MsG:
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_score(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['url']) embed.set_image(url=values[c - 1]['url'])
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 keys[c - 1] in hearted.keys() else None, embed=embed)
else: else:
await paginator.edit(content='**No more images found**') await paginator.edit(content='**No more images found**')
@ -1080,10 +1088,14 @@ class MsG:
if hearted: if hearted:
await ctx.message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}') await ctx.message.add_reaction('\N{HOURGLASS WITH FLOWING SAND}')
for embed in hearted: n = 1
for embed in hearted.values():
await asyncio.sleep(self.RATE_LIMIT) await asyncio.sleep(self.RATE_LIMIT)
await ctx.author.send('`{} / {}`'.format(hearted.index(embed) + 1, len(hearted)), embed=embed) embed.footer.text = f'{n} / {len(hearted)}'
await ctx.author.send(embed=embed)
n += 1
# 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
@cmds.group(aliases=['e6', '6'], brief='e621 | NSFW', description='e621 | NSFW\nTag-based search for e621.net\n\nYou can only search 5 tags and 6 images at once for now.\ne6 [tags...] ([# of images])') @cmds.group(aliases=['e6', '6'], brief='e621 | NSFW', description='e621 | NSFW\nTag-based search for e621.net\n\nYou can only search 5 tags and 6 images at once for now.\ne6 [tags...] ([# of images])')

View file

@ -29,9 +29,9 @@ class Bot:
await self.bot.get_channel(u.config['info_channel']).send('**Shutting down** \N{CRESCENT MOON} . . .') await self.bot.get_channel(u.config['info_channel']).send('**Shutting down** \N{CRESCENT MOON} . . .')
u.temp['startup_chan'] = ctx.channel.id chantype = 'guild' if isinstance(ctx.channel, d.TextChannel) else 'private'
u.temp['startup_msg'] = ctx.message.id u.temp['startup'] = (chantype, ctx.channel.id if chantype == 'guild' else ctx.author.id, ctx.message.id)
u.dump(u.temp, 'temp.pkl') u.dump(u.temp, 'temp/temp.pkl')
# loop = self.bot.loop.all_tasks() # loop = self.bot.loop.all_tasks()
# for task in loop: # for task in loop:
@ -50,9 +50,9 @@ class Bot:
await self.bot.get_channel(u.config['info_channel']).send('**Restarting** \N{SLEEPING SYMBOL} . . .') await self.bot.get_channel(u.config['info_channel']).send('**Restarting** \N{SLEEPING SYMBOL} . . .')
# u.notify('R E S T A R T I N G') # u.notify('R E S T A R T I N G')
u.temp['startup_chan'] = ctx.channel.id chantype = 'guild' if isinstance(ctx.channel, d.TextChannel) else 'private'
u.temp['startup_msg'] = ctx.message.id u.temp['startup'] = (chantype, ctx.channel.id if chantype == 'guild' else ctx.author.id, ctx.message.id)
u.dump(u.temp, 'temp.pkl') u.dump(u.temp, 'temp/temp.pkl')
# loop = self.bot.loop.all_tasks() # loop = self.bot.loop.all_tasks()
# for task in loop: # for task in loop:

View file

@ -54,7 +54,9 @@ log.basicConfig(level=log.WARNING)
def get_prefix(bot, message): def get_prefix(bot, message):
return u.settings['prefixes'].get(message.guild.id, u.config['prefix']) with suppress(AttributeError):
return u.settings['prefixes'].get(message.guild.id, u.config['prefix'])
return u.config['prefix']
bot = cmds.Bot(command_prefix=get_prefix, formatter=cmds.HelpFormatter(show_check_failure=True), description='Modumind - A booru bot with a side of management\n\nS for single command\nG for group command', help_attrs={'aliases': ['h']}, pm_help=None) bot = cmds.Bot(command_prefix=get_prefix, formatter=cmds.HelpFormatter(show_check_failure=True), description='Modumind - A booru bot with a side of management\n\nS for single command\nG for group command', help_attrs={'aliases': ['h']}, pm_help=None)
@ -84,10 +86,17 @@ async def on_ready():
await bot.get_channel(u.config['info_channel']).send('**Started** \N{BLACK SUN WITH RAYS} .') await bot.get_channel(u.config['info_channel']).send('**Started** \N{BLACK SUN WITH RAYS} .')
# u.notify('C O N N E C T E D') # u.notify('C O N N E C T E D')
if u.temp: if u.temp:
channel = bot.get_channel(u.temp['startup_chan']) with suppress(err.NotFound):
message = await channel.get_message(u.temp['startup_msg']) if u.temp['startup'][0] == 'guild':
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') dest = bot.get_channel(u.temp['startup'][1])
u.temp.clear() else:
dest = bot.get_user(u.temp['startup'][1])
message = await dest.get_message(u.temp['startup'][2])
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
u.temp['startup'] = ()
u.dump(u.temp, 'temp/temp.pkl')
@bot.event @bot.event
@ -102,11 +111,20 @@ async def on_error(error, *args, **kwargs):
tb.print_exc() tb.print_exc()
await bot.get_user(u.config['owner_id']).send('**ERROR** \N{WARNING SIGN}\n```\n{}```'.format(error)) await bot.get_user(u.config['owner_id']).send('**ERROR** \N{WARNING SIGN}\n```\n{}```'.format(error))
await bot.get_channel(u.config['info_channel']).send('**ERROR** \N{WARNING SIGN}\n```\n{}```'.format(error)) await bot.get_channel(u.config['info_channel']).send('**ERROR** \N{WARNING SIGN}\n```\n{}```'.format(error))
if u.temp: if u.temp:
channel = bot.get_channel(u.temp['startup_chan']) with suppress(err.NotFound):
message = await channel.get_message(u.temp['startup_msg']) print(u.temp['startup'])
await message.add_reaction('\N{WARNING SIGN}') if u.temp['startup'][0] == 'guild':
dest = bot.get_channel(u.temp['startup'][1])
else:
dest = bot.get_user(u.temp['startup'][1])
message = await dest.get_message(u.temp['startup'][2])
await message.add_reaction('\N{WARNING SIGN}')
u.temp.clear() u.temp.clear()
u.dump(u.temp, 'temp/temp.pkl')
# u.notify('E R R O R') # u.notify('E R R O R')
await bot.logout() await bot.logout()
u.close(bot.loop) u.close(bot.loop)

View file

@ -66,9 +66,9 @@ def dump(obj, filename, *, json=False):
jsn.dump(obj, outfile, indent=4, sort_keys=True) jsn.dump(obj, outfile, indent=4, sort_keys=True)
settings = setdefault('settings.pkl', {'del_ctx': [], 'prefixes': {}}) settings = setdefault('misc/settings.pkl', {'del_ctx': [], 'prefixes': {}})
tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_rev': []}) tasks = setdefault('cogs/tasks.pkl', {'auto_del': [], 'auto_rev': []})
temp = setdefault('temp.pkl', {}) temp = setdefault('temp/temp.pkl', {})
RATE_LIMIT = 2.2 RATE_LIMIT = 2.2
color = d.Color(0x1A1A1A) color = d.Color(0x1A1A1A)