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:
commit
c780f40866
5 changed files with 100 additions and 25 deletions
|
@ -21,9 +21,10 @@ class MsG:
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.LIMIT = 100
|
self.LIMIT = 100
|
||||||
|
|
||||||
|
self.favorites = u.setdefault('cogs/favorites.pkl', {})
|
||||||
self.blacklists = u.setdefault(
|
self.blacklists = u.setdefault(
|
||||||
'./cogs/blacklists.pkl', {'global_blacklist': set(), 'guild_blacklist': {}, 'user_blacklist': {}})
|
'cogs/blacklists.pkl', {'global_blacklist': set(), 'guild_blacklist': {}, 'user_blacklist': {}})
|
||||||
self.aliases = u.setdefault('./cogs/aliases.pkl', {})
|
self.aliases = u.setdefault('cogs/aliases.pkl', {})
|
||||||
|
|
||||||
# Tag search
|
# Tag search
|
||||||
@commands.command(aliases=['tag', 't'], brief='e621 Tag search', description='e621 | NSFW\nReturn a link search for given tags')
|
@commands.command(aliases=['tag', 't'], brief='e621 Tag search', description='e621 | NSFW\nReturn a link search for given tags')
|
||||||
|
@ -87,8 +88,10 @@ class MsG:
|
||||||
try:
|
try:
|
||||||
if int(msg.content) <= len(pools) and int(msg.content) > 0 and msg.author is user and msg.channel is channel:
|
if int(msg.content) <= len(pools) and int(msg.content) > 0 and msg.author is user and msg.channel is channel:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -234,12 +237,14 @@ 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 ctx.send('🚫 **Exited paginator.**')
|
await ctx.send('🚫 **Exited paginator.**')
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
try:
|
try:
|
||||||
await ctx.send(content='❌ **Paginator timed out.**')
|
await ctx.send(content='❌ **Paginator timed out.**')
|
||||||
|
|
||||||
except UnboundLocalError:
|
except UnboundLocalError:
|
||||||
await ctx.send('❌ **Paginator timed out.**')
|
await ctx.send('❌ **Paginator timed out.**')
|
||||||
|
|
||||||
|
@ -289,6 +294,7 @@ class MsG:
|
||||||
raise exc.NotFound(formatter.tostring(tags))
|
raise exc.NotFound(formatter.tostring(tags))
|
||||||
if len(request) < limit:
|
if len(request) < limit:
|
||||||
limit = len(request)
|
limit = len(request)
|
||||||
|
|
||||||
for post in request:
|
for post in request:
|
||||||
if 'swf' in post['file_ext'] or 'webm' in post['file_ext']:
|
if 'swf' in post['file_ext'] or 'webm' in post['file_ext']:
|
||||||
continue
|
continue
|
||||||
|
@ -303,6 +309,7 @@ class MsG:
|
||||||
if len(posts) == limit:
|
if len(posts) == limit:
|
||||||
break
|
break
|
||||||
c += 1
|
c += 1
|
||||||
|
|
||||||
return posts
|
return posts
|
||||||
|
|
||||||
@commands.command(name='e621p', aliases=['e6p', '6p'])
|
@commands.command(name='e621p', aliases=['e6p', '6p'])
|
||||||
|
@ -550,6 +557,57 @@ class MsG:
|
||||||
except exc.Timeout:
|
except exc.Timeout:
|
||||||
await ctx.send('❌ **Request timed out.**')
|
await ctx.send('❌ **Request timed out.**')
|
||||||
|
|
||||||
|
@commands.group(name='favorites', aliases=['faves', 'f'])
|
||||||
|
@checks.del_ctx()
|
||||||
|
async def favorites(self, ctx):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@favorites.error
|
||||||
|
async def favorites_error(self, ctx, error):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@favorites.command(name='get', aliases=['g'])
|
||||||
|
async def _get_favorites(self, ctx):
|
||||||
|
user = ctx.message.author
|
||||||
|
|
||||||
|
await ctx.send('⭐ {}**\'s favorites:**\n```\n{}```'.format(user.mention, formatter.tostring(self.favorites.get(user.id, set()))))
|
||||||
|
|
||||||
|
@favorites.command(name='add', aliases=['a'])
|
||||||
|
async def _add_favorites(self, ctx, *tags):
|
||||||
|
user = ctx.message.author
|
||||||
|
|
||||||
|
self.favorites.setdefault(user.id, set()).update(tags)
|
||||||
|
u.dump(self.favorites, 'cogs/favorites.pkl')
|
||||||
|
|
||||||
|
await ctx.send('✅ {} **added:**\n```\n{}```'.format(user.mention, formatter.tostring(tags)))
|
||||||
|
|
||||||
|
@favorites.command(name='remove', aliases=['r'])
|
||||||
|
async def _remove_favorites(self, ctx, *tags):
|
||||||
|
user = ctx.message.author
|
||||||
|
|
||||||
|
try:
|
||||||
|
for tag in tags:
|
||||||
|
try:
|
||||||
|
self.favorites[user.id].remove(tag)
|
||||||
|
|
||||||
|
except KeyError:
|
||||||
|
raise exc.TagError(tag)
|
||||||
|
|
||||||
|
u.dump(self.favorites, 'cogs/favorites.pkl')
|
||||||
|
|
||||||
|
await ctx.send('✅ {} **removed:**\n```\n{}```'.format(user.mention, formatter.tostring(tags)), delete_after=5)
|
||||||
|
|
||||||
|
except exc.TagError as e:
|
||||||
|
await ctx.send('❌ `{}` **not in favorites.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
|
@favorites.command(name='clear', aliases=['c'])
|
||||||
|
async def _clear_favorites(self, ctx):
|
||||||
|
user = ctx.message.author
|
||||||
|
|
||||||
|
del self.favorites[user.id]
|
||||||
|
|
||||||
|
await ctx.send('✅ {}**\'s favorites cleared.**'.format(user.mention))
|
||||||
|
|
||||||
# Umbrella command structure to manage global, channel, and user blacklists
|
# Umbrella command structure to manage global, channel, and user blacklists
|
||||||
@commands.group(aliases=['bl', 'b'], brief='Manage blacklists', description='Blacklist base command for managing blacklists\n\n`bl get [blacklist]` to show a blacklist\n`bl set [blacklist] [tags]` to replace a blacklist\n`bl clear [blacklist]` to clear a blacklist\n`bl add [blacklist] [tags]` to add tags to a blacklist\n`bl remove [blacklist] [tags]` to remove tags from a blacklist', usage='[flag] [blacklist] ([tags])')
|
@commands.group(aliases=['bl', 'b'], brief='Manage blacklists', description='Blacklist base command for managing blacklists\n\n`bl get [blacklist]` to show a blacklist\n`bl set [blacklist] [tags]` to replace a blacklist\n`bl clear [blacklist]` to clear a blacklist\n`bl add [blacklist] [tags]` to add tags to a blacklist\n`bl remove [blacklist] [tags]` to remove tags from a blacklist', usage='[flag] [blacklist] ([tags])')
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
|
@ -627,8 +685,8 @@ class MsG:
|
||||||
if alias_request:
|
if alias_request:
|
||||||
for dic in alias_request:
|
for dic in alias_request:
|
||||||
self.aliases.setdefault(tag, set()).add(dic['name'])
|
self.aliases.setdefault(tag, set()).add(dic['name'])
|
||||||
u.dump(self.blacklists, './cogs/blacklists.pkl')
|
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
||||||
u.dump(self.aliases, './cogs/aliases.pkl')
|
u.dump(self.aliases, 'cogs/aliases.pkl')
|
||||||
|
|
||||||
await ctx.send('✅ **Added to global blacklist:**\n```\n{}```'.format(formatter.tostring(tags)), delete_after=5)
|
await ctx.send('✅ **Added to global blacklist:**\n```\n{}```'.format(formatter.tostring(tags)), delete_after=5)
|
||||||
|
|
||||||
|
@ -646,8 +704,8 @@ class MsG:
|
||||||
if alias_request:
|
if alias_request:
|
||||||
for dic in alias_request:
|
for dic in alias_request:
|
||||||
self.aliases.setdefault(tag, set()).add(dic['name'])
|
self.aliases.setdefault(tag, set()).add(dic['name'])
|
||||||
u.dump(self.blacklists, './cogs/blacklists.pkl')
|
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
||||||
u.dump(self.aliases, './cogs/aliases.pkl')
|
u.dump(self.aliases, 'cogs/aliases.pkl')
|
||||||
|
|
||||||
await ctx.send('✅ **Added to** {} **blacklist:**\n```\n{}```'.format(channel.mention, formatter.tostring(tags)), delete_after=5)
|
await ctx.send('✅ **Added to** {} **blacklist:**\n```\n{}```'.format(channel.mention, formatter.tostring(tags)), delete_after=5)
|
||||||
|
|
||||||
|
@ -661,8 +719,8 @@ class MsG:
|
||||||
if alias_request:
|
if alias_request:
|
||||||
for dic in alias_request:
|
for dic in alias_request:
|
||||||
self.aliases.setdefault(tag, set()).add(dic['name'])
|
self.aliases.setdefault(tag, set()).add(dic['name'])
|
||||||
u.dump(self.blacklists, './cogs/blacklists.pkl')
|
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
||||||
u.dump(self.aliases, './cogs/aliases.pkl')
|
u.dump(self.aliases, 'cogs/aliases.pkl')
|
||||||
|
|
||||||
await ctx.send('✅ {} **added:**\n```\n{}```'.format(user.mention, formatter.tostring(tags)), delete_after=5)
|
await ctx.send('✅ {} **added:**\n```\n{}```'.format(user.mention, formatter.tostring(tags)), delete_after=5)
|
||||||
|
|
||||||
|
@ -681,9 +739,10 @@ class MsG:
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise exc.TagError(tag)
|
raise exc.TagError(tag)
|
||||||
u.dump(self.blacklists, './cogs/blacklists.pkl')
|
|
||||||
|
|
||||||
await ctx.send('✅ **Removed from global blacklist:**\n```\n' + formatter.tostring(tags) + '```', delete_after=5)
|
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
||||||
|
|
||||||
|
await ctx.send('✅ **Removed from global blacklist:**\n```\n{}```'.format(formatter.tostring(tags)), delete_after=5)
|
||||||
|
|
||||||
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)
|
||||||
|
@ -702,9 +761,10 @@ class MsG:
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise exc.TagError(tag)
|
raise exc.TagError(tag)
|
||||||
u.dump(self.blacklists, './cogs/blacklists.pkl')
|
|
||||||
|
|
||||||
await ctx.send('✅ **Removed from** ' + channel.mention + ' **blacklist:**\n```\n' + formatter.tostring(tags) + '```', delete_after=5)
|
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
||||||
|
|
||||||
|
await ctx.send('✅ **Removed from** {} **blacklist:**\n```\n{}```'.format(channel.mention, formatter.tostring(tags), delete_after=5))
|
||||||
|
|
||||||
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)
|
||||||
|
@ -720,7 +780,8 @@ class MsG:
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise exc.TagError(tag)
|
raise exc.TagError(tag)
|
||||||
u.dump(self.blacklists, './cogs/blacklists.pkl')
|
|
||||||
|
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
||||||
|
|
||||||
await ctx.send('✅ {} **removed:**\n```\n{}```'.format(user.mention, formatter.tostring(tags)), delete_after=5)
|
await ctx.send('✅ {} **removed:**\n```\n{}```'.format(user.mention, formatter.tostring(tags)), delete_after=5)
|
||||||
|
|
||||||
|
@ -736,7 +797,7 @@ class MsG:
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def __clear_global_blacklist(self, ctx):
|
async def __clear_global_blacklist(self, ctx):
|
||||||
del self.blacklists['global_blacklist']
|
del self.blacklists['global_blacklist']
|
||||||
u.dump(self.blacklists, './cogs/blacklists.pkl')
|
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
||||||
|
|
||||||
await ctx.send('✅ **Global blacklist cleared.**', delete_after=5)
|
await ctx.send('✅ **Global blacklist cleared.**', delete_after=5)
|
||||||
|
|
||||||
|
@ -748,7 +809,7 @@ class MsG:
|
||||||
channel = ctx.message.channel
|
channel = ctx.message.channel
|
||||||
|
|
||||||
del self.blacklists['guild_blacklist'][str(guild.id)][channel.id]
|
del self.blacklists['guild_blacklist'][str(guild.id)][channel.id]
|
||||||
u.dump(self.blacklists, './cogs/blacklists.pkl')
|
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
||||||
|
|
||||||
await ctx.send('✅ {} **blacklist cleared.**'.format(channel.mention), delete_after=5)
|
await ctx.send('✅ {} **blacklist cleared.**'.format(channel.mention), delete_after=5)
|
||||||
|
|
||||||
|
@ -757,6 +818,6 @@ class MsG:
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
|
|
||||||
del self.blacklists['user_blacklist'][user.id]
|
del self.blacklists['user_blacklist'][user.id]
|
||||||
u.dump(self.blacklists, './cogs/blacklists.pkl')
|
u.dump(self.blacklists, 'cogs/blacklists.pkl')
|
||||||
|
|
||||||
await ctx.send('✅ {}**\'s blacklist cleared.**'.format(user.mention), delete_after=5)
|
await ctx.send('✅ {}**\'s blacklist cleared.**'.format(user.mention), delete_after=5)
|
||||||
|
|
|
@ -2,6 +2,7 @@ import asyncio
|
||||||
import traceback as tb
|
import traceback as tb
|
||||||
|
|
||||||
import discord as d
|
import discord as d
|
||||||
|
from discord import errors as err
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
|
||||||
from misc import exceptions as exc
|
from misc import exceptions as exc
|
||||||
|
@ -80,7 +81,7 @@ class Administration:
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
try:
|
try:
|
||||||
ref = await channel.get_message(reference)
|
ref = await channel.get_message(reference)
|
||||||
except d.errors.NotFound:
|
except err.NotFound:
|
||||||
continue
|
continue
|
||||||
history = []
|
history = []
|
||||||
try:
|
try:
|
||||||
|
@ -135,7 +136,7 @@ class Administration:
|
||||||
try:
|
try:
|
||||||
if not message.pinned:
|
if not message.pinned:
|
||||||
await message.delete()
|
await message.delete()
|
||||||
except d.errors.NotFound:
|
except err.NotFound:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def on_message(self, channel):
|
async def on_message(self, channel):
|
||||||
|
@ -153,7 +154,7 @@ class Administration:
|
||||||
await self.queue.put(message)
|
await self.queue.put(message)
|
||||||
except exc.Abort:
|
except exc.Abort:
|
||||||
u.tasks['management']['auto_delete'].remove(channel.id)
|
u.tasks['management']['auto_delete'].remove(channel.id)
|
||||||
u.dump(u.tasks, './cogs/tasks.pkl')
|
u.dump(u.tasks, 'cogs/tasks.pkl')
|
||||||
print('Stopped looping {}'.format(channel.id))
|
print('Stopped looping {}'.format(channel.id))
|
||||||
await channel.send('✅ **Stopped deleting messages in** {}**.**'.format(channel.mention), delete_after=5)
|
await channel.send('✅ **Stopped deleting messages in** {}**.**'.format(channel.mention), delete_after=5)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -168,7 +169,7 @@ class Administration:
|
||||||
try:
|
try:
|
||||||
if channel.id not in u.tasks.setdefault('management', {}).setdefault('auto_delete', []):
|
if channel.id not in u.tasks.setdefault('management', {}).setdefault('auto_delete', []):
|
||||||
u.tasks['management']['auto_delete'].append(channel.id)
|
u.tasks['management']['auto_delete'].append(channel.id)
|
||||||
u.dump(u.tasks, './cogs/tasks.pkl')
|
u.dump(u.tasks, 'cogs/tasks.pkl')
|
||||||
self.bot.loop.create_task(self.on_message(channel))
|
self.bot.loop.create_task(self.on_message(channel))
|
||||||
self.bot.loop.create_task(self.delete())
|
self.bot.loop.create_task(self.delete())
|
||||||
print('Looping #{}'.format(channel.name))
|
print('Looping #{}'.format(channel.name))
|
||||||
|
|
|
@ -32,11 +32,12 @@ class Bot:
|
||||||
# loop = self.bot.loop.all_tasks()
|
# loop = self.bot.loop.all_tasks()
|
||||||
# for task in loop:
|
# for task in loop:
|
||||||
# task.cancel()
|
# task.cancel()
|
||||||
|
if u.session:
|
||||||
await u.session.close()
|
await u.session.close()
|
||||||
await self.bot.logout()
|
await self.bot.logout()
|
||||||
await self.bot.close()
|
await self.bot.close()
|
||||||
print('- - - - - - -')
|
print('- - - - - - -')
|
||||||
print('CLOSED')
|
print('DISCONNECTED')
|
||||||
|
|
||||||
@commands.command(name=',restart', aliases=[',res', ',r'], hidden=True)
|
@commands.command(name=',restart', aliases=[',res', ',r'], hidden=True)
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
|
@ -49,6 +50,7 @@ class Bot:
|
||||||
# loop = self.bot.loop.all_tasks()
|
# loop = self.bot.loop.all_tasks()
|
||||||
# for task in loop:
|
# for task in loop:
|
||||||
# task.cancel()
|
# task.cancel()
|
||||||
|
if u.session:
|
||||||
await u.session.close()
|
await u.session.close()
|
||||||
await self.bot.logout()
|
await self.bot.logout()
|
||||||
await self.bot.close()
|
await self.bot.close()
|
||||||
|
|
|
@ -43,10 +43,21 @@ async def on_ready():
|
||||||
print('- - - - - - -')
|
print('- - - - - - -')
|
||||||
|
|
||||||
|
|
||||||
|
@bot.event
|
||||||
|
async def on_error(error):
|
||||||
|
if u.session:
|
||||||
|
await u.session.close()
|
||||||
|
await bot.logout()
|
||||||
|
await bot.close()
|
||||||
|
print('- - - - - - -')
|
||||||
|
print('ERROR')
|
||||||
|
tb.print_exc()
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_command_error(ctx, error):
|
async def on_command_error(ctx, error):
|
||||||
if not isinstance(error, commands.errors.CommandNotFound):
|
if not isinstance(error, commands.errors.CommandNotFound):
|
||||||
print(error)
|
tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
|
||||||
await ctx.send('{}\n```\n{}```'.format(exc.base, error))
|
await ctx.send('{}\n```\n{}```'.format(exc.base, error))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ def dump(obj, filename):
|
||||||
pkl.dump(obj, outfile)
|
pkl.dump(obj, outfile)
|
||||||
|
|
||||||
|
|
||||||
tasks = setdefault('./cogs/tasks.pkl', {})
|
tasks = setdefault('cogs/tasks.pkl', {})
|
||||||
|
|
||||||
|
|
||||||
async def clear(obj, interval=10 * 60, replace=None):
|
async def clear(obj, interval=10 * 60, replace=None):
|
||||||
|
|
Loading…
Reference in a new issue