mirror of
https://github.com/myned/modufur.git
synced 2024-11-01 21:02:38 +00:00
Merge branch 'dev'
This commit is contained in:
commit
ef75b4664b
6 changed files with 218 additions and 118 deletions
|
@ -14,8 +14,6 @@ from misc import checks
|
||||||
from utils import utils as u
|
from utils import utils as u
|
||||||
from utils import formatter, scraper
|
from utils import formatter, scraper
|
||||||
|
|
||||||
# temp_urls = {}
|
|
||||||
|
|
||||||
|
|
||||||
class MsG:
|
class MsG:
|
||||||
|
|
||||||
|
@ -30,19 +28,38 @@ class MsG:
|
||||||
# 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')
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def tags(self, ctx, *tags):
|
async def tags(self, ctx, tag):
|
||||||
await ctx.send('✅ `{}`\nhttps://e621.net/post?tags={}'.format(formatter.tostring(tags), ','.join(tags)))
|
tags = []
|
||||||
|
|
||||||
|
await ctx.trigger_typing()
|
||||||
|
tag_request = await u.fetch('https://e621.net/tag/related.json', params={'tags': tag, 'type': 'general'}, json=True)
|
||||||
|
for tag in tag_request.get('wolf', []):
|
||||||
|
tags.append(tag[0])
|
||||||
|
|
||||||
|
await ctx.send('✅ ``{}` **tags:**\n```\n{}```'.format(tag, formatter.tostring(tags)))
|
||||||
|
|
||||||
|
@tags.error
|
||||||
|
async def tags_error(self, ctx, error):
|
||||||
|
if isinstance(error, errext.MissingRequiredArgument):
|
||||||
|
return await ctx.send('❌ **No tags given.**', delete_after=10)
|
||||||
|
|
||||||
# Tag aliases
|
# Tag aliases
|
||||||
@commands.command(aliases=['alias', 'a'], brief='e621 Tag aliases', description='e621 | NSFW\nSearch aliases for given tag')
|
@commands.command(name='aliases', aliases=['alias', 'a'], brief='e621 Tag aliases', description='e621 | NSFW\nSearch aliases for given tag')
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def aliases(self, ctx, tag):
|
async def tag_aliases(self, ctx, tag):
|
||||||
aliases = []
|
aliases = []
|
||||||
|
|
||||||
|
await ctx.trigger_typing()
|
||||||
alias_request = await u.fetch('https://e621.net/tag_alias/index.json', params={'aliased_to': tag, 'approved': 'true'}, json=True)
|
alias_request = await u.fetch('https://e621.net/tag_alias/index.json', params={'aliased_to': tag, 'approved': 'true'}, json=True)
|
||||||
for dic in alias_request:
|
for dic in alias_request:
|
||||||
aliases.append(dic['name'])
|
aliases.append(dic['name'])
|
||||||
await ctx.send('✅ `' + tag + '` **aliases:**\n```' + formatter.tostring(aliases) + '```')
|
|
||||||
|
await ctx.send('✅ `{}` **aliases:**\n```\n{}```'.format(tag, formatter.tostring(aliases)))
|
||||||
|
|
||||||
|
@tag_aliases.error
|
||||||
|
async def tag_aliases_error(self, ctx, error):
|
||||||
|
if isinstance(error, errext.MissingRequiredArgument):
|
||||||
|
return await ctx.send('❌ **No tags given.**', delete_after=10)
|
||||||
|
|
||||||
# Reverse image searches a linked image using the public iqdb
|
# Reverse image searches a linked image using the public iqdb
|
||||||
@commands.command(name='reverse', aliases=['rev', 'ris'], brief='e621 Reverse image search', description='e621 | NSFW\nReverse-search an image with given URL')
|
@commands.command(name='reverse', aliases=['rev', 'ris'], brief='e621 Reverse image search', description='e621 | NSFW\nReverse-search an image with given URL')
|
||||||
|
@ -50,16 +67,25 @@ class MsG:
|
||||||
async def reverse_image_search(self, ctx, url):
|
async def reverse_image_search(self, ctx, url):
|
||||||
try:
|
try:
|
||||||
await ctx.trigger_typing()
|
await ctx.trigger_typing()
|
||||||
await ctx.send('✅ ' + ctx.message.author.mention + ' **Probable match:**\n' + await scraper.check_match(url))
|
await ctx.send('✅ **Probable match:**\n{}'.format(await scraper.check_match(url)))
|
||||||
|
|
||||||
except exc.MatchError:
|
except exc.MatchError:
|
||||||
await ctx.send('❌ ' + ctx.message.author.mention + ' **No probable match.**', delete_after=10)
|
await ctx.send('❌ **No probable match.**', delete_after=10)
|
||||||
|
|
||||||
|
@reverse_image_search.error
|
||||||
|
async def reverse_image_search_error(self, ctx, error):
|
||||||
|
if isinstance(error, errext.MissingRequiredArgument):
|
||||||
|
return await ctx.send('❌ **Invalid url.**', delete_after=10)
|
||||||
|
|
||||||
async def return_pool(self, *, ctx, booru='e621', query=[]):
|
async def return_pool(self, *, ctx, booru='e621', query=[]):
|
||||||
|
channel = ctx.message.channel
|
||||||
|
user = ctx.message.author
|
||||||
|
|
||||||
def on_message(msg):
|
def on_message(msg):
|
||||||
if msg.content.lower() == 'cancel' and msg.author is ctx.message.author and msg.channel is ctx.message.channel:
|
if msg.content.lower() == 'cancel' and msg.author is user and msg.channel is channel:
|
||||||
raise exc.Abort
|
raise exc.Abort
|
||||||
try:
|
try:
|
||||||
if int(msg.content) <= len(pools) and int(msg.content) > 0 and msg.author is ctx.message.author and msg.channel is ctx.message.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
|
||||||
|
@ -104,36 +130,39 @@ class MsG:
|
||||||
@commands.command(name='pool', aliases=['e6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format', hidden=True)
|
@commands.command(name='pool', aliases=['e6pp'], brief='e621 pool paginator', description='e621 | NSFW\nShow pools in a page format', hidden=True)
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def pool_paginator(self, ctx, *kwords):
|
async def pool_paginator(self, ctx, *kwords):
|
||||||
|
channel = ctx.message.channel
|
||||||
|
user = ctx.message.author
|
||||||
|
|
||||||
def on_react(reaction, user):
|
def on_react(reaction, user):
|
||||||
if reaction.emoji == '🚫' and reaction.message.content == paginator.content and user is ctx.message.author:
|
if reaction.emoji == '🚫' and reaction.message.content == paginator.content and (user is user or user.id == u.config['owner_id']):
|
||||||
raise exc.Abort
|
raise exc.Abort
|
||||||
elif reaction.emoji == '📁' and reaction.message.content == paginator.content and user is ctx.message.author:
|
elif reaction.emoji == '📁' and reaction.message.content == paginator.content and (user is user or user.id == u.config['owner_id']):
|
||||||
raise exc.Save
|
raise exc.Save
|
||||||
elif reaction.emoji == '⬅' and reaction.message.content == paginator.content and user is ctx.message.author:
|
elif reaction.emoji == '⬅' and reaction.message.content == paginator.content and (user is user or user.id == u.config['owner_id']):
|
||||||
raise exc.Left
|
raise exc.Left
|
||||||
elif reaction.emoji == '🔢' and reaction.message.content == paginator.content and user is ctx.message.author:
|
elif reaction.emoji == '🔢' and reaction.message.content == paginator.content and (user is user or user.id == u.config['owner_id']):
|
||||||
raise exc.GoTo
|
raise exc.GoTo
|
||||||
elif reaction.emoji == '➡' and reaction.message.content == paginator.content and user is ctx.message.author:
|
elif reaction.emoji == '➡' and reaction.message.content == paginator.content and (user is user or user.id == u.config['owner_id']):
|
||||||
raise exc.Right
|
raise exc.Right
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def on_message(msg):
|
def on_message(msg):
|
||||||
try:
|
try:
|
||||||
if int(msg.content) <= len(posts) and msg.author is ctx.message.author and msg.channel is ctx.message.channel:
|
if int(msg.content) <= len(posts) 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
|
||||||
|
|
||||||
user = ctx.message.author
|
|
||||||
starred = []
|
starred = []
|
||||||
c = 1
|
c = 1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await ctx.trigger_typing()
|
await ctx.trigger_typing()
|
||||||
|
|
||||||
pool, posts = await self.return_pool(ctx=ctx, booru='e621', query=kwords)
|
pool, posts = await self.return_pool(ctx=ctx, booru='e621', query=kwords)
|
||||||
keys = list(posts.keys())
|
keys = list(posts.keys())
|
||||||
values = list(posts.values())
|
values = list(posts.values())
|
||||||
|
@ -207,15 +236,19 @@ class MsG:
|
||||||
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.**')
|
||||||
|
|
||||||
except exc.NotFound:
|
except exc.NotFound:
|
||||||
await ctx.send('❌ **Pool not found.**', delete_after=10)
|
await ctx.send('❌ **Pool not found.**', delete_after=10)
|
||||||
|
|
||||||
except exc.Timeout:
|
except exc.Timeout:
|
||||||
await ctx.send('❌ **Request timed out.**')
|
await ctx.send('❌ **Request timed out.**')
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
for url in starred:
|
for url in starred:
|
||||||
await user.send(url)
|
await user.send(url)
|
||||||
|
@ -276,30 +309,34 @@ class MsG:
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
@checks.is_nsfw()
|
@checks.is_nsfw()
|
||||||
async def e621_paginator(self, ctx, *args):
|
async def e621_paginator(self, ctx, *args):
|
||||||
|
channel = ctx.message.channel
|
||||||
|
user = ctx.message.author
|
||||||
|
|
||||||
def on_react(reaction, user):
|
def on_react(reaction, user):
|
||||||
if reaction.emoji == '🚫' and reaction.message.content == paginator.content and user is ctx.message.author:
|
if reaction.emoji == '🚫' and reaction.message.content == paginator.content and (user is user or user.id == u.config['owner_id']):
|
||||||
raise exc.Abort
|
raise exc.Abort
|
||||||
elif reaction.emoji == '📁' and reaction.message.content == paginator.content and user is ctx.message.author:
|
elif reaction.emoji == '📁' and reaction.message.content == paginator.content and (user is user or user.id == u.config['owner_id']):
|
||||||
raise exc.Save
|
raise exc.Save
|
||||||
elif reaction.emoji == '⬅' and reaction.message.content == paginator.content and user is ctx.message.author:
|
elif reaction.emoji == '⬅' and reaction.message.content == paginator.content and (user is user or user.id == u.config['owner_id']):
|
||||||
raise exc.Left
|
raise exc.Left
|
||||||
elif reaction.emoji == '🔢' and reaction.message.content == paginator.content and user is ctx.message.author:
|
elif reaction.emoji == '🔢' and reaction.message.content == paginator.content and (user is user or user.id == u.config['owner_id']):
|
||||||
raise exc.GoTo
|
raise exc.GoTo
|
||||||
elif reaction.emoji == '➡' and reaction.message.content == paginator.content and user is ctx.message.author:
|
elif reaction.emoji == '➡' and reaction.message.content == paginator.content and (user is user or user.id == u.config['owner_id']):
|
||||||
raise exc.Right
|
raise exc.Right
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def on_message(msg):
|
def on_message(msg):
|
||||||
try:
|
try:
|
||||||
if int(msg.content) <= len(posts) and msg.author is ctx.message.author and msg.channel is ctx.message.channel:
|
if int(msg.content) <= len(posts) 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
|
||||||
|
|
||||||
user = ctx.message.author
|
|
||||||
args = list(args)
|
args = list(args)
|
||||||
limit = self.LIMIT / 5
|
limit = self.LIMIT / 5
|
||||||
starred = []
|
starred = []
|
||||||
|
@ -307,7 +344,6 @@ class MsG:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await ctx.trigger_typing()
|
await ctx.trigger_typing()
|
||||||
|
|
||||||
posts = await self.check_return_posts(ctx=ctx, booru='e621', tags=args, limit=limit)
|
posts = await self.check_return_posts(ctx=ctx, booru='e621', tags=args, limit=limit)
|
||||||
keys = list(posts.keys())
|
keys = list(posts.keys())
|
||||||
values = list(posts.values())
|
values = list(posts.values())
|
||||||
|
@ -369,8 +405,10 @@ class MsG:
|
||||||
await ctx.trigger_typing()
|
await ctx.trigger_typing()
|
||||||
try:
|
try:
|
||||||
posts.update(await self.check_return_posts(ctx=ctx, booru='e621', tags=args, limit=limit, previous=posts))
|
posts.update(await self.check_return_posts(ctx=ctx, booru='e621', tags=args, limit=limit, previous=posts))
|
||||||
|
|
||||||
except exc.NotFound:
|
except exc.NotFound:
|
||||||
await paginator.edit(content='❌ **No more images found.**')
|
await paginator.edit(content='❌ **No more images found.**')
|
||||||
|
|
||||||
keys = list(posts.keys())
|
keys = list(posts.keys())
|
||||||
values = list(posts.values())
|
values = list(posts.values())
|
||||||
|
|
||||||
|
@ -384,16 +422,22 @@ class MsG:
|
||||||
|
|
||||||
except exc.Abort:
|
except exc.Abort:
|
||||||
await paginator.edit(content='🚫 **Exited paginator.**')
|
await paginator.edit(content='🚫 **Exited paginator.**')
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
await paginator.edit(content='❌ **Paginator timed out.**')
|
await paginator.edit(content='❌ **Paginator timed out.**')
|
||||||
|
|
||||||
except exc.NotFound as e:
|
except exc.NotFound as e:
|
||||||
await ctx.send('❌ `{}` **not found.**'.format(e), delete_after=10)
|
await ctx.send('❌ `{}` **not found.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.TagBlacklisted as e:
|
except exc.TagBlacklisted as e:
|
||||||
await ctx.send('❌ `{}` **blacklisted.**'.format(e), delete_after=10)
|
await ctx.send('❌ `{}` **blacklisted.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.TagBoundsError as e:
|
except exc.TagBoundsError as e:
|
||||||
await ctx.send('❌ `{}` **out of bounds.** Tags limited to 5, currently.'.format(e), delete_after=10)
|
await ctx.send('❌ `{}` **out of bounds.** Tags limited to 5, currently.'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.Timeout:
|
except exc.Timeout:
|
||||||
await ctx.send('❌ **Request timed out.**')
|
await ctx.send('❌ **Request timed out.**')
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
for url in starred:
|
for url in starred:
|
||||||
await user.send(url)
|
await user.send(url)
|
||||||
|
@ -403,15 +447,13 @@ class MsG:
|
||||||
@e621_paginator.error
|
@e621_paginator.error
|
||||||
async def e621_paginator_error(self, ctx, error):
|
async def e621_paginator_error(self, ctx, error):
|
||||||
if isinstance(error, errext.CheckFailure):
|
if isinstance(error, errext.CheckFailure):
|
||||||
return await ctx.send('❌ <#' + str(ctx.message.channel.mention) + '> **is not an NSFW channel.**', delete_after=10)
|
return await ctx.send('❌ {} **is not an NSFW channel.**'.format(ctx.message.channel.mention), delete_after=10)
|
||||||
|
|
||||||
# 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
|
||||||
@commands.command(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])')
|
@commands.command(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])')
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
@checks.is_nsfw()
|
@checks.is_nsfw()
|
||||||
async def e621(self, ctx, *args):
|
async def e621(self, ctx, *args):
|
||||||
# global temp_urls
|
|
||||||
|
|
||||||
args = list(args)
|
args = list(args)
|
||||||
limit = 1
|
limit = 1
|
||||||
|
|
||||||
|
@ -420,46 +462,52 @@ class MsG:
|
||||||
# Checks for, defines, and removes limit from args
|
# Checks for, defines, and removes limit from args
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if len(arg) == 1:
|
if len(arg) == 1:
|
||||||
|
try:
|
||||||
if int(arg) <= 6 and int(arg) >= 1:
|
if int(arg) <= 6 and int(arg) >= 1:
|
||||||
limit = int(arg)
|
limit = int(arg)
|
||||||
args.remove(arg)
|
args.remove(arg)
|
||||||
else:
|
else:
|
||||||
raise exc.BoundsError(arg)
|
raise exc.BoundsError(arg)
|
||||||
# , previous=temp_urls.get(ctx.message.author.id, []))
|
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
posts = await self.check_return_posts(ctx=ctx, booru='e621', tags=args, limit=limit)
|
posts = await self.check_return_posts(ctx=ctx, booru='e621', tags=args, limit=limit)
|
||||||
for ident, post in posts.items():
|
for ident, post in posts.items():
|
||||||
embed = d.Embed(title=post['author'], url='https://e621.net/post/show/{}'.format(ident),
|
embed = d.Embed(title=post['author'], url='https://e621.net/post/show/{}'.format(ident),
|
||||||
color=ctx.me.color).set_image(url=post['url'])
|
color=ctx.me.color).set_image(url=post['url'])
|
||||||
embed.set_author(name=formatter.tostring(args, random=True),
|
embed.set_author(name=formatter.tostring(args, random=True),
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=ctx.message.author.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=user.avatar_url)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text=str(ident), icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
text=str(ident), icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
# temp_urls.setdefault(ctx.message.author.id, []).extend(posts.keys())
|
|
||||||
except exc.TagBlacklisted as e:
|
except exc.TagBlacklisted as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **blacklisted.**', delete_after=10)
|
await ctx.send('❌ `{}` **blacklisted.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.BoundsError as e:
|
except exc.BoundsError as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **out of bounds.**', delete_after=10)
|
await ctx.send('❌ `{}` **out of bounds.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.TagBoundsError as e:
|
except exc.TagBoundsError as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **out of bounds.** Tags limited to 5, currently.', delete_after=10)
|
await ctx.send('❌ `{}` **out of bounds.** Tags limited to 5, currently.'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.NotFound as e:
|
except exc.NotFound as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **not found.**', delete_after=10)
|
await ctx.send('❌ `{}` **not found.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.Timeout:
|
except exc.Timeout:
|
||||||
await ctx.send('❌ **Request timed out.**')
|
await ctx.send('❌ **Request timed out.**')
|
||||||
tools.command_dict.setdefault(str(ctx.message.author.id), {}).update(
|
|
||||||
|
tools.command_dict.setdefault(str(user.id), {}).update(
|
||||||
{'command': ctx.command, 'args': ctx.args})
|
{'command': ctx.command, 'args': ctx.args})
|
||||||
|
|
||||||
@e621.error
|
@e621.error
|
||||||
async def e621_error(self, ctx, error):
|
async def e621_error(self, ctx, error):
|
||||||
if isinstance(error, errext.CheckFailure):
|
if isinstance(error, errext.CheckFailure):
|
||||||
return await ctx.send('❌ <#' + str(ctx.message.channel.mention) + '> **is not an NSFW channel.**', delete_after=10)
|
return await ctx.send('❌ {} **is not an NSFW channel.**'.format(ctx.message.channel.mention), delete_after=10)
|
||||||
|
|
||||||
# Searches for and returns images from e926.net given tags when not blacklisted
|
# Searches for and returns images from e926.net given tags when not blacklisted
|
||||||
@commands.command(aliases=['e9', '9'], brief='e926 | SFW', description='e926 | SFW\nTag-based search for e926.net\n\nYou can only search 5 tags and 6 images at once for now.\ne9 [tags...] ([# of images])')
|
@commands.command(aliases=['e9', '9'], brief='e926 | SFW', description='e926 | SFW\nTag-based search for e926.net\n\nYou can only search 5 tags and 6 images at once for now.\ne9 [tags...] ([# of images])')
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def e926(self, ctx, *args):
|
async def e926(self, ctx, *args):
|
||||||
# global temp_urls
|
|
||||||
|
|
||||||
args = list(args)
|
args = list(args)
|
||||||
limit = 1
|
limit = 1
|
||||||
|
|
||||||
|
@ -468,30 +516,37 @@ class MsG:
|
||||||
# Checks for, defines, and removes limit from args
|
# Checks for, defines, and removes limit from args
|
||||||
for arg in args:
|
for arg in args:
|
||||||
if len(arg) == 1:
|
if len(arg) == 1:
|
||||||
|
try:
|
||||||
if int(arg) <= 6 and int(arg) >= 1:
|
if int(arg) <= 6 and int(arg) >= 1:
|
||||||
limit = int(arg)
|
limit = int(arg)
|
||||||
args.remove(arg)
|
args.remove(arg)
|
||||||
else:
|
else:
|
||||||
raise exc.BoundsError(arg)
|
raise exc.BoundsError(arg)
|
||||||
# , previous=temp_urls.get(ctx.message.author.id, []))
|
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
posts = await self.check_return_posts(ctx=ctx, booru='e926', tags=args, limit=limit)
|
posts = await self.check_return_posts(ctx=ctx, booru='e926', tags=args, limit=limit)
|
||||||
for ident, post in posts.items():
|
for ident, post in posts.items():
|
||||||
embed = d.Embed(title=post['author'], url='https://e926.net/post/show/{}'.format(ident),
|
embed = d.Embed(title=post['author'], url='https://e926.net/post/show/{}'.format(ident),
|
||||||
color=ctx.me.color).set_image(url=post['url'])
|
color=ctx.me.color).set_image(url=post['url'])
|
||||||
embed.set_author(name=formatter.tostring(args, random=True),
|
embed.set_author(name=formatter.tostring(args, random=True),
|
||||||
url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=ctx.message.author.avatar_url)
|
url='https://e621.net/post?tags={}'.format(','.join(args)), icon_url=user.avatar_url)
|
||||||
embed.set_footer(
|
embed.set_footer(
|
||||||
text=str(ident), icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
text=str(ident), icon_url='http://ndl.mgccw.com/mu3/app/20141013/18/1413204353554/icon/icon_xl.png')
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
# temp_urls.setdefault(ctx.message.author.id, []).extend(posts.values())
|
|
||||||
except exc.TagBlacklisted as e:
|
except exc.TagBlacklisted as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **blacklisted.**', delete_after=10)
|
await ctx.send('❌ `{}` **blacklisted.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.BoundsError as e:
|
except exc.BoundsError as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **out of bounds.**', delete_after=10)
|
await ctx.send('❌ `{}` **out of bounds.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.TagBoundsError as e:
|
except exc.TagBoundsError as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **out of bounds.** Tags limited to 5, currently.', delete_after=10)
|
await ctx.send('❌ `{}` **out of bounds.** Tags limited to 5, currently.'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.NotFound as e:
|
except exc.NotFound as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **not found.**', delete_after=10)
|
await ctx.send('❌ `{}` **not found.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
except exc.Timeout:
|
except exc.Timeout:
|
||||||
await ctx.send('❌ **Request timed out.**')
|
await ctx.send('❌ **Request timed out.**')
|
||||||
|
|
||||||
|
@ -500,14 +555,14 @@ class MsG:
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def blacklist(self, ctx):
|
async def blacklist(self, ctx):
|
||||||
if ctx.invoked_subcommand is None:
|
if ctx.invoked_subcommand is None:
|
||||||
await ctx.send('❌ **Use a flag to manage blacklists.**\n*Type* `' + ctx.prefix + 'help bl` *for more info.*', delete_after=10)
|
await ctx.send('❌ **Use a flag to manage blacklists.**\n*Type* `{}help bl` *for more info.*'.format(ctx.prefix), delete_after=10)
|
||||||
|
|
||||||
@blacklist.error
|
@blacklist.error
|
||||||
async def blacklist_error(self, ctx, error):
|
async def blacklist_error(self, ctx, error):
|
||||||
if isinstance(error, commands.CheckFailure):
|
if isinstance(error, commands.CheckFailure):
|
||||||
return await ctx.send('❌ **Insufficient permissions.**')
|
return await ctx.send('❌ **Insufficient permissions.**')
|
||||||
if isinstance(error, KeyError):
|
# if isinstance(error, KeyError):
|
||||||
return await ctx.send('❌ **Blacklist does not exist.**', delete_after=10)
|
# return await ctx.send('❌ **Blacklist does not exist.**', delete_after=10)
|
||||||
|
|
||||||
@blacklist.group(name='get', aliases=['g'])
|
@blacklist.group(name='get', aliases=['g'])
|
||||||
async def _get_blacklist(self, ctx):
|
async def _get_blacklist(self, ctx):
|
||||||
|
@ -516,26 +571,29 @@ class MsG:
|
||||||
|
|
||||||
@_get_blacklist.command(name='global', aliases=['gl', 'g'])
|
@_get_blacklist.command(name='global', aliases=['gl', 'g'])
|
||||||
async def __get_global_blacklist(self, ctx):
|
async def __get_global_blacklist(self, ctx):
|
||||||
await ctx.send('🚫 **Global blacklist:**\n```\n' + formatter.tostring(self.blacklists['global_blacklist']) + '```')
|
await ctx.send('🚫 **Global blacklist:**\n```\n{}```'.format(formatter.tostring(self.blacklists['global_blacklist'])))
|
||||||
|
|
||||||
@_get_blacklist.command(name='channel', aliases=['ch', 'c'])
|
@_get_blacklist.command(name='channel', aliases=['ch', 'c'])
|
||||||
async def __get_channel_blacklist(self, ctx):
|
async def __get_channel_blacklist(self, ctx):
|
||||||
guild = ctx.message.guild if isinstance(
|
guild = ctx.message.guild if isinstance(
|
||||||
ctx.message.guild, d.Guild) else ctx.message.channel
|
ctx.message.guild, d.Guild) else ctx.message.channel
|
||||||
channel = ctx.message.channel
|
channel = ctx.message.channel
|
||||||
await ctx.send('🚫 ' + channel.mention + ' **blacklist:**\n```\n' + formatter.tostring(self.blacklists['guild_blacklist'].get(guild.id, {}).get(channel.id, set())) + '```')
|
|
||||||
|
await ctx.send('🚫 {} **blacklist:**\n```\n{}```'.format(channel.mention, formatter.tostring(self.blacklists['guild_blacklist'].get(guild.id, {}).get(channel.id, set()))))
|
||||||
|
|
||||||
@_get_blacklist.command(name='me', aliases=['m'])
|
@_get_blacklist.command(name='me', aliases=['m'])
|
||||||
async def __get_user_blacklist(self, ctx):
|
async def __get_user_blacklist(self, ctx):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
await ctx.send('🚫 ' + user.mention + '**\'s blacklist:**\n```\n' + formatter.tostring(self.blacklists['user_blacklist'].get(user.id, set())) + '```', delete_after=10)
|
|
||||||
|
await ctx.send('🚫 {}**\'s blacklist:**\n```\n{}```'.format(user.mention, formatter.tostring(self.blacklists['user_blacklist'].get(user.id, set()))), delete_after=10)
|
||||||
|
|
||||||
@_get_blacklist.command(name='here', aliases=['h'])
|
@_get_blacklist.command(name='here', aliases=['h'])
|
||||||
async def __get_here_blacklists(self, ctx):
|
async def __get_here_blacklists(self, ctx):
|
||||||
guild = ctx.message.guild if isinstance(
|
guild = ctx.message.guild if isinstance(
|
||||||
ctx.message.guild, d.Guild) else ctx.message.channel
|
ctx.message.guild, d.Guild) else ctx.message.channel
|
||||||
channel = ctx.message.channel
|
channel = ctx.message.channel
|
||||||
await ctx.send('🚫 **__Blacklisted:__**\n\n**Global:**\n```\n' + formatter.tostring(self.blacklists['global_blacklist']) + '```\n**' + channel.mention + ':**\n```\n' + formatter.tostring(self.blacklists['guild_blacklist'].get(guild.id, {}).get(channel.id, set())) + '```')
|
|
||||||
|
await ctx.send('🚫 **__Blacklisted:__**\n\n**Global:**\n```\n{}```\n**{}:**\n```\n{}```'.format(formatter.tostring(self.blacklists['global_blacklist']), channel.mention, formatter.tostring(self.blacklists['guild_blacklist'].get(guild.id, {}).get(channel.id, set()))))
|
||||||
|
|
||||||
@_get_blacklist.group(name='all', aliases=['a'])
|
@_get_blacklist.group(name='all', aliases=['a'])
|
||||||
async def __get_all_blacklists(self, ctx):
|
async def __get_all_blacklists(self, ctx):
|
||||||
|
@ -547,12 +605,13 @@ class MsG:
|
||||||
async def ___get_all_guild_blacklists(self, ctx):
|
async def ___get_all_guild_blacklists(self, ctx):
|
||||||
guild = ctx.message.guild if isinstance(
|
guild = ctx.message.guild if isinstance(
|
||||||
ctx.message.guild, d.Guild) else ctx.message.channel
|
ctx.message.guild, d.Guild) else ctx.message.channel
|
||||||
await ctx.send('🚫 **__' + guild.name + ' blacklists:__**\n\n' + formatter.dict_tostring(self.blacklists['guild_blacklist'].get(guild.id, {})))
|
|
||||||
|
await ctx.send('🚫 **__{} blacklists:__**\n\n{}'.format(guild.name, formatter.dict_tostring(self.blacklists['guild_blacklist'].get(guild.id, {}))))
|
||||||
|
|
||||||
@__get_all_blacklists.command(name='user', aliases=['u', 'member', 'm'])
|
@__get_all_blacklists.command(name='user', aliases=['u', 'member', 'm'])
|
||||||
@commands.is_owner()
|
@commands.is_owner()
|
||||||
async def ___get_all_user_blacklists(self, ctx):
|
async def ___get_all_user_blacklists(self, ctx):
|
||||||
await ctx.send('🚫 **__User blacklists:__**\n\n' + formatter.dict_tostring(self.blacklists['user_blacklist']))
|
await ctx.send('🚫 **__User blacklists:__**\n\n{}'.format(formatter.dict_tostring(self.blacklists['user_blacklist'])))
|
||||||
|
|
||||||
@blacklist.group(name='add', aliases=['a'])
|
@blacklist.group(name='add', aliases=['a'])
|
||||||
async def _add_tags(self, ctx):
|
async def _add_tags(self, ctx):
|
||||||
|
@ -570,7 +629,8 @@ class MsG:
|
||||||
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' + formatter.tostring(tags) + '```', delete_after=5)
|
|
||||||
|
await ctx.send('✅ **Added to global blacklist:**\n```\n{}```'.format(formatter.tostring(tags)), delete_after=5)
|
||||||
|
|
||||||
@_add_tags.command(name='channel', aliases=['ch', 'c'])
|
@_add_tags.command(name='channel', aliases=['ch', 'c'])
|
||||||
@commands.has_permissions(manage_channels=True)
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
@ -588,7 +648,8 @@ class MsG:
|
||||||
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** ' + channel.mention + ' **blacklist:**\n```\n' + formatter.tostring(tags) + '```', delete_after=5)
|
|
||||||
|
await ctx.send('✅ **Added to** {} **blacklist:**\n```\n{}```'.format(channel.mention, formatter.tostring(tags)), delete_after=5)
|
||||||
|
|
||||||
@_add_tags.command(name='me', aliases=['m'])
|
@_add_tags.command(name='me', aliases=['m'])
|
||||||
async def __add_user_tags(self, ctx, *tags):
|
async def __add_user_tags(self, ctx, *tags):
|
||||||
|
@ -602,7 +663,8 @@ class MsG:
|
||||||
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('✅ ' + user.mention + ' **added:**\n```\n' + formatter.tostring(tags) + '```', delete_after=5)
|
|
||||||
|
await ctx.send('✅ {} **added:**\n```\n{}```'.format(user.mention, formatter.tostring(tags)), delete_after=5)
|
||||||
|
|
||||||
@blacklist.group(name='remove', aliases=['rm', 'r'])
|
@blacklist.group(name='remove', aliases=['rm', 'r'])
|
||||||
async def _remove_tags(self, ctx):
|
async def _remove_tags(self, ctx):
|
||||||
|
@ -616,12 +678,15 @@ class MsG:
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
try:
|
try:
|
||||||
self.blacklists['global_blacklist'].remove(tag)
|
self.blacklists['global_blacklist'].remove(tag)
|
||||||
|
|
||||||
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 from global blacklist:**\n```\n' + formatter.tostring(tags) + '```', delete_after=5)
|
await ctx.send('✅ **Removed from global blacklist:**\n```\n' + formatter.tostring(tags) + '```', delete_after=5)
|
||||||
|
|
||||||
except exc.TagError as e:
|
except exc.TagError as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **not in blacklist.**', delete_after=10)
|
await ctx.send('❌ `{}` **not in blacklist.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
@_remove_tags.command(name='channel', aliases=['ch', 'c'])
|
@_remove_tags.command(name='channel', aliases=['ch', 'c'])
|
||||||
@commands.has_permissions(manage_channels=True)
|
@commands.has_permissions(manage_channels=True)
|
||||||
|
@ -629,30 +694,38 @@ class MsG:
|
||||||
guild = ctx.message.guild if isinstance(
|
guild = ctx.message.guild if isinstance(
|
||||||
ctx.message.guild, d.Guild) else ctx.message.channel
|
ctx.message.guild, d.Guild) else ctx.message.channel
|
||||||
channel = ctx.message.channel
|
channel = ctx.message.channel
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
try:
|
try:
|
||||||
self.blacklists['guild_blacklist'][guild.id][channel.id].remove(tag)
|
self.blacklists['guild_blacklist'][guild.id][channel.id].remove(tag)
|
||||||
|
|
||||||
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 from** ' + channel.mention + ' **blacklist:**\n```\n' + formatter.tostring(tags) + '```', delete_after=5)
|
await ctx.send('✅ **Removed from** ' + channel.mention + ' **blacklist:**\n```\n' + formatter.tostring(tags) + '```', delete_after=5)
|
||||||
|
|
||||||
except exc.TagError as e:
|
except exc.TagError as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **not in blacklist.**', delete_after=10)
|
await ctx.send('❌ `{}` **not in blacklist.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
@_remove_tags.command(name='me', aliases=['m'])
|
@_remove_tags.command(name='me', aliases=['m'])
|
||||||
async def __remove_user_tags(self, ctx, *tags):
|
async def __remove_user_tags(self, ctx, *tags):
|
||||||
user = ctx.message.author
|
user = ctx.message.author
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
try:
|
try:
|
||||||
self.blacklists['user_blacklist'][user.id].remove(tag)
|
self.blacklists['user_blacklist'][user.id].remove(tag)
|
||||||
|
|
||||||
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('✅ ' + user.mention + ' **removed:**\n```\n' + formatter.tostring(tags) + '```', delete_after=5)
|
|
||||||
|
await ctx.send('✅ {} **removed:**\n```\n{}```'.format(user.mention, formatter.tostring(tags)), delete_after=5)
|
||||||
|
|
||||||
except exc.TagError as e:
|
except exc.TagError as e:
|
||||||
await ctx.send('❌ `' + str(e) + '` **not in blacklist.**', delete_after=10)
|
await ctx.send('❌ `{}` **not in blacklist.**'.format(e), delete_after=10)
|
||||||
|
|
||||||
@blacklist.group(name='clear', aliases=['cl', 'c'])
|
@blacklist.group(name='clear', aliases=['cl', 'c'])
|
||||||
async def _clear_blacklist(self, ctx):
|
async def _clear_blacklist(self, ctx):
|
||||||
|
@ -664,6 +737,7 @@ class MsG:
|
||||||
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)
|
||||||
|
|
||||||
@_clear_blacklist.command(name='channel', aliases=['ch', 'c'])
|
@_clear_blacklist.command(name='channel', aliases=['ch', 'c'])
|
||||||
|
@ -672,13 +746,17 @@ class MsG:
|
||||||
guild = ctx.message.guild if isinstance(
|
guild = ctx.message.guild if isinstance(
|
||||||
ctx.message.guild, d.Guild) else ctx.message.channel
|
ctx.message.guild, d.Guild) else ctx.message.channel
|
||||||
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('✅ <#' + channel.mention + '> **blacklist cleared.**', delete_after=5)
|
|
||||||
|
await ctx.send('✅ {} **blacklist cleared.**'.format(channel.mention), delete_after=5)
|
||||||
|
|
||||||
@_clear_blacklist.command(name='me', aliases=['m'])
|
@_clear_blacklist.command(name='me', aliases=['m'])
|
||||||
async def __clear_user_blacklist(self, ctx):
|
async def __clear_user_blacklist(self, ctx):
|
||||||
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('✅ ' + user.mention + '**\'s blacklist cleared.**', delete_after=5)
|
|
||||||
|
await ctx.send('✅ {}**\'s blacklist cleared.**'.format(user.mention), delete_after=5)
|
||||||
|
|
|
@ -62,6 +62,18 @@ class Bot:
|
||||||
async def invite(self, ctx):
|
async def invite(self, ctx):
|
||||||
await ctx.send('🔗 https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot&permissions={}'.format(self.config['client_id'], self.config['permissions']), delete_after=10)
|
await ctx.send('🔗 https://discordapp.com/oauth2/authorize?&client_id={}&scope=bot&permissions={}'.format(self.config['client_id'], self.config['permissions']), delete_after=10)
|
||||||
|
|
||||||
|
@commands.command(aliases=['presence', 'game'], hidden=True)
|
||||||
|
@commands.is_owner()
|
||||||
|
@checks.del_ctx()
|
||||||
|
async def status(self, ctx, game):
|
||||||
|
try:
|
||||||
|
if game is not None:
|
||||||
|
await self.bot.change_presence(game=d.Game(name=game))
|
||||||
|
else:
|
||||||
|
raise exc.NotFound
|
||||||
|
except exc.NotFound:
|
||||||
|
await ctx.send('❌ **No game given.**', delete_after=10)
|
||||||
|
|
||||||
|
|
||||||
class Tools:
|
class Tools:
|
||||||
|
|
||||||
|
@ -96,8 +108,8 @@ class Tools:
|
||||||
@checks.del_ctx()
|
@checks.del_ctx()
|
||||||
async def console(self, ctx):
|
async def console(self, ctx):
|
||||||
def execute(msg):
|
def execute(msg):
|
||||||
if msg.content == ',exit' and msg.author is ctx.message.author:
|
if msg.content == 'exit' and msg.author is ctx.message.author:
|
||||||
raise exc.CheckFail
|
raise exc.Abort
|
||||||
elif msg.author is ctx.message.author and msg.channel is ctx.message.channel:
|
elif msg.author is ctx.message.author and msg.channel is ctx.message.channel:
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -107,20 +119,23 @@ class Tools:
|
||||||
console = await self.generate(ctx)
|
console = await self.generate(ctx)
|
||||||
exception = await self.generate_err(ctx)
|
exception = await self.generate_err(ctx)
|
||||||
while not self.bot.is_closed():
|
while not self.bot.is_closed():
|
||||||
|
try:
|
||||||
exe = await self.bot.wait_for('message', check=execute)
|
exe = await self.bot.wait_for('message', check=execute)
|
||||||
|
except exc.Abort:
|
||||||
|
raise exc.Abort
|
||||||
|
finally:
|
||||||
await exe.delete()
|
await exe.delete()
|
||||||
|
try:
|
||||||
sys.stdout = io.StringIO()
|
sys.stdout = io.StringIO()
|
||||||
sys.stderr = io.StringIO()
|
sys.stderr = io.StringIO()
|
||||||
try:
|
|
||||||
exec(exe.content)
|
exec(exe.content)
|
||||||
except Exception:
|
except Exception:
|
||||||
tb.print_exc(limit=1)
|
await self.refresh_err(exception, tb.format_exc(limit=1))
|
||||||
|
finally:
|
||||||
await self.refresh(console, exe.content, sys.stdout.getvalue())
|
await self.refresh(console, exe.content, sys.stdout.getvalue())
|
||||||
await self.refresh_err(exception, sys.stderr.getvalue())
|
|
||||||
await ctx.send(console.content[10:-3])
|
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = sys.__stdout__
|
||||||
sys.stderr = sys.__stderr__
|
sys.stderr = sys.__stderr__
|
||||||
except exc.CheckFail:
|
except exc.Abort:
|
||||||
await ctx.send('↩️ **Exited console.**')
|
await ctx.send('↩️ **Exited console.**')
|
||||||
finally:
|
finally:
|
||||||
sys.stdout = sys.__stdout__
|
sys.stdout = sys.__stdout__
|
||||||
|
|
|
@ -48,7 +48,7 @@ class Utils:
|
||||||
async def ping(self, ctx):
|
async def ping(self, ctx):
|
||||||
global command_dict
|
global command_dict
|
||||||
|
|
||||||
await ctx.send(ctx.message.author.mention + ' 🏓 `' + str(int(self.bot.latency * 1000)) + 'ms`', delete_after=5)
|
await ctx.send(ctx.message.author.mention + ' 🏓 `' + str(round(self.bot.latency * 1000)) + 'ms`', delete_after=5)
|
||||||
command_dict.setdefault(str(ctx.message.author.id), {}).update({'command': ctx.command})
|
command_dict.setdefault(str(ctx.message.author.id), {}).update({'command': ctx.command})
|
||||||
|
|
||||||
@commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes')
|
@commands.command(aliases=['pre'], brief='List bot prefixes', description='Shows all used prefixes')
|
||||||
|
|
|
@ -6,11 +6,10 @@ import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.commands import errors
|
from discord.ext.commands import errors
|
||||||
|
|
||||||
with open('config.json') as infile:
|
from utils import utils as u
|
||||||
config = json.load(infile)
|
|
||||||
|
|
||||||
owner_id = config['owner_id']
|
owner_id = u.config['owner_id']
|
||||||
listed_ids = config['listed_ids']
|
listed_ids = u.config['listed_ids']
|
||||||
|
|
||||||
|
|
||||||
def is_owner():
|
def is_owner():
|
||||||
|
|
|
@ -17,31 +17,18 @@ from misc import exceptions as exc
|
||||||
from misc import checks
|
from misc import checks
|
||||||
from utils import utils as u
|
from utils import utils as u
|
||||||
|
|
||||||
try:
|
|
||||||
with open('config.json') as infile:
|
|
||||||
config = json.load(infile)
|
|
||||||
print('\"config.json\" loaded.')
|
|
||||||
except FileNotFoundError:
|
|
||||||
with open('config.json', 'w') as outfile:
|
|
||||||
json.dump({'client_id': 0, 'listed_ids': [0], 'owner_id': 0, 'permissions': 126016, 'prefix': ',',
|
|
||||||
'shutdown_channel': 0, 'startup_channel': 0, 'token': 'str'}, outfile, indent=4, sort_keys=True)
|
|
||||||
raise FileNotFoundError(
|
|
||||||
'Config file not found: \"config.json\" created with abstract values. Restart \"run.py\" with correct values.')
|
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
print('PID {}'.format(os.getpid()))
|
print('PID {}'.format(os.getpid()))
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix=config['prefix'], description='Experimental booru bot')
|
bot = commands.Bot(command_prefix=u.config['prefix'], description='Experimental booru bot')
|
||||||
|
|
||||||
|
|
||||||
# Send and print ready message to #testing and console after logon
|
# Send and print ready message to #testing and console after logon
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
bot.add_cog(tools.Utils(bot))
|
bot.add_cog(tools.Utils(bot))
|
||||||
bot.add_cog(owner.Bot(bot, config))
|
bot.add_cog(owner.Bot(bot))
|
||||||
bot.add_cog(owner.Tools(bot))
|
bot.add_cog(owner.Tools(bot))
|
||||||
bot.add_cog(management.Administration(bot))
|
bot.add_cog(management.Administration(bot))
|
||||||
bot.add_cog(info.Info(bot))
|
bot.add_cog(info.Info(bot))
|
||||||
|
@ -51,8 +38,8 @@ async def on_ready():
|
||||||
|
|
||||||
# bot.loop.create_task(u.clear(booru.temp_urls, 30*60))
|
# bot.loop.create_task(u.clear(booru.temp_urls, 30*60))
|
||||||
|
|
||||||
if isinstance(bot.get_channel(config['startup_channel']), d.TextChannel):
|
if isinstance(bot.get_channel(u.config['startup_channel']), d.TextChannel):
|
||||||
await bot.get_channel(config['startup_channel']).send('**Started.** ☀️')
|
await bot.get_channel(u.config['startup_channel']).send('**Started.** ☀️')
|
||||||
print('CONNECTED')
|
print('CONNECTED')
|
||||||
print(bot.user.name)
|
print(bot.user.name)
|
||||||
print('-------')
|
print('-------')
|
||||||
|
@ -60,16 +47,29 @@ async def on_ready():
|
||||||
|
|
||||||
@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):
|
||||||
print(error)
|
print(error)
|
||||||
await ctx.send('{}\n```\n{}```'.format(exc.base, error))
|
await ctx.send('{}\n```\n{}```'.format(exc.base, error))
|
||||||
|
|
||||||
|
|
||||||
async def on_reaction_add(r, u):
|
async def on_reaction_add(r, u):
|
||||||
print('Reacted')
|
pass
|
||||||
|
|
||||||
|
|
||||||
async def on_reaction_remove(r, u):
|
async def on_reaction_remove(r, u):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
async def reaction_add(r, u):
|
||||||
|
bot.add_listener(on_reaction_add)
|
||||||
|
print('Reacted')
|
||||||
|
bot.remove_listener(on_reaction_remove)
|
||||||
|
|
||||||
|
|
||||||
|
async def reaction_remove(r, u):
|
||||||
|
bot.add_listener(on_reaction_remove)
|
||||||
print('Removed')
|
print('Removed')
|
||||||
|
bot.remove_listener(on_reaction_remove)
|
||||||
|
|
||||||
|
|
||||||
@bot.command(name=',test', hidden=True)
|
@bot.command(name=',test', hidden=True)
|
||||||
|
@ -81,4 +81,4 @@ async def test(ctx):
|
||||||
bot.add_listener(on_reaction_add)
|
bot.add_listener(on_reaction_add)
|
||||||
bot.add_listener(on_reaction_remove)
|
bot.add_listener(on_reaction_remove)
|
||||||
|
|
||||||
bot.run(config['token'])
|
bot.run(u.config['token'])
|
||||||
|
|
|
@ -30,8 +30,16 @@ def dump(obj, filename):
|
||||||
|
|
||||||
tasks = setdefault('./cogs/tasks.pkl', {})
|
tasks = setdefault('./cogs/tasks.pkl', {})
|
||||||
|
|
||||||
with open('config.json') as infile:
|
try:
|
||||||
|
with open('config.json') as infile:
|
||||||
config = json.load(infile)
|
config = json.load(infile)
|
||||||
|
print('\"config.json\" loaded.')
|
||||||
|
except FileNotFoundError:
|
||||||
|
with open('config.json', 'w') as outfile:
|
||||||
|
json.dump({'client_id': 0, 'listed_ids': [0], 'owner_id': 0, 'permissions': 126016, 'prefix': ',',
|
||||||
|
'shutdown_channel': 0, 'startup_channel': 0, 'token': 'str'}, outfile, indent=4, sort_keys=True)
|
||||||
|
raise FileNotFoundError(
|
||||||
|
'Config file not found: \"config.json\" created with abstract values. Restart \"run.py\" with correct values.')
|
||||||
|
|
||||||
|
|
||||||
async def clear(obj, interval=10 * 60, replace=None):
|
async def clear(obj, interval=10 * 60, replace=None):
|
||||||
|
|
Loading…
Reference in a new issue