2017-09-24 14:09:02 -04:00
import asyncio
2017-10-12 22:34:48 -04:00
import json
2017-10-16 02:08:20 -04:00
import re
2017-11-20 02:16:01 -05:00
import sys
2017-10-11 03:11:00 -04:00
import traceback as tb
2017-10-15 12:57:31 -04:00
from contextlib import suppress
2017-11-19 23:28:17 -05:00
from datetime import datetime as dt
from datetime import timedelta as td
2017-11-20 02:16:01 -05:00
from fractions import gcd
2017-11-21 06:14:12 -05:00
import copy
2017-10-12 22:34:48 -04:00
2017-10-11 03:11:00 -04:00
import discord as d
2017-10-12 22:34:48 -04:00
from discord import errors as err
2017-09-24 14:09:02 -04:00
from discord import reaction
2017-11-20 06:18:42 -05:00
from discord . ext import commands as cmds
2017-10-02 19:37:58 -04:00
from discord . ext . commands import errors as errext
2017-10-12 22:34:48 -04:00
2017-10-02 15:20:04 -04:00
from cogs import tools
2017-09-24 14:09:02 -04:00
from misc import exceptions as exc
2017-10-12 22:34:48 -04:00
from misc import checks
2017-10-11 03:11:00 -04:00
from utils import utils as u
2017-10-12 22:34:48 -04:00
from utils import formatter , scraper
2017-10-11 03:11:00 -04:00
2017-10-12 22:34:48 -04:00
2017-09-24 11:05:28 -04:00
class MsG :
2017-10-20 16:14:24 -04:00
def __init__ ( self , bot ) :
self . bot = bot
self . LIMIT = 100
2017-10-28 15:43:29 -04:00
self . HISTORY_LIMIT = 150
2017-10-20 16:14:24 -04:00
self . RATE_LIMIT = u . RATE_LIMIT
2017-11-20 11:28:49 -05:00
self . reversiqueue = asyncio . Queue ( )
2017-11-20 11:36:34 -05:00
self . heartqueue = asyncio . Queue ( )
2017-11-19 23:25:30 -05:00
self . reversifying = False
2017-11-19 23:28:17 -05:00
self . updating = False
2017-11-20 11:36:34 -05:00
self . hearting = False
2017-11-19 23:28:17 -05:00
time = ( dt . utcnow ( ) - td ( days = 29 ) ) . strftime ( ' %d / % m/ % Y/ % H: % M: % S ' )
self . suggested = u . setdefault ( ' cogs/suggested.pkl ' , 7 )
# self.suggested = u.setdefault('cogs/suggested.pkl', {'last_update': 'test', 'tags': {}, 'total': 1})
print ( self . suggested )
2017-11-19 23:32:09 -05:00
self . favorites = u . setdefault ( ' cogs/favorites.pkl ' , { } )
2017-10-20 16:14:24 -04:00
self . blacklists = u . setdefault (
' cogs/blacklists.pkl ' , { ' global_blacklist ' : set ( ) , ' guild_blacklist ' : { } , ' user_blacklist ' : { } } )
self . aliases = u . setdefault ( ' cogs/aliases.pkl ' , { } )
2017-10-17 19:04:45 -04:00
2017-11-20 11:36:34 -05:00
if not self . hearting :
self . hearting = True
self . bot . loop . create_task ( self . _send_hearts ( ) )
print ( ' STARTED : hearting ' )
2017-11-20 02:17:48 -05:00
if u . tasks [ ' auto_rev ' ] :
for channel in u . tasks [ ' auto_rev ' ] :
2017-10-20 16:14:24 -04:00
temp = self . bot . get_channel ( channel )
2017-11-19 23:25:30 -05:00
self . bot . loop . create_task ( self . queue_for_reversification ( temp ) )
2017-11-20 11:28:49 -05:00
print ( ' STARTED : auto-reversifying in # {} ' . format ( temp . name ) )
2017-11-19 23:25:30 -05:00
self . reversifying = True
self . bot . loop . create_task ( self . _reversify ( ) )
2017-12-31 21:54:37 -05:00
if u . tasks [ ' auto_hrt ' ] :
for channel in u . tasks [ ' auto_hrt ' ] :
temp = self . bot . get_channel ( channel )
self . bot . loop . create_task ( self . queue_for_hearts ( channel = temp ) )
print ( f ' STARTED : auto-hearting in # { temp . name } ' )
2017-11-19 23:28:17 -05:00
# if not self.updating:
# self.updating = True
# self.bot.loop.create_task(self._update_suggested())
2017-10-17 19:04:45 -04:00
2017-11-19 23:28:17 -05:00
async def _update_suggested ( self ) :
while self . updating :
print ( ' Checking for tag updates... ' )
print ( self . suggested )
time = dt . utcnow ( )
last_update = dt . strptime ( self . suggested [ ' last_update ' ] , ' %d / % m/ % Y/ % H: % M: % S ' )
delta = time - last_update
print ( delta . days )
if delta . days < 30 :
print ( ' Up to date. ' )
else :
page = 1
pages = len ( list ( self . suggested [ ' tags ' ] . keys ( ) ) )
print ( f ' Last updated: { self . suggested [ " last_update " ] } ' )
print ( ' Updating tags... ' )
content = await u . fetch ( ' https://e621.net/tag/index.json ' , params = { ' order ' : ' count ' , ' limit ' : 500 , ' page ' : page } , json = True )
while content :
for tag in content :
self . suggested [ ' tags ' ] [ tag [ ' name ' ] ] = tag [ ' count ' ]
self . suggested [ ' total ' ] + = tag [ ' count ' ]
print ( f ' UPDATED : PAGE { page } / { pages } ' , end = ' \r ' )
page + = 1
content = await u . fetch ( ' https://e621.net/tag/index.json ' , params = { ' order ' : ' count ' , ' limit ' : 500 , ' page ' : page } , json = True )
u . dump ( self . suggested , ' cogs/suggested.pkl ' )
self . suggested [ ' last_update ' ] = time . strftime ( ' %d / % m/ % Y/ % H: % M: % S ' )
print ( ' \n Finished updating tags. ' )
await asyncio . sleep ( 24 * 60 * 60 )
2017-11-19 23:34:29 -05:00
def _get_favorites ( self , ctx , args ) :
if ' -f ' in args or ' -favs ' in args or ' -faves ' in args or ' -favorites ' in args :
if self . favorites . get ( ctx . author . id , { } ) . get ( ' tags ' , set ( ) ) :
args = [ ' ~ {} ' . format ( tag )
for tag in self . favorites [ ctx . author . id ] [ ' tags ' ] ]
else :
raise exc . FavoritesNotFound
return args
def _get_score ( self , score ) :
if score < 0 :
return ' https://emojipedia-us.s3.amazonaws.com/thumbs/320/twitter/103/pouting-face_1f621.png '
elif 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
2017-11-20 11:36:34 -05:00
async def _send_hearts ( self ) :
while self . hearting :
temp = await self . heartqueue . get ( )
2017-12-31 21:54:37 -05:00
if isinstance ( temp [ 1 ] , d . Embed ) :
2017-12-31 21:28:58 -05:00
await temp [ 0 ] . send ( embed = temp [ 1 ] )
2017-11-20 11:36:34 -05:00
2017-12-31 21:28:58 -05:00
await asyncio . sleep ( self . RATE_LIMIT )
2017-12-31 21:54:37 -05:00
elif isinstance ( temp [ 1 ] , d . Message ) :
for match in re . finditer ( ' (https?: \ / \ /[^ ]* \ .(?:gif|png|jpg|jpeg)) ' , temp [ 1 ] . content ) :
await temp [ 0 ] . send ( match )
await asyncio . sleep ( self . RATE_LIMIT )
for attachment in temp [ 1 ] . attachments :
await temp [ 0 ] . send ( attachment . url )
await asyncio . sleep ( self . RATE_LIMIT )
2017-11-20 11:36:34 -05:00
print ( ' STOPPED : hearting ' )
2017-12-31 21:54:37 -05:00
async def queue_for_hearts ( self , * , message = None , send = None , channel = None , reaction = True , timeout = 60 * 60 ) :
2017-11-20 11:36:34 -05:00
def on_reaction ( reaction , user ) :
if reaction . emoji == ' \N{HEAVY BLACK HEART} ' and reaction . message . id == message . id :
raise exc . Save ( user )
return False
2017-12-31 21:54:37 -05:00
def on_message ( msg ) :
2017-12-31 21:28:58 -05:00
if ' stop h ' in msg . content . lower ( ) :
2017-12-31 21:54:37 -05:00
raise exc . Abort
return msg . channel . id == channel . id and ( re . search ( ' (https?: \ / \ /[^ ]* \ .(?:gif|png|jpg|jpeg)) ' , msg . content ) or msg . attachments )
2017-11-20 11:36:34 -05:00
2017-12-31 21:54:37 -05:00
if message :
2017-12-31 21:28:58 -05:00
try :
2017-12-31 21:54:37 -05:00
if reaction :
2017-12-31 21:28:58 -05:00
await message . add_reaction ( ' \N{HEAVY BLACK HEART} ' )
await asyncio . sleep ( 1 )
2017-11-20 11:36:34 -05:00
2017-12-31 21:28:58 -05:00
while self . hearting :
try :
2017-12-31 21:54:37 -05:00
await self . bot . wait_for ( ' reaction_add ' , check = on_reaction , timeout = timeout )
2017-11-20 11:36:34 -05:00
2017-12-31 21:28:58 -05:00
except exc . Save as e :
2017-12-31 21:54:37 -05:00
await self . heartqueue . put ( ( e . user , send if send else message ) )
2017-11-20 11:36:34 -05:00
2017-12-31 21:28:58 -05:00
except asyncio . TimeoutError :
await message . add_reaction ( ' \N{WHITE HEAVY CHECK MARK} ' )
2017-12-31 21:54:37 -05:00
else :
try :
async for message in channel . history ( limit = 300 ) :
if re . search ( ' (https?: \ / \ /[^ ]* \ .(?:gif|png|jpg|jpeg)) ' , message . content ) or message . attachments :
self . bot . loop . create_task ( self . _wait_for_reaction ( message ) )
while self . hearting :
message = await self . bot . wait_for ( ' message ' , check = on_message )
self . bot . loop . create_task ( self . _wait_for_reaction ( message ) )
except exc . Abort :
u . tasks [ ' auto_hrt ' ] . remove ( channel . id )
u . dump ( u . tasks , ' cogs/tasks.pkl ' )
print ( ' STOPPED : auto-hearting in # {} ' . format ( channel . name ) )
await channel . send ( ' **Stopped queueing messages for hearting in** {} ' . format ( channel . mention ) , delete_after = 5 )
async def _wait_for_reaction ( self , message ) :
def on_reaction ( reaction , user ) :
if reaction . emoji == ' \N{HEAVY BLACK HEART} ' and reaction . message . id == message . id :
raise exc . Save ( user )
return False
while self . hearting :
try :
await self . bot . wait_for ( ' reaction_add ' , check = on_reaction )
except exc . Save as e :
await self . heartqueue . put ( ( e . user , message ) )
@cmds.command ( name = ' autoheart ' , aliases = [ ' autohrt ' ] )
@cmds.has_permissions ( administrator = True )
async def auto_heart ( self , ctx ) :
try :
if ctx . channel . id not in u . tasks [ ' auto_hrt ' ] :
u . tasks [ ' auto_hrt ' ] . append ( ctx . channel . id )
u . dump ( u . tasks , ' cogs/tasks.pkl ' )
self . bot . loop . create_task ( self . queue_for_hearts ( channel = ctx . channel ) )
print ( ' STARTED : auto-hearting in # {} ' . format ( ctx . channel . name ) )
await ctx . send ( ' **Auto-hearting all messages in {} ** ' . format ( ctx . channel . mention ) , delete_after = 5 )
else :
raise exc . Exists
except exc . Exists :
2017-12-31 21:28:58 -05:00
await ctx . send ( ' **Already auto-hearting in {} .** Type `stop h(earting)` to stop. ' . format ( ctx . channel . mention ) , delete_after = 7 )
2017-12-31 21:54:37 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-11-20 11:36:34 -05:00
2017-11-20 06:18:42 -05:00
# @cmds.command()
2017-10-28 15:43:51 -04:00
# async def auto_post(self, ctx):
# try:
# if ctx.channel.id not in u.tasks['auto_post']:
# u.tasks['auto_post'].append(ctx.channel.id)
# u.dump(u.tasks, 'cogs/tasks.pkl')
2017-11-19 23:33:45 -05:00
# self.bot.loop.create_task(self.queue_for_posting(ctx.channel))
# if not self.posting:
# self.bot.loop.create_task(self._post())
# self.posting = True
2017-10-28 15:43:51 -04:00
#
2017-11-20 11:28:49 -05:00
# print('STARTED : auto-posting in #{}'.format(ctx.channel.name))
2017-10-28 16:29:17 -04:00
# await ctx.send('**Auto-posting all images in {}**'.format(ctx.channel.mention), delete_after=5)
2017-10-28 15:43:51 -04:00
# else:
# raise exc.Exists
#
# except exc.Exists:
2017-11-19 12:03:49 -05:00
# await ctx.send('**Already auto-posting in {}.** Type `stop` to stop.'.format(ctx.channel.mention), delete_after=7)
2017-11-06 02:00:58 -05:00
# await ctx.message.add_reaction('\N{CROSS MARK}')
2017-10-20 16:12:57 -04:00
2017-12-10 17:14:15 -05:00
@cmds.group ( aliases = [ ' tag ' , ' t ' ] , brief = ' (G) Get info on tags ' , description = ' Group command for obtaining info on tags \n \n Usage: \n \ { p \ }tag \ { flag \ } \ { tag(s) \ } ' )
2017-11-19 23:36:54 -05:00
async def tags ( self , ctx ) :
pass
2017-10-20 16:14:24 -04:00
# Tag search
2017-12-21 22:38:59 -05:00
@tags.command ( name = ' related ' , aliases = [ ' relate ' , ' rel ' , ' r ' ] , brief = ' (tags) Search for related tags ' , description = ' Return related tags for given tag(s) \n \n Example: \n \ { p \ }tag related wolf ' )
2017-11-19 23:36:54 -05:00
async def _tags_related ( self , ctx , * args ) :
2017-10-20 16:14:24 -04:00
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
related = [ ]
2017-11-19 23:36:54 -05:00
c = 0
2017-10-17 19:04:45 -04:00
2017-10-20 16:14:24 -04:00
await dest . trigger_typing ( )
2017-10-17 19:04:45 -04:00
2017-10-20 16:14:24 -04:00
for tag in tags :
2017-11-19 23:36:54 -05:00
try :
tag_request = await u . fetch ( ' https://e621.net/tag/related.json ' , params = { ' tags ' : tag } , json = True )
2017-11-19 11:49:32 -05:00
for rel in tag_request . get ( tag , [ ] ) :
related . append ( rel [ 0 ] )
2017-10-17 19:04:45 -04:00
2017-11-19 23:36:54 -05:00
if related :
2017-11-19 11:49:32 -05:00
await dest . send ( ' ` {} ` **related tags:** \n ``` \n {} ``` ' . format ( tag , formatter . tostring ( related ) ) )
2017-11-19 23:36:54 -05:00
else :
2017-11-19 12:03:49 -05:00
await ctx . send ( f ' **No related tags found for:** ` { tag } ` ' , delete_after = 7 )
2017-10-17 23:32:32 -04:00
2017-11-19 11:49:32 -05:00
related . clear ( )
2017-11-19 23:36:54 -05:00
c + = 1
finally :
await asyncio . sleep ( self . RATE_LIMIT )
2017-10-17 19:04:45 -04:00
2017-11-19 23:36:54 -05:00
if not c :
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-17 19:04:45 -04:00
2017-10-20 16:14:24 -04:00
# Tag aliases
2017-12-21 22:38:59 -05:00
@tags.command ( name = ' aliases ' , aliases = [ ' alias ' , ' als ' , ' a ' ] , brief = ' (tags) Search for tag aliases ' , description = ' Return aliases for given tag(s) \n \n Example: \n \ { p \ }tag alias wolf ' )
2017-11-19 23:36:54 -05:00
async def _tags_aliases ( self , ctx , * args ) :
2017-10-20 16:14:24 -04:00
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
aliases = [ ]
2017-11-19 23:36:54 -05:00
c = 0
2017-10-17 19:04:45 -04:00
2017-10-20 16:14:24 -04:00
await dest . trigger_typing ( )
2017-10-17 19:04:45 -04:00
2017-10-20 16:14:24 -04:00
for tag in tags :
2017-11-19 23:36:54 -05:00
try :
2017-11-19 11:49:32 -05:00
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 :
aliases . append ( dic [ ' name ' ] )
2017-10-17 19:04:45 -04:00
2017-11-19 23:36:54 -05:00
if aliases :
2017-11-19 11:49:32 -05:00
await dest . send ( ' ` {} ` **aliases:** \n ``` \n {} ``` ' . format ( tag , formatter . tostring ( aliases ) ) )
2017-11-19 23:36:54 -05:00
else :
2017-11-19 12:03:49 -05:00
await ctx . send ( f ' **No aliases found for:** ` { tag } ` ' , delete_after = 7 )
2017-10-17 19:04:45 -04:00
2017-11-19 23:36:54 -05:00
aliases . clear ( )
c + = 1
finally :
2017-11-19 11:49:32 -05:00
await asyncio . sleep ( self . RATE_LIMIT )
2017-10-17 23:32:32 -04:00
2017-11-19 23:36:54 -05:00
if not c :
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-12-10 17:14:15 -05:00
@cmds.group ( aliases = [ ' g ' ] , brief = ' (G) Get e621 elements ' , description = ' Group command for obtaining various elements like post info \n \n Usage: \n \ { p \ }get \ { flag \ } \ { args \ } ' )
2017-11-19 23:39:32 -05:00
async def get ( self , ctx ) :
if not ctx . invoked_subcommand :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **Use a flag to get items.** \n *Type* ` {} help get` *for more info.* ' . format ( ctx . prefix ) , delete_after = 7 )
2017-11-19 23:39:32 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-12-10 17:14:15 -05:00
@get.command ( name = ' info ' , aliases = [ ' i ' ] , brief = ' (get) Get info from post ' , description = ' Return info for given post URL or ID \n \n Example: \n \ { p \ }get info 1145042 ' )
2017-11-19 23:39:32 -05:00
async def _get_info ( self , ctx , * args ) :
try :
kwargs = u . get_kwargs ( ctx , args )
dest , posts = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
if not posts :
raise exc . MissingArgument
for ident in posts :
try :
await dest . trigger_typing ( )
2017-11-20 02:16:01 -05:00
ident = ident if not ident . isdigit ( ) else re . search (
' show/([0-9]+) ' , ident ) . group ( 1 )
2017-11-19 23:39:32 -05:00
post = await u . fetch ( ' https://e621.net/post/show.json ' , params = { ' id ' : ident } , json = True )
embed = d . Embed (
title = ' , ' . join ( post [ ' artist ' ] ) , url = f ' https://e621.net/post/show/ { post [ " id " ] } ' , color = ctx . me . color if isinstance ( ctx . channel , d . TextChannel ) else u . color )
embed . set_thumbnail ( url = post [ ' file_url ' ] )
2017-12-31 21:55:04 -05:00
embed . set_author ( name = f ' { post [ " width " ] } x { post [ " height " ] } ' ,
2017-11-19 23:39:32 -05:00
url = f ' https://e621.net/post?tags=ratio: { post [ " width " ] / post [ " height " ] : .2f } ' , icon_url = ctx . author . avatar_url )
2017-11-20 02:18:44 -05:00
embed . set_footer ( text = post [ ' score ' ] ,
2017-11-19 23:39:32 -05:00
icon_url = self . _get_score ( post [ ' score ' ] ) )
2017-10-17 19:04:45 -04:00
2017-11-19 23:39:32 -05:00
# except
2017-10-20 16:14:24 -04:00
2017-11-19 23:39:32 -05:00
finally :
await asyncio . sleep ( self . RATE_LIMIT )
except exc . MissingArgument :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **Invalid url** ' , delete_after = 7 )
2017-11-19 23:39:32 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-12-10 17:14:15 -05:00
@get.command ( name = ' image ' , aliases = [ ' img ' ] , brief = ' (get) Get direct image from post ' , description = ' Return direct image URL for given post \n \n Example: \n \ { p \ }get image 1145042 ' )
2017-11-19 23:39:32 -05:00
async def _get_image ( self , ctx , * args ) :
try :
kwargs = u . get_kwargs ( ctx , args )
dest , urls = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
c = 0
if not urls :
raise exc . MissingArgument
for url in urls :
try :
await dest . trigger_typing ( )
await dest . send ( await scraper . get_image ( url ) )
c + = 1
# except
2017-11-19 12:03:49 -05:00
# await ctx.send(f'**No aliases found for:** `{tag}`', delete_after=7)
2017-11-19 23:39:32 -05:00
finally :
await asyncio . sleep ( self . RATE_LIMIT )
if not c :
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
except exc . MissingArgument :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **Invalid url or file** ' , delete_after = 7 )
2017-11-19 23:39:32 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-12-10 17:14:15 -05:00
@get.command ( name = ' pool ' , aliases = [ ' p ' ] , brief = ' (get) Get pool from query ' , description = ' Return pool info for given query \n \n Example: \n \ { p \ }get pool 1145042 ' )
2017-11-19 23:39:32 -05:00
async def _get_pool ( self , ctx , * args ) :
2017-10-30 00:20:40 -04:00
def on_reaction ( reaction , user ) :
2017-11-06 02:00:58 -05:00
if reaction . emoji == ' \N{OCTAGONAL SIGN} ' and reaction . message . id == ctx . message . id and user is ctx . author :
2017-10-30 00:20:40 -04:00
raise exc . Abort ( match )
2017-10-27 21:07:06 -04:00
return False
2017-10-30 00:20:40 -04:00
def on_message ( msg ) :
return msg . content . isdigit ( ) and int ( msg . content ) < = len ( pools ) and int ( msg . content ) > 0 and msg . author is ctx . author and msg . channel is ctx . channel
2017-10-27 21:07:06 -04:00
try :
kwargs = u . get_kwargs ( ctx , args )
dest , query = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
ident = None
await dest . trigger_typing ( )
pools = [ ]
pool_request = await u . fetch ( ' https://e621.net/pool/index.json ' , params = { ' query ' : ' ' . join ( query ) } , json = True )
if len ( pool_request ) > 1 :
for pool in pool_request :
pools . append ( pool [ ' name ' ] )
2017-10-30 00:23:33 -04:00
match = await ctx . send ( ' **Multiple pools found for ` {} `.** Type the number of the correct match \n ``` \n {} ``` ' . format ( ' ' . join ( query ) , ' \n ' . join ( [ ' {} {} ' . format ( c , elem ) for c , elem in enumerate ( pools , 1 ) ] ) ) )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{OCTAGONAL SIGN} ' )
2017-10-30 00:23:33 -04:00
done , pending = await asyncio . wait ( [ self . bot . wait_for ( ' reaction_add ' , check = on_reaction , timeout = 60 ) ,
self . bot . wait_for ( ' reaction_remove ' , check = on_reaction , timeout = 60 ) , self . bot . wait_for ( ' message ' , check = on_message , timeout = 60 ) ] , return_when = asyncio . FIRST_COMPLETED )
for future in done :
selection = future . result ( )
2017-10-27 21:07:06 -04:00
await match . delete ( )
2017-11-19 23:39:32 -05:00
tempool = [ pool for pool in pool_request if pool [ ' name ' ]
== pools [ int ( selection . content ) - 1 ] ] [ 0 ]
2017-10-27 21:07:06 -04:00
await selection . delete ( )
elif pool_request :
tempool = pool_request [ 0 ]
else :
raise exc . NotFound
2017-10-27 21:23:47 -04:00
await ctx . send ( f ' ** { tempool [ " name " ] } ** \n https://e621.net/pool/show/ { tempool [ " id " ] } ' )
2017-10-27 21:07:06 -04:00
2017-10-30 00:23:33 -04:00
except exc . Abort as e :
2017-11-20 11:38:27 -05:00
await e . message . edit ( content = ' \N{NO ENTRY SIGN} ' , delete_after = 7 )
2017-10-20 16:14:24 -04:00
# Reverse image searches a linked image using the public iqdb
2017-12-10 17:14:15 -05:00
@cmds.command ( name = ' reverse ' , aliases = [ ' rev ' , ' ris ' ] , brief = ' Reverse image search from e621 ' , description = ' NSFW \n Reverse-search an image with given URL ' )
2017-11-19 23:25:30 -05:00
async def reverse ( self , ctx , * args ) :
2017-10-16 02:08:20 -04:00
try :
2017-10-20 16:14:24 -04:00
kwargs = u . get_kwargs ( ctx , args )
dest , urls = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
c = 0
2017-10-16 02:08:20 -04:00
2017-10-20 16:14:24 -04:00
if not urls and not ctx . message . attachments :
raise exc . MissingArgument
2017-10-16 02:08:20 -04:00
2017-10-20 16:14:24 -04:00
for attachment in ctx . message . attachments :
2017-11-19 23:25:30 -05:00
urls . append ( attachment . url )
2017-10-17 17:59:08 -04:00
2017-10-20 16:14:24 -04:00
for url in urls :
try :
await dest . trigger_typing ( )
2017-10-17 17:59:08 -04:00
2017-10-20 16:14:24 -04:00
post = await scraper . get_post ( url )
2017-10-17 17:59:08 -04:00
2017-11-19 23:25:30 -05:00
embed = d . Embed (
title = ' , ' . join ( post [ ' artist ' ] ) , url = f ' https://e621.net/post/show/ { post [ " id " ] } ' , color = ctx . me . color if isinstance ( ctx . channel , d . TextChannel ) else u . color )
embed . set_image ( url = post [ ' file_url ' ] )
2017-12-31 21:55:04 -05:00
embed . set_author ( name = f ' { post [ " width " ] } x { post [ " height " ] } ' ,
2017-11-19 23:25:30 -05:00
url = f ' https://e621.net/post?tags=ratio: { post [ " width " ] / post [ " height " ] : .2f } ' , icon_url = ctx . author . avatar_url )
2017-11-20 02:18:44 -05:00
embed . set_footer ( text = post [ ' score ' ] ,
2017-11-19 23:25:30 -05:00
icon_url = self . _get_score ( post [ ' score ' ] ) )
await dest . send ( ' **Probable match** ' , embed = embed )
2017-10-16 02:08:20 -04:00
2017-10-20 16:14:24 -04:00
c + = 1
2017-10-16 02:08:20 -04:00
2017-10-20 16:14:24 -04:00
except exc . MatchError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **No probable match for:** ` {} ` ' . format ( e ) , delete_after = 7 )
2017-10-17 17:59:08 -04:00
2017-11-19 23:25:30 -05:00
if not c :
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . MissingArgument :
2017-11-20 02:20:30 -05:00
await ctx . send ( ' **Invalid url or file.** Be sure the link directs to an image file ' , delete_after = 7 )
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
except exc . SizeError as e :
await ctx . send ( f ' ` { e } ` **too large.** Maximum is 8 MB ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-16 02:08:20 -04:00
2017-11-20 06:18:42 -05:00
@cmds.command ( name = ' reversify ' , aliases = [ ' revify ' , ' risify ' , ' rify ' ] )
2017-10-20 16:14:24 -04:00
async def reversify ( self , ctx , * args ) :
2017-10-17 19:04:45 -04:00
try :
2017-10-20 16:14:24 -04:00
kwargs = u . get_kwargs ( ctx , args , limit = self . HISTORY_LIMIT / 5 )
dest , remove , limit = kwargs [ ' destination ' ] , kwargs [ ' remove ' ] , kwargs [ ' limit ' ]
2017-10-31 00:32:43 -04:00
links = { }
2017-10-28 16:32:04 -04:00
c = 0
2017-10-16 02:08:20 -04:00
2017-10-20 16:14:24 -04:00
if not ctx . author . permissions_in ( ctx . channel ) . manage_messages :
dest = ctx . author
2017-10-16 03:27:21 -04:00
2017-10-20 16:14:24 -04:00
async for message in ctx . channel . history ( limit = self . HISTORY_LIMIT * limit ) :
2017-10-28 16:32:04 -04:00
if c > = limit :
2017-10-20 16:14:24 -04:00
break
2017-10-28 16:32:04 -04:00
if message . author . id != self . bot . user . id and ( re . search ( ' (https?: \ / \ /[^ ]* \ .(?:gif|png|jpg|jpeg)) ' , message . content ) is not None or message . embeds or message . attachments ) :
2017-10-31 00:32:43 -04:00
links [ message ] = [ ]
2017-10-28 16:32:04 -04:00
for match in re . finditer ( ' (https?: \ / \ /[^ ]* \ .(?:gif|png|jpg|jpeg)) ' , message . content ) :
2017-10-31 00:32:43 -04:00
links [ message ] . append ( match . group ( 0 ) )
2017-10-28 16:32:04 -04:00
for embed in message . embeds :
if embed . image . url is not d . Embed . Empty :
2017-10-31 00:32:43 -04:00
links [ message ] . append ( embed . image . url )
2017-10-28 16:32:04 -04:00
for attachment in message . attachments :
2017-10-31 00:32:43 -04:00
links [ message ] . append ( attachment . url )
2017-10-28 16:32:04 -04:00
2017-11-06 02:00:58 -05:00
await message . add_reaction ( ' \N{HOURGLASS WITH FLOWING SAND} ' )
2017-10-28 16:32:04 -04:00
c + = 1
2017-10-16 02:08:20 -04:00
2017-10-31 00:32:43 -04:00
if not links :
2017-10-28 16:32:04 -04:00
raise exc . NotFound
2017-10-16 02:08:20 -04:00
2017-10-31 00:49:02 -04:00
n = 1
2017-10-31 00:32:43 -04:00
for message , urls in links . items ( ) :
for url in urls :
try :
await dest . trigger_typing ( )
2017-10-16 02:08:20 -04:00
2017-11-20 02:21:35 -05:00
post = await scraper . get_post ( url )
embed = d . Embed (
title = ' , ' . join ( post [ ' artist ' ] ) , url = f ' https://e621.net/post/show/ { post [ " id " ] } ' , color = ctx . me . color if isinstance ( ctx . channel , d . TextChannel ) else u . color )
embed . set_image ( url = post [ ' file_url ' ] )
2017-12-31 21:55:04 -05:00
embed . set_author ( name = f ' { post [ " width " ] } x { post [ " height " ] } ' ,
2017-11-20 02:21:35 -05:00
url = f ' https://e621.net/post?tags=ratio: { post [ " width " ] / post [ " height " ] : .2f } ' , icon_url = ctx . author . avatar_url )
embed . set_footer (
text = post [ ' score ' ] , icon_url = self . _get_score ( post [ ' score ' ] ) )
await dest . send ( f ' **Probable match from** { message . author . display_name } ' , embed = embed )
2017-11-06 02:00:58 -05:00
await message . add_reaction ( ' \N{WHITE HEAVY CHECK MARK} ' )
2017-10-16 02:08:20 -04:00
2017-10-31 00:32:43 -04:00
if remove :
with suppress ( err . NotFound ) :
await message . delete ( )
2017-10-17 19:04:45 -04:00
2017-10-31 00:32:43 -04:00
except exc . MatchError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} / {} ` **No probable match for:** ` {} ` ' . format ( n , len ( links ) , e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-31 00:32:43 -04:00
c - = 1
2017-11-20 02:20:30 -05:00
except exc . SizeError as e :
await ctx . send ( f ' ` { e } ` **too large.** Maximum is 8 MB ' , delete_after = 7 )
await message . add_reaction ( ' \N{CROSS MARK} ' )
c - = 1
2017-10-16 02:08:20 -04:00
2017-10-31 00:49:02 -04:00
finally :
n + = 1
2017-10-16 02:08:20 -04:00
2017-11-19 23:25:30 -05:00
if c < = 0 :
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . NotFound :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **No matches found** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . BoundsError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **invalid limit.** Query limited to 30 ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
2017-11-19 23:25:30 -05:00
async def _reversify ( self ) :
while self . reversifying :
2017-11-20 11:28:49 -05:00
message = await self . reversiqueue . get ( )
2017-10-28 16:32:04 -04:00
urls = [ ]
2017-10-16 03:27:21 -04:00
2017-10-28 16:32:04 -04:00
for match in re . finditer ( ' (https?: \ / \ /[^ ]* \ .(?:gif|png|jpg|jpeg)) ' , message . content ) :
urls . append ( match . group ( 0 ) )
for embed in message . embeds :
if embed . image . url is not d . Embed . Empty :
urls . append ( embed . image . url )
2017-10-20 16:14:24 -04:00
for attachment in message . attachments :
2017-10-28 16:32:04 -04:00
urls . append ( attachment . url )
for url in urls :
2017-10-20 16:14:24 -04:00
try :
await message . channel . trigger_typing ( )
2017-10-16 03:27:21 -04:00
2017-10-28 16:32:04 -04:00
post = await scraper . get_post ( url )
2017-10-16 03:27:21 -04:00
2017-11-20 02:21:35 -05:00
embed = d . Embed (
title = ' , ' . join ( post [ ' artist ' ] ) , url = f ' https://e621.net/post/show/ { post [ " id " ] } ' , color = message . channel . guild . me . color if isinstance ( message . channel , d . TextChannel ) else u . color )
embed . set_image ( url = post [ ' file_url ' ] )
2017-12-31 21:55:04 -05:00
embed . set_author ( name = f ' { post [ " width " ] } x { post [ " height " ] } ' ,
2017-11-20 02:21:35 -05:00
url = f ' https://e621.net/post?tags=ratio: { post [ " width " ] / post [ " height " ] : .2f } ' , icon_url = message . author . avatar_url )
embed . set_footer ( text = post [ ' score ' ] ,
2017-12-31 21:55:23 -05:00
icon_url = self . _get_score ( post [ ' score ' ] ) )
2017-10-16 03:27:21 -04:00
2017-11-20 02:21:35 -05:00
await message . channel . send ( ' **Probable match from** {} ' . format ( message . author . display_name ) , embed = embed )
await message . add_reaction ( ' \N{WHITE HEAVY CHECK MARK} ' )
2017-10-16 03:27:21 -04:00
2017-10-20 16:14:24 -04:00
except exc . MatchError as e :
2017-11-19 12:03:49 -05:00
await message . channel . send ( ' **No probable match for:** ` {} ` ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await message . add_reaction ( ' \N{CROSS MARK} ' )
2017-11-20 02:20:30 -05:00
except exc . SizeError as e :
await message . channel . send ( f ' ` { e } ` **too large.** Maximum is 8 MB ' , delete_after = 7 )
await message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-16 03:27:21 -04:00
2017-11-19 23:25:30 -05:00
finally :
await asyncio . sleep ( self . RATE_LIMIT )
2017-11-20 02:21:35 -05:00
with suppress ( err . NotFound ) :
await message . delete ( )
2017-11-19 23:25:30 -05:00
print ( ' STOPPED : reversifying ' )
2017-10-16 03:27:21 -04:00
2017-11-19 23:25:30 -05:00
async def queue_for_reversification ( self , channel ) :
2017-10-20 16:14:24 -04:00
def check ( msg ) :
2017-12-31 21:28:58 -05:00
if ' stop r ' in msg . content . lower ( ) and msg . channel is channel and msg . author . guild_permissions . administrator :
2017-10-20 16:14:24 -04:00
raise exc . Abort
2017-10-28 16:30:46 -04:00
elif msg . channel is channel and msg . author . id != self . bot . user . id and ( re . search ( ' (https?: \ / \ /[^ ]* \ .(?:gif|png|jpg|jpeg)) ' , msg . content ) is not None or msg . attachments or msg . embeds ) :
2017-10-20 16:14:24 -04:00
return True
return False
2017-10-16 03:27:21 -04:00
2017-10-20 16:14:24 -04:00
try :
2017-11-20 11:28:49 -05:00
while self . reversifying :
2017-10-20 16:14:24 -04:00
message = await self . bot . wait_for ( ' message ' , check = check )
2017-11-20 11:28:49 -05:00
await self . reversiqueue . put ( message )
2017-11-06 02:00:58 -05:00
await message . add_reaction ( ' \N{HOURGLASS WITH FLOWING SAND} ' )
2017-10-20 16:14:24 -04:00
except exc . Abort :
2017-11-20 02:17:48 -05:00
u . tasks [ ' auto_rev ' ] . remove ( channel . id )
2017-10-20 16:14:24 -04:00
u . dump ( u . tasks , ' cogs/tasks.pkl ' )
2017-11-20 02:17:48 -05:00
if not u . tasks [ ' auto_rev ' ] :
2017-11-19 23:25:30 -05:00
self . reversifying = False
print ( ' STOPPED : reversifying # {} ' . format ( channel . name ) )
await channel . send ( ' **Stopped queueing messages for reversification in** {} ' . format ( channel . mention ) , delete_after = 5 )
2017-10-20 16:14:24 -04:00
2017-11-20 06:18:42 -05:00
@cmds.command ( name = ' autoreversify ' , aliases = [ ' autorev ' ] )
@cmds.has_permissions ( manage_channels = True )
2017-11-19 23:25:30 -05:00
async def auto_reversify ( self , ctx ) :
2017-11-20 02:17:48 -05:00
if ctx . channel . id not in u . tasks [ ' auto_rev ' ] :
u . tasks [ ' auto_rev ' ] . append ( ctx . channel . id )
2017-11-19 11:49:32 -05:00
u . dump ( u . tasks , ' cogs/tasks.pkl ' )
2017-11-19 23:25:30 -05:00
self . bot . loop . create_task (
self . queue_for_reversification ( ctx . channel ) )
if not self . reversifying :
self . bot . loop . create_task ( self . _reversify ( ) )
self . reversifying = True
2017-10-20 16:14:24 -04:00
2017-11-20 11:28:49 -05:00
print ( ' STARTED : auto-reversifying in # {} ' . format ( ctx . channel . name ) )
2017-11-19 23:25:30 -05:00
await ctx . send ( ' **Auto-reversifying all images in** {} ' . format ( ctx . channel . mention ) , delete_after = 5 )
2017-11-19 11:49:32 -05:00
else :
2017-12-31 21:28:58 -05:00
await ctx . send ( ' **Already auto-reversifying in {} .** Type `stop r(eversifying)` to stop. ' . format ( ctx . channel . mention ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
2017-10-29 17:55:40 -04:00
async def _get_pool ( self , ctx , * , destination , booru = ' e621 ' , query = [ ] ) :
2017-10-30 00:23:33 -04:00
def on_reaction ( reaction , user ) :
2017-11-06 02:00:58 -05:00
if reaction . emoji == ' \N{OCTAGONAL SIGN} ' and reaction . message . id == ctx . message . id and user is ctx . author :
2017-10-30 00:23:33 -04:00
raise exc . Abort ( match )
2017-10-20 16:14:24 -04:00
return False
2017-10-30 00:23:33 -04:00
def on_message ( msg ) :
return msg . content . isdigit ( ) and int ( msg . content ) < = len ( pools ) and int ( msg . content ) > 0 and msg . author is ctx . author and msg . channel is ctx . channel
2017-10-20 16:14:24 -04:00
posts = { }
pool = { }
2017-10-30 00:23:33 -04:00
try :
pools = [ ]
pool_request = await u . fetch ( ' https:// {} .net/pool/index.json ' . format ( booru ) , params = { ' query ' : ' ' . join ( query ) } , json = True )
if len ( pool_request ) > 1 :
for pool in pool_request :
pools . append ( pool [ ' name ' ] )
match = await ctx . send ( ' **Multiple pools found for ` {} `.** Type the number of the correct match. \n ``` \n {} ``` ' . format ( ' ' . join ( query ) , ' \n ' . join ( [ ' {} {} ' . format ( c , elem ) for c , elem in enumerate ( pools , 1 ) ] ) ) )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{OCTAGONAL SIGN} ' )
2017-10-30 00:23:33 -04:00
done , pending = await asyncio . wait ( [ self . bot . wait_for ( ' reaction_add ' , check = on_reaction , timeout = 60 ) ,
self . bot . wait_for ( ' reaction_remove ' , check = on_reaction , timeout = 60 ) , self . bot . wait_for ( ' message ' , check = on_message , timeout = 60 ) ] , return_when = asyncio . FIRST_COMPLETED )
for future in done :
selection = future . result ( )
await match . delete ( )
tempool = [ pool for pool in pool_request if pool [ ' name ' ]
== pools [ int ( selection . content ) - 1 ] ] [ 0 ]
await selection . delete ( )
pool = { ' name ' : tempool [ ' name ' ] , ' id ' : tempool [ ' id ' ] }
await destination . trigger_typing ( )
elif pool_request :
tempool = pool_request [ 0 ]
2017-11-19 23:39:32 -05:00
pool = { ' name ' : pool_request [ 0 ]
[ ' name ' ] , ' id ' : pool_request [ 0 ] [ ' id ' ] }
2017-10-30 00:23:33 -04:00
else :
raise exc . NotFound
page = 1
while len ( posts ) < tempool [ ' post_count ' ] :
posts_request = await u . fetch ( ' https:// {} .net/pool/show.json ' . format ( booru ) , params = { ' id ' : tempool [ ' id ' ] , ' page ' : page } , json = True )
for post in posts_request [ ' posts ' ] :
2017-11-19 23:39:32 -05:00
posts [ post [ ' id ' ] ] = { ' artist ' : ' , ' . join (
2017-11-21 06:11:09 -05:00
post [ ' artist ' ] ) , ' file_url ' : post [ ' file_url ' ] , ' score ' : post [ ' score ' ] }
2017-10-30 00:23:33 -04:00
page + = 1
return pool , posts
except exc . Abort as e :
2017-11-20 11:38:27 -05:00
await e . message . edit ( content = ' \N{NO ENTRY SIGN} ' )
2017-10-30 00:23:33 -04:00
raise exc . Continue
2017-10-20 16:14:24 -04:00
# Messy code that checks image limit and tags in blacklists
2017-10-21 16:45:26 -04:00
async def _get_posts ( self , ctx , * , booru = ' e621 ' , tags = [ ] , limit = 1 , previous = { } ) :
2017-10-20 16:14:24 -04:00
guild = ctx . guild if isinstance (
ctx . guild , d . Guild ) else ctx . channel
blacklist = set ( )
# Creates temp blacklist based on context
2017-11-08 23:48:12 -05:00
for bl in ( self . blacklists [ ' global_blacklist ' ] , self . blacklists [ ' guild_blacklist ' ] . get ( guild . id , { } ) . get ( ctx . channel . id , set ( ) ) , self . blacklists [ ' user_blacklist ' ] . get ( ctx . author . id , set ( ) ) ) :
for tag in bl :
blacklist . update ( [ tag ] + list ( self . aliases [ tag ] ) )
2017-10-31 16:13:39 -04:00
# Checks for, assigns, and removes first order in tags if possible
order = [ tag for tag in tags if ' order: ' in tag ]
if order :
order = order [ 0 ]
tags . remove ( order )
else :
order = ' order:random '
2017-10-20 16:14:24 -04:00
# Checks if tags are in local blacklists
if tags :
if ( len ( tags ) > 5 and booru == ' e621 ' ) or ( len ( tags ) > 4 and booru == ' e926 ' ) :
raise exc . TagBoundsError ( formatter . tostring ( tags [ 5 : ] ) )
for tag in tags :
if tag == ' swf ' or tag == ' webm ' or tag in blacklist :
raise exc . TagBlacklisted ( tag )
# Checks for blacklisted tags in endpoint blacklists - try/except is for continuing the parent loop
posts = { }
2017-10-21 16:45:26 -04:00
temposts = len ( posts )
empty = 0
2017-10-20 16:14:24 -04:00
c = 0
while len ( posts ) < limit :
2017-10-31 16:20:19 -04:00
if c == limit * 5 + ( self . LIMIT / 5 ) :
2017-10-20 16:14:24 -04:00
raise exc . Timeout
2017-10-30 23:35:40 -04:00
request = await u . fetch ( ' https:// {} .net/post/index.json ' . format ( booru ) , params = { ' tags ' : ' , ' . join ( [ order ] + tags ) , ' limit ' : int ( self . LIMIT * limit ) } , json = True )
2017-10-20 16:14:24 -04:00
if len ( request ) == 0 :
raise exc . NotFound ( formatter . tostring ( tags ) )
if len ( request ) < limit :
limit = len ( request )
for post in request :
if ' swf ' in post [ ' file_ext ' ] or ' webm ' in post [ ' file_ext ' ] :
continue
try :
for tag in blacklist :
if tag in post [ ' tags ' ] :
raise exc . Continue
except exc . Continue :
continue
if post [ ' id ' ] not in posts . keys ( ) and post [ ' id ' ] not in previous . keys ( ) :
2017-10-30 23:32:55 -04:00
posts [ post [ ' id ' ] ] = { ' artist ' : ' , ' . join (
2017-11-20 11:39:08 -05:00
post [ ' artist ' ] ) , ' file_url ' : post [ ' file_url ' ] , ' score ' : post [ ' score ' ] }
2017-10-20 16:14:24 -04:00
if len ( posts ) == limit :
break
2017-10-21 16:45:26 -04:00
if len ( posts ) == temposts :
empty + = 1
if empty == 5 :
break
else :
empty = 0
temposts = len ( posts )
2017-10-21 16:44:05 -04:00
c + = 1
2017-10-20 16:14:24 -04:00
2017-10-21 16:45:26 -04:00
if posts :
2017-10-30 23:35:40 -04:00
return posts , order
2017-10-21 16:45:26 -04:00
else :
2017-11-08 23:48:46 -05:00
raise exc . NotFound ( formatter . tostring ( tags ) )
2017-10-20 16:14:24 -04:00
2017-10-29 17:56:38 -04:00
# Creates reaction-based paginator for linked pools
2017-11-20 06:18:42 -05:00
@cmds.command ( name = ' poolpage ' , aliases = [ ' poolp ' , ' pp ' , ' e621pp ' , ' e6pp ' , ' 6pp ' ] , brief = ' e621 pool paginator ' , description = ' e621 | NSFW \n Show pools in a page format ' )
2017-10-29 17:56:38 -04:00
async def pool_paginator ( self , ctx , * args ) :
2017-10-20 16:14:24 -04:00
def on_reaction ( reaction , user ) :
2017-11-08 22:36:06 -05:00
if reaction . emoji == ' \N{OCTAGONAL SIGN} ' and reaction . message . id == ctx . message . id and ( user is ctx . author or user . permissions_in ( reaction . message . channel ) . manage_messages ) :
2017-10-20 16:14:24 -04:00
raise exc . Abort
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{HEAVY BLACK HEART} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-20 16:14:24 -04:00
raise exc . Save
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{LEFTWARDS BLACK ARROW} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-21 16:45:26 -04:00
raise exc . Left
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{NUMBER SIGN} \N{COMBINING ENCLOSING KEYCAP} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-21 16:45:26 -04:00
raise exc . GoTo
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{BLACK RIGHTWARDS ARROW} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-20 16:14:24 -04:00
raise exc . Right
return False
def on_message ( msg ) :
2017-11-21 06:12:30 -05:00
return msg . content . isdigit ( ) and 0 < = int ( msg . content ) < = len ( posts ) and msg . author is ctx . author and msg . channel is ctx . channel
2017-10-20 16:14:24 -04:00
try :
2017-10-29 17:56:38 -04:00
kwargs = u . get_kwargs ( ctx , args )
dest , query = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
2017-11-20 08:48:44 -05:00
hearted = { }
2017-10-29 17:56:38 -04:00
c = 1
2017-10-20 16:14:24 -04:00
2017-10-29 17:56:38 -04:00
await dest . trigger_typing ( )
pool , posts = await self . _get_pool ( ctx , destination = dest , booru = ' e621 ' , query = query )
keys = list ( posts . keys ( ) )
values = list ( posts . values ( ) )
embed = d . Embed (
2017-11-06 02:00:58 -05:00
title = values [ c - 1 ] [ ' artist ' ] , url = ' https://e621.net/post/show/ {} ' . format ( keys [ c - 1 ] ) , color = dest . me . color if isinstance ( dest . channel , d . TextChannel ) else u . color )
2017-11-20 11:39:08 -05:00
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-29 17:56:38 -04:00
embed . set_author ( name = pool [ ' name ' ] ,
url = ' https://e621.net/pool/show?id= {} ' . format ( pool [ ' id ' ] ) , icon_url = ctx . author . avatar_url )
2017-10-31 15:10:36 -04:00
embed . set_footer ( text = ' {} / {} ' . format ( c , len ( posts ) ) ,
2017-10-30 23:32:55 -04:00
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
2017-10-20 16:14:24 -04:00
2017-10-29 17:56:38 -04:00
paginator = await dest . send ( embed = embed )
2017-10-20 16:14:24 -04:00
2017-11-06 02:00:58 -05:00
for emoji in ( ' \N{HEAVY BLACK HEART} ' , ' \N{LEFTWARDS BLACK ARROW} ' , ' \N{NUMBER SIGN} \N{COMBINING ENCLOSING KEYCAP} ' , ' \N{BLACK RIGHTWARDS ARROW} ' ) :
2017-10-29 17:56:38 -04:00
await paginator . add_reaction ( emoji )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{OCTAGONAL SIGN} ' )
2017-10-29 17:56:38 -04:00
await asyncio . sleep ( 1 )
2017-10-20 16:14:24 -04:00
2017-10-29 17:56:38 -04:00
while not self . bot . is_closed ( ) :
try :
2017-11-08 23:49:12 -05:00
await asyncio . gather ( * [ self . bot . wait_for ( ' reaction_add ' , check = on_reaction , timeout = 7 * 60 ) ,
self . bot . wait_for ( ' reaction_remove ' , check = on_reaction , timeout = 7 * 60 ) ] )
2017-10-20 16:14:24 -04:00
2017-10-29 17:56:38 -04:00
except exc . Save :
2017-11-21 06:14:12 -05:00
if keys [ c - 1 ] not in hearted :
hearted [ keys [ c - 1 ] ] = copy . deepcopy ( embed )
2017-10-20 16:14:24 -04:00
2017-11-06 02:00:58 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' )
2017-10-29 17:56:38 -04:00
else :
2017-11-21 06:14:12 -05:00
del hearted [ keys [ c - 1 ] ]
2017-10-20 16:14:24 -04:00
2017-11-06 02:00:58 -05:00
await paginator . edit ( content = ' \N{BROKEN HEART} ' )
2017-10-29 17:56:38 -04:00
except exc . Left :
if c > 1 :
c - = 1
2017-10-29 18:09:48 -04:00
embed . title = values [ c - 1 ] [ ' artist ' ]
2017-11-19 23:41:01 -05:00
embed . url = ' https://e621.net/post/show/ {} ' . format (
keys [ c - 1 ] )
2017-10-31 15:10:36 -04:00
embed . set_footer ( text = ' {} / {} ' . format ( c , len ( posts ) ) ,
2017-10-30 23:32:55 -04:00
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
2017-11-20 11:39:08 -05:00
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-21 16:45:26 -04:00
2017-11-20 08:48:44 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' if keys [ c - 1 ] in hearted . keys ( ) else None , embed = embed )
2017-10-29 17:56:38 -04:00
else :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{BLACK RIGHTWARDS ARROW} ' )
2017-10-29 17:56:38 -04:00
except exc . GoTo :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{INPUT SYMBOL FOR NUMBERS} ' )
2017-11-08 23:49:12 -05:00
number = await self . bot . wait_for ( ' message ' , check = on_message , timeout = 7 * 60 )
2017-10-29 17:56:38 -04:00
2017-11-21 06:12:30 -05:00
if int ( number . content ) != 0 :
c = int ( number . content )
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 = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-29 17:56:38 -04:00
await number . delete ( )
2017-11-20 08:48:44 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' if keys [ c - 1 ] in hearted . keys ( ) else None , embed = embed )
2017-10-29 17:56:38 -04:00
except exc . Right :
if c < len ( keys ) :
c + = 1
2017-10-29 18:09:48 -04:00
embed . title = values [ c - 1 ] [ ' artist ' ]
2017-11-19 23:41:01 -05:00
embed . url = ' https://e621.net/post/show/ {} ' . format (
keys [ c - 1 ] )
2017-10-31 15:10:36 -04:00
embed . set_footer ( text = ' {} / {} ' . format ( c , len ( posts ) ) ,
2017-10-30 23:32:55 -04:00
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
2017-11-20 11:39:08 -05:00
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-20 16:14:24 -04:00
2017-11-20 08:48:44 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' if keys [ c - 1 ] in hearted . keys ( ) else None , embed = embed )
2017-10-29 17:56:38 -04:00
else :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{LEFTWARDS BLACK ARROW} ' )
2017-10-27 21:08:52 -04:00
except exc . Abort :
try :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{WHITE HEAVY CHECK MARK} ' )
2017-10-27 21:08:52 -04:00
except UnboundLocalError :
2017-11-20 11:38:27 -05:00
await dest . send ( ' \N{WHITE HEAVY CHECK MARK} ' )
2017-10-27 21:08:52 -04:00
except asyncio . TimeoutError :
try :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{HOURGLASS} ' )
2017-10-27 21:08:52 -04:00
except UnboundLocalError :
2017-11-20 11:38:27 -05:00
await dest . send ( ' \N{HOURGLASS} ' )
2017-10-27 21:08:52 -04:00
except exc . NotFound :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **Pool not found** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-27 21:08:52 -04:00
except exc . Timeout :
2017-10-28 16:28:16 -04:00
await ctx . send ( ' **Request timed out** ' )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-30 00:20:40 -04:00
except exc . Continue :
pass
2017-10-27 21:08:52 -04:00
finally :
if hearted :
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{HOURGLASS WITH FLOWING SAND} ' )
2017-10-27 21:08:52 -04:00
2017-11-20 08:48:44 -05:00
n = 1
for embed in hearted . values ( ) :
2017-10-27 21:08:52 -04:00
await asyncio . sleep ( self . RATE_LIMIT )
2017-11-21 06:15:25 -05:00
await ctx . author . send ( content = f ' ` { n } / { len ( hearted ) } ` ' , embed = embed )
2017-11-20 08:48:44 -05:00
n + = 1
2017-10-27 21:08:52 -04:00
2017-11-20 06:18:42 -05:00
@cmds.command ( name = ' e621page ' , aliases = [ ' e621p ' , ' e6p ' , ' 6p ' ] )
2017-10-27 21:08:52 -04:00
@checks.is_nsfw ( )
async def e621_paginator ( self , ctx , * args ) :
2017-10-29 17:56:38 -04:00
def on_reaction ( reaction , user ) :
2017-11-08 22:36:06 -05:00
if reaction . emoji == ' \N{OCTAGONAL SIGN} ' and reaction . message . id == ctx . message . id and ( user is ctx . author or user . permissions_in ( reaction . message . channel ) . manage_messages ) :
2017-10-29 17:56:38 -04:00
raise exc . Abort
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{HEAVY BLACK HEART} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-29 17:56:38 -04:00
raise exc . Save
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{LEFTWARDS BLACK ARROW} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-29 17:56:38 -04:00
raise exc . Left
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{NUMBER SIGN} \N{COMBINING ENCLOSING KEYCAP} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-29 17:56:38 -04:00
raise exc . GoTo
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{BLACK RIGHTWARDS ARROW} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-29 17:56:38 -04:00
raise exc . Right
return False
def on_message ( msg ) :
2017-11-21 06:12:30 -05:00
return msg . content . isdigit ( ) and 0 < = int ( msg . content ) < = len ( posts ) and msg . author is ctx . author and msg . channel is ctx . channel
2017-10-29 17:56:38 -04:00
2017-10-27 21:08:52 -04:00
try :
2017-10-29 17:56:38 -04:00
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
limit = self . LIMIT / 5
2017-11-20 08:48:44 -05:00
hearted = { }
2017-10-29 17:56:38 -04:00
c = 1
tags = self . _get_favorites ( ctx , tags )
await ctx . trigger_typing ( )
2017-10-30 23:35:40 -04:00
posts , order = await self . _get_posts ( ctx , booru = ' e621 ' , tags = tags , limit = limit )
2017-10-29 17:56:38 -04:00
keys = list ( posts . keys ( ) )
values = list ( posts . values ( ) )
embed = d . Embed (
2017-11-06 02:00:58 -05:00
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 u . color )
2017-11-20 11:39:08 -05:00
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-30 23:35:40 -04:00
embed . set_author ( name = formatter . tostring ( tags , order = order ) ,
2017-10-29 17:56:38 -04:00
url = ' https://e621.net/post?tags= {} ' . format ( ' , ' . join ( tags ) ) , icon_url = ctx . author . avatar_url )
2017-11-21 06:15:25 -05:00
embed . set_footer ( text = values [ c - 1 ] [ ' score ' ] ,
2017-10-30 23:32:55 -04:00
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
2017-10-29 17:56:38 -04:00
paginator = await dest . send ( embed = embed )
2017-11-06 02:00:58 -05:00
for emoji in ( ' \N{HEAVY BLACK HEART} ' , ' \N{LEFTWARDS BLACK ARROW} ' , ' \N{NUMBER SIGN} \N{COMBINING ENCLOSING KEYCAP} ' , ' \N{BLACK RIGHTWARDS ARROW} ' ) :
2017-10-29 17:56:38 -04:00
await paginator . add_reaction ( emoji )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{OCTAGONAL SIGN} ' )
2017-10-29 17:56:38 -04:00
await asyncio . sleep ( 1 )
while not self . bot . is_closed ( ) :
try :
2017-11-08 23:49:12 -05:00
await asyncio . gather ( * [ self . bot . wait_for ( ' reaction_add ' , check = on_reaction , timeout = 7 * 60 ) ,
self . bot . wait_for ( ' reaction_remove ' , check = on_reaction , timeout = 7 * 60 ) ] )
2017-10-29 17:56:38 -04:00
except exc . Save :
2017-11-21 06:14:12 -05:00
if keys [ c - 1 ] not in hearted . keys ( ) :
hearted [ keys [ c - 1 ] ] = copy . deepcopy ( embed )
2017-10-29 17:56:38 -04:00
2017-11-06 02:00:58 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' )
2017-10-29 17:56:38 -04:00
else :
2017-11-20 08:48:44 -05:00
del hearted [ keys [ c - 1 ] ]
2017-10-29 17:56:38 -04:00
2017-11-06 02:00:58 -05:00
await paginator . edit ( content = ' \N{BROKEN HEART} ' )
2017-10-29 17:56:38 -04:00
except exc . Left :
if c > 1 :
c - = 1
2017-10-29 18:09:48 -04:00
embed . title = values [ c - 1 ] [ ' artist ' ]
2017-11-19 23:41:01 -05:00
embed . url = ' https://e621.net/post/show/ {} ' . format (
keys [ c - 1 ] )
2017-11-21 06:15:25 -05:00
embed . set_footer ( text = values [ c - 1 ] [ ' score ' ] ,
2017-10-30 23:32:55 -04:00
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
2017-11-20 11:39:08 -05:00
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-29 17:56:38 -04:00
2017-11-20 08:48:44 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' if keys [ c - 1 ] in hearted . keys ( ) else None , embed = embed )
2017-10-29 17:56:38 -04:00
else :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{BLACK RIGHTWARDS ARROW} ' )
2017-10-29 17:56:38 -04:00
except exc . GoTo :
2017-11-21 06:12:30 -05:00
await paginator . edit ( content = f ' ` { c } / { len ( posts ) } ` ' )
2017-11-28 18:34:26 -05:00
number = await self . bot . wait_for ( ' message ' , check = on_message , timeout = 7 * 60 )
2017-11-21 06:12:30 -05:00
if int ( number . content ) != 0 :
c = int ( number . content )
embed . title = values [ c - 1 ] [ ' artist ' ]
embed . url = ' https://e621.net/post/show/ {} ' . format (
keys [ c - 1 ] )
embed . set_footer ( text = values [ c - 1 ] [ ' score ' ] ,
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-29 17:56:38 -04:00
await number . delete ( )
2017-11-20 08:48:44 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' if keys [ c - 1 ] in hearted . keys ( ) else None , embed = embed )
2017-10-29 17:56:38 -04:00
except exc . Right :
try :
if c % limit == 0 :
await dest . trigger_typing ( )
2017-11-08 22:37:04 -05:00
temposts , order = await self . _get_posts ( ctx , booru = ' e621 ' , tags = tags , limit = limit , previous = posts )
posts . update ( temposts )
2017-10-29 17:56:38 -04:00
keys = list ( posts . keys ( ) )
values = list ( posts . values ( ) )
2017-11-06 23:49:10 -05:00
if c < len ( keys ) :
c + = 1
embed . title = values [ c - 1 ] [ ' artist ' ]
2017-11-19 23:41:01 -05:00
embed . url = ' https://e621.net/post/show/ {} ' . format (
keys [ c - 1 ] )
2017-11-21 06:15:25 -05:00
embed . set_footer ( text = values [ c - 1 ] [ ' score ' ] ,
2017-11-06 23:49:10 -05:00
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
2017-11-20 11:39:08 -05:00
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-11-06 23:49:10 -05:00
2017-11-20 08:48:44 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' if keys [ c - 1 ] in hearted . keys ( ) else None , embed = embed )
2017-11-06 23:49:10 -05:00
else :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{LEFTWARDS BLACK ARROW} ' )
2017-10-29 17:56:38 -04:00
except exc . NotFound :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{LEFTWARDS BLACK ARROW} ' )
2017-10-20 16:14:24 -04:00
except exc . Abort :
try :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{WHITE HEAVY CHECK MARK} ' )
2017-10-20 16:14:24 -04:00
except UnboundLocalError :
2017-11-20 11:38:27 -05:00
await dest . send ( ' \N{HOURGLASS} ' )
2017-10-20 16:14:24 -04:00
except asyncio . TimeoutError :
try :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{HOURGLASS} ' )
2017-10-20 16:14:24 -04:00
except UnboundLocalError :
2017-11-20 11:38:27 -05:00
await dest . send ( ' \N{HOURGLASS} ' )
2017-10-20 16:14:24 -04:00
except exc . NotFound as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **not found** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . TagBlacklisted as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' \N{NO ENTRY SIGN} ` {} ` **blacklisted** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{NO ENTRY SIGN} ' )
2017-10-20 16:14:24 -04:00
except exc . TagBoundsError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **out of bounds.** Tags limited to 5. ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . FavoritesNotFound :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **You have no favorite tags** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . Timeout :
2017-10-28 16:28:16 -04:00
await ctx . send ( ' **Request timed out** ' )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-17 19:04:45 -04:00
2017-10-20 16:14:24 -04:00
finally :
2017-10-21 16:45:26 -04:00
if hearted :
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{HOURGLASS WITH FLOWING SAND} ' )
2017-10-20 16:14:24 -04:00
2017-11-20 08:48:44 -05:00
n = 1
for embed in hearted . values ( ) :
2017-10-21 16:45:26 -04:00
await asyncio . sleep ( self . RATE_LIMIT )
2017-11-21 06:15:25 -05:00
await ctx . author . send ( content = f ' ` { n } / { len ( hearted ) } ` ' , embed = embed )
2017-11-20 08:48:44 -05:00
n + = 1
2017-10-20 16:14:24 -04:00
2017-11-08 22:37:45 -05:00
# @e621_paginator.error
# async def e621_paginator_error(self, ctx, error):
# if isinstance(error, exc.NSFW):
2017-11-19 12:03:49 -05:00
# await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel**'.format(ctx.channel.mention), delete_after=7)
2017-11-08 22:37:45 -05:00
# await ctx.message.add_reaction('\N{NO ENTRY}')
2017-10-20 16:14:24 -04:00
2017-11-20 06:18:42 -05:00
@cmds.command ( name = ' e926page ' , aliases = [ ' e926p ' , ' e9p ' , ' 9p ' ] )
2017-10-31 14:21:42 -04:00
async def e926_paginator ( self , ctx , * args ) :
def on_reaction ( reaction , user ) :
2017-11-08 22:36:06 -05:00
if reaction . emoji == ' \N{OCTAGONAL SIGN} ' and reaction . message . id == ctx . message . id and ( user is ctx . author or user . permissions_in ( reaction . message . channel ) . manage_messages ) :
2017-10-31 14:21:42 -04:00
raise exc . Abort
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{HEAVY BLACK HEART} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-31 14:21:42 -04:00
raise exc . Save
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{LEFTWARDS BLACK ARROW} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-31 14:21:42 -04:00
raise exc . Left
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{NUMBER SIGN} \N{COMBINING ENCLOSING KEYCAP} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-31 14:21:42 -04:00
raise exc . GoTo
2017-11-06 02:00:58 -05:00
elif reaction . emoji == ' \N{BLACK RIGHTWARDS ARROW} ' and reaction . message . id == paginator . id and user is ctx . author :
2017-10-31 14:21:42 -04:00
raise exc . Right
return False
def on_message ( msg ) :
2017-11-21 06:12:30 -05:00
return msg . content . isdigit ( ) and 0 < = int ( msg . content ) < = len ( posts ) and msg . author is ctx . author and msg . channel is ctx . channel
2017-10-31 14:21:42 -04:00
try :
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
limit = self . LIMIT / 5
2017-11-20 08:48:44 -05:00
hearted = { }
2017-10-31 14:21:42 -04:00
c = 1
tags = self . _get_favorites ( ctx , tags )
await ctx . trigger_typing ( )
posts , order = await self . _get_posts ( ctx , booru = ' e926 ' , tags = tags , limit = limit )
keys = list ( posts . keys ( ) )
values = list ( posts . values ( ) )
embed = d . Embed (
2017-11-06 02:00:58 -05:00
title = values [ c - 1 ] [ ' artist ' ] , url = ' https://e926.net/post/show/ {} ' . format ( keys [ c - 1 ] ) , color = ctx . me . color if isinstance ( ctx . channel , d . TextChannel ) else u . color )
2017-11-20 11:39:08 -05:00
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-31 14:21:42 -04:00
embed . set_author ( name = formatter . tostring ( tags , order = order ) ,
url = ' https://e926.net/post?tags= {} ' . format ( ' , ' . join ( tags ) ) , icon_url = ctx . author . avatar_url )
2017-11-21 06:15:25 -05:00
embed . set_footer ( text = values [ c - 1 ] [ ' score ' ] ,
2017-10-31 14:21:42 -04:00
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
paginator = await dest . send ( embed = embed )
2017-11-06 02:00:58 -05:00
for emoji in ( ' \N{HEAVY BLACK HEART} ' , ' \N{LEFTWARDS BLACK ARROW} ' , ' \N{NUMBER SIGN} \N{COMBINING ENCLOSING KEYCAP} ' , ' \N{BLACK RIGHTWARDS ARROW} ' ) :
2017-10-31 14:21:42 -04:00
await paginator . add_reaction ( emoji )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{OCTAGONAL SIGN} ' )
2017-10-31 14:21:42 -04:00
await asyncio . sleep ( 1 )
while not self . bot . is_closed ( ) :
try :
2017-11-08 23:49:12 -05:00
await asyncio . gather ( * [ self . bot . wait_for ( ' reaction_add ' , check = on_reaction , timeout = 7 * 60 ) ,
self . bot . wait_for ( ' reaction_remove ' , check = on_reaction , timeout = 7 * 60 ) ] )
2017-10-31 14:21:42 -04:00
except exc . Save :
2017-11-21 06:14:12 -05:00
if keys [ c - 1 ] not in hearted :
hearted [ keys [ c - 1 ] ] = copy . deepcopy ( embed )
2017-10-31 14:21:42 -04:00
2017-11-06 02:00:58 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' )
2017-10-31 14:21:42 -04:00
else :
2017-11-21 06:14:12 -05:00
del hearted [ keys [ c - 1 ] ]
2017-10-31 14:21:42 -04:00
2017-11-06 02:00:58 -05:00
await paginator . edit ( content = ' \N{BROKEN HEART} ' )
2017-10-31 14:21:42 -04:00
except exc . Left :
if c > 1 :
c - = 1
embed . title = values [ c - 1 ] [ ' artist ' ]
2017-11-19 23:41:01 -05:00
embed . url = ' https://e926.net/post/show/ {} ' . format (
keys [ c - 1 ] )
2017-11-21 06:15:25 -05:00
embed . set_footer ( text = values [ c - 1 ] [ ' score ' ] ,
2017-10-31 14:21:42 -04:00
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
2017-11-20 11:39:08 -05:00
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-31 14:21:42 -04:00
2017-11-20 08:48:44 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' if keys [ c - 1 ] in hearted . keys ( ) else None , embed = embed )
2017-10-31 14:21:42 -04:00
else :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{BLACK RIGHTWARDS ARROW} ' )
2017-10-31 14:21:42 -04:00
except exc . GoTo :
2017-11-21 06:12:30 -05:00
await paginator . edit ( content = f ' ` { c } / { len ( posts ) } ` ' )
2017-11-08 23:49:12 -05:00
number = await self . bot . wait_for ( ' message ' , check = on_message , timeout = 7 * 60 )
2017-10-31 14:21:42 -04:00
2017-11-21 06:12:30 -05:00
if int ( number . content ) != 0 :
c = int ( number . content )
embed . title = values [ c - 1 ] [ ' artist ' ]
embed . url = ' https://e926.net/post/show/ {} ' . format (
keys [ c - 1 ] )
embed . set_footer ( text = values [ c - 1 ] [ ' score ' ] ,
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-31 14:21:42 -04:00
await number . delete ( )
2017-11-20 08:48:44 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' if keys [ c - 1 ] in hearted . keys ( ) else None , embed = embed )
2017-10-31 14:21:42 -04:00
except exc . Right :
try :
if c % limit == 0 :
await dest . trigger_typing ( )
2017-11-08 22:37:04 -05:00
temposts , order = await self . _get_posts ( ctx , booru = ' e926 ' , tags = tags , limit = limit , previous = posts )
posts . update ( temposts )
2017-10-31 14:21:42 -04:00
keys = list ( posts . keys ( ) )
values = list ( posts . values ( ) )
2017-11-06 23:49:10 -05:00
if c < len ( keys ) :
c + = 1
embed . title = values [ c - 1 ] [ ' artist ' ]
2017-11-19 23:41:01 -05:00
embed . url = ' https://e926.net/post/show/ {} ' . format (
keys [ c - 1 ] )
2017-11-21 06:15:25 -05:00
embed . set_footer ( text = values [ c - 1 ] [ ' score ' ] ,
2017-11-06 23:49:10 -05:00
icon_url = self . _get_score ( values [ c - 1 ] [ ' score ' ] ) )
2017-11-20 11:39:08 -05:00
embed . set_image ( url = values [ c - 1 ] [ ' file_url ' ] )
2017-10-31 14:21:42 -04:00
2017-11-20 08:48:44 -05:00
await paginator . edit ( content = ' \N{HEAVY BLACK HEART} ' if keys [ c - 1 ] in hearted . keys ( ) else None , embed = embed )
2017-11-06 23:49:10 -05:00
else :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{LEFTWARDS BLACK ARROW} ' )
2017-10-31 14:21:42 -04:00
except exc . NotFound :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{LEFTWARDS BLACK ARROW} ' )
2017-10-31 14:21:42 -04:00
except exc . Abort :
try :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{WHITE HEAVY CHECK MARK} ' )
2017-10-31 14:21:42 -04:00
except UnboundLocalError :
2017-11-20 11:38:27 -05:00
await dest . send ( ' \N{WHITE HEAVY CHECK MARK} ' )
2017-10-31 14:21:42 -04:00
except asyncio . TimeoutError :
try :
2017-11-20 11:38:27 -05:00
await paginator . edit ( content = ' \N{HOURGLASS} ' )
2017-10-31 14:21:42 -04:00
except UnboundLocalError :
2017-11-20 11:38:27 -05:00
await dest . send ( ' \N{HOURGLASS} ' )
2017-10-31 14:21:42 -04:00
except exc . NotFound as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **not found** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-31 14:21:42 -04:00
except exc . TagBlacklisted as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' \N{NO ENTRY SIGN} ` {} ` **blacklisted** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{NO ENTRY SIGN} ' )
2017-10-31 14:21:42 -04:00
except exc . TagBoundsError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **out of bounds.** Tags limited to 5. ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-31 14:21:42 -04:00
except exc . FavoritesNotFound :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **You have no favorite tags** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-31 14:21:42 -04:00
except exc . Timeout :
await ctx . send ( ' **Request timed out** ' )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-31 14:21:42 -04:00
finally :
if hearted :
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{HOURGLASS WITH FLOWING SAND} ' )
2017-10-31 14:21:42 -04:00
2017-11-20 08:48:44 -05:00
n = 1
for embed in hearted . values ( ) :
2017-10-31 14:21:42 -04:00
await asyncio . sleep ( self . RATE_LIMIT )
2017-11-21 06:15:25 -05:00
await ctx . author . send ( content = f ' ` { n } / { len ( hearted ) } ` ' , embed = embed )
2017-11-20 08:48:44 -05:00
n + = 1
2017-10-31 14:21:42 -04:00
2017-10-20 16:14:24 -04:00
# Searches for and returns images from e621.net given tags when not blacklisted
2017-11-20 06:18:42 -05:00
@cmds.group ( aliases = [ ' e6 ' , ' 6 ' ] , brief = ' e621 | NSFW ' , description = ' e621 | NSFW \n Tag-based search for e621.net \n \n You can only search 5 tags and 6 images at once for now. \n e6 [tags...] ([# of images]) ' )
2017-10-20 16:14:24 -04:00
@checks.is_nsfw ( )
async def e621 ( self , ctx , * args ) :
try :
kwargs = u . get_kwargs ( ctx , args , limit = 3 )
dest , args , limit = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ] , kwargs [ ' limit ' ]
2017-10-17 19:04:45 -04:00
2017-10-21 16:45:26 -04:00
tags = self . _get_favorites ( ctx , args )
2017-10-19 04:40:50 -04:00
2017-10-20 16:14:24 -04:00
await dest . trigger_typing ( )
2017-10-17 19:04:45 -04:00
2017-10-30 23:35:40 -04:00
posts , order = await self . _get_posts ( ctx , booru = ' e621 ' , tags = tags , limit = limit )
2017-10-19 04:40:50 -04:00
2017-10-20 16:14:24 -04:00
for ident , post in posts . items ( ) :
2017-10-29 18:09:48 -04:00
embed = d . Embed ( title = post [ ' artist ' ] , url = ' https://e621.net/post/show/ {} ' . format ( ident ) ,
2017-11-20 11:39:08 -05:00
color = ctx . me . color if isinstance ( ctx . channel , d . TextChannel ) else u . color )
embed . set_image ( url = post [ ' file_url ' ] )
2017-10-30 23:35:40 -04:00
embed . set_author ( name = formatter . tostring ( tags , order = order ) ,
2017-10-20 16:14:24 -04:00
url = ' https://e621.net/post?tags= {} ' . format ( ' , ' . join ( tags ) ) , icon_url = ctx . author . avatar_url )
embed . set_footer (
2017-10-30 23:32:55 -04:00
text = post [ ' score ' ] , icon_url = self . _get_score ( post [ ' score ' ] ) )
2017-10-20 16:14:24 -04:00
2017-11-20 11:36:34 -05:00
message = await dest . send ( embed = embed )
self . bot . loop . create_task ( self . queue_for_hearts ( message = message , send = embed ) )
2017-10-20 16:14:24 -04:00
except exc . TagBlacklisted as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **blacklisted** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . BoundsError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **out of bounds.** Images limited to 3. ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . TagBoundsError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **out of bounds.** Tags limited to 5. ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . NotFound as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **not found** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . FavoritesNotFound :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **You have no favorite tags** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . Timeout :
2017-10-28 16:28:16 -04:00
await ctx . send ( ' **Request timed out** ' )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
2017-11-08 22:37:45 -05:00
# @e621.error
# async def e621_error(self, ctx, error):
# if isinstance(error, exc.NSFW):
2017-11-19 12:03:49 -05:00
# await ctx.send('\N{NO ENTRY} {} **is not an NSFW channel**'.format(ctx.channel.mention), delete_after=7)
2017-11-08 22:37:45 -05:00
# await ctx.message.add_reaction('\N{NO ENTRY}')
2017-10-20 16:14:24 -04:00
# Searches for and returns images from e926.net given tags when not blacklisted
2017-11-20 06:18:42 -05:00
@cmds.command ( aliases = [ ' e9 ' , ' 9 ' ] , brief = ' e926 | SFW ' , description = ' e926 | SFW \n Tag-based search for e926.net \n \n You can only search 5 tags and 6 images at once for now. \n e9 [tags...] ([# of images]) ' )
2017-10-20 16:14:24 -04:00
async def e926 ( self , ctx , * args ) :
try :
kwargs = u . get_kwargs ( ctx , args , limit = 3 )
dest , args , limit = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ] , kwargs [ ' limit ' ]
2017-10-21 16:45:26 -04:00
tags = self . _get_favorites ( ctx , args )
2017-10-20 16:14:24 -04:00
await dest . trigger_typing ( )
2017-10-30 23:35:40 -04:00
posts , order = await self . _get_posts ( ctx , booru = ' e926 ' , tags = tags , limit = limit )
2017-10-20 16:14:24 -04:00
for ident , post in posts . items ( ) :
2017-10-29 18:09:48 -04:00
embed = d . Embed ( title = post [ ' artist ' ] , url = ' https://e926.net/post/show/ {} ' . format ( ident ) ,
2017-11-20 11:39:08 -05:00
color = ctx . me . color if isinstance ( ctx . channel , d . TextChannel ) else u . color )
embed . set_image ( url = post [ ' file_url ' ] )
2017-10-30 23:35:40 -04:00
embed . set_author ( name = formatter . tostring ( tags , order = order ) ,
2017-10-20 16:14:24 -04:00
url = ' https://e621.net/post?tags= {} ' . format ( ' , ' . join ( tags ) ) , icon_url = ctx . author . avatar_url )
embed . set_footer (
2017-10-30 23:32:55 -04:00
text = post [ ' score ' ] , icon_url = self . _get_score ( post [ ' score ' ] ) )
2017-10-20 16:14:24 -04:00
2017-11-20 11:36:34 -05:00
message = await dest . send ( embed = embed )
self . bot . loop . create_task ( self . queue_for_hearts ( message = message , send = embed ) )
2017-10-20 16:14:24 -04:00
except exc . TagBlacklisted as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **blacklisted** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . BoundsError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **out of bounds.** Images limited to 3. ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . TagBoundsError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **out of bounds.** Tags limited to 5. ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . NotFound as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **not found** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . FavoritesNotFound :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **You have no favorite tags** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . Timeout :
2017-10-28 16:28:16 -04:00
await ctx . send ( ' **Request timed out** ' )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
2017-11-20 06:18:42 -05:00
@cmds.group ( aliases = [ ' fave ' , ' fav ' , ' f ' ] )
2017-10-20 16:14:24 -04:00
async def favorite ( self , ctx ) :
2017-11-19 12:03:49 -05:00
if not ctx . invoked_subcommand :
await ctx . send ( ' **Use a flag to manage favorites.** \n *Type* ` {} help fav` *for more info.* ' . format ( ctx . prefix ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
@favorite.error
async def favorite_error ( self , ctx , error ) :
pass
@favorite.group ( name = ' get ' , aliases = [ ' g ' ] )
async def _get_favorite ( self , ctx ) :
pass
@_get_favorite.command ( name = ' tags ' , aliases = [ ' t ' ] )
async def __get_favorite_tags ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
2017-11-19 12:03:49 -05:00
await dest . send ( ' \N{WHITE MEDIUM STAR} {} ** \' s favorite tags:** \n ``` \n {} ``` ' . format ( ctx . author . mention , formatter . tostring ( self . favorites . get ( ctx . author . id , { } ) . get ( ' tags ' , set ( ) ) ) ) , delete_after = 7 )
2017-10-20 16:14:24 -04:00
@_get_favorite.command ( name = ' posts ' , aliases = [ ' p ' ] )
async def __get_favorite_posts ( self , ctx ) :
pass
@favorite.group ( name = ' add ' , aliases = [ ' a ' ] )
async def _add_favorite ( self , ctx ) :
pass
@_add_favorite.command ( name = ' tags ' , aliases = [ ' t ' ] )
async def __add_favorite_tags ( self , ctx , * args ) :
2017-09-24 11:05:28 -04:00
try :
2017-10-20 16:14:24 -04:00
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
for tag in tags :
if tag in self . blacklists [ ' user_blacklist ' ] . get ( ctx . author . id , set ( ) ) :
raise exc . TagBlacklisted ( tag )
2017-11-19 23:32:09 -05:00
with suppress ( KeyError ) :
2017-11-19 11:49:32 -05:00
if len ( self . favorites [ ctx . author . id ] [ ' tags ' ] ) + len ( tags ) > 5 :
raise exc . BoundsError
2017-10-20 16:14:24 -04:00
2017-11-19 23:32:09 -05:00
self . favorites . setdefault ( ctx . author . id , { } ) . setdefault (
' tags ' , set ( ) ) . update ( tags )
2017-10-20 16:14:24 -04:00
u . dump ( self . favorites , ' cogs/favorites.pkl ' )
await dest . send ( ' {} **added to their favorites:** \n ``` \n {} ``` ' . format ( ctx . author . mention , formatter . tostring ( tags ) ) , delete_after = 5 )
except exc . BoundsError :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **Favorites list currently limited to:** `5` ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . TagBlacklisted as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' \N{NO ENTRY SIGN} ` {} ` **blacklisted** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{NO ENTRY SIGN} ' )
2017-10-20 16:14:24 -04:00
@_add_favorite.command ( name = ' posts ' , aliases = [ ' p ' ] )
async def __add_favorite_posts ( self , ctx , * posts ) :
pass
@favorite.group ( name = ' remove ' , aliases = [ ' r ' ] )
async def _remove_favorite ( self , ctx ) :
pass
@_remove_favorite.command ( name = ' tags ' , aliases = [ ' t ' ] )
async def __remove_favorite_tags ( self , ctx , * args ) :
2017-09-24 11:05:28 -04:00
try :
2017-10-20 16:14:24 -04:00
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
2017-10-14 15:29:53 -04:00
2017-10-20 16:14:24 -04:00
for tag in tags :
try :
2017-11-19 23:32:09 -05:00
self . favorites [ ctx . author . id ] . get (
' tags ' , set ( ) ) . remove ( tag )
2017-10-19 12:42:19 -04:00
2017-10-20 16:14:24 -04:00
except KeyError :
raise exc . TagError ( tag )
2017-10-19 12:42:19 -04:00
2017-10-20 16:14:24 -04:00
u . dump ( self . favorites , ' cogs/favorites.pkl ' )
2017-10-19 12:42:19 -04:00
2017-10-20 16:14:24 -04:00
await dest . send ( ' {} **removed from their favorites:** \n ``` \n {} ``` ' . format ( ctx . author . mention , formatter . tostring ( tags ) ) , delete_after = 5 )
2017-10-15 17:21:08 -04:00
2017-11-19 23:32:09 -05:00
except KeyError :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' **You do not have any favorites** ' , delete_after = 7 )
2017-11-19 23:32:09 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
except exc . TagError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **not in favorites** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-15 17:21:08 -04:00
2017-10-20 16:14:24 -04:00
@_remove_favorite.command ( name = ' posts ' , aliases = [ ' p ' ] )
async def __remove_favorite_posts ( self , ctx ) :
pass
2017-10-17 17:59:08 -04:00
2017-10-20 16:14:24 -04:00
@favorite.group ( name = ' clear ' , aliases = [ ' c ' ] )
async def _clear_favorite ( self , ctx ) :
pass
2017-10-17 19:04:45 -04:00
2017-10-20 16:14:24 -04:00
@_clear_favorite.command ( name = ' tags ' , aliases = [ ' t ' ] )
async def __clear_favorite_tags ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
2017-10-17 19:04:45 -04:00
2017-10-20 16:14:24 -04:00
with suppress ( KeyError ) :
del self . favorites [ ctx . author . id ]
u . dump ( self . favorites , ' cogs/favorites.pkl ' )
2017-10-19 04:40:50 -04:00
2017-10-28 16:28:16 -04:00
await dest . send ( ' {} ** \' s favorites cleared** ' . format ( ctx . author . mention ) , delete_after = 5 )
2017-10-17 19:04:45 -04:00
2017-10-20 16:14:24 -04:00
@_clear_favorite.command ( name = ' posts ' , aliases = [ ' p ' ] )
async def __clear_favorite_posts ( self , ctx ) :
pass
2017-10-19 04:40:50 -04:00
2017-10-20 16:14:24 -04:00
# Umbrella command structure to manage global, channel, and user blacklists
2017-12-21 22:38:59 -05:00
@cmds.group ( aliases = [ ' bl ' , ' b ' ] , brief = ' (G) Manage blacklists ' , description = ' Manage channel or personal blacklists \n \n Usage: \n \ { p \ }bl get \ { blacklist \ } to show a blacklist \n \ { p \ }bl clear \ { blacklist \ } to clear a blacklist \n \ { p \ }bl add \ { blacklist \ } \ { tags... \ } to add tag(s) to a blacklist \n \ { p \ }bl remove \ { blacklist \ } \ { tags... \ } to remove tags from a blacklist ' )
2017-10-20 16:14:24 -04:00
async def blacklist ( self , ctx ) :
2017-11-19 12:03:49 -05:00
if not ctx . invoked_subcommand :
await ctx . send ( ' **Use a flag to manage blacklists.** \n *Type* ` {} help bl` *for more info.* ' . format ( ctx . prefix ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
# @blacklist.error
# async def blacklist_error(self, ctx, error):
# if isinstance(error, KeyError):
2017-11-19 12:03:49 -05:00
# return await ctx.send('**Blacklist does not exist**', delete_after=7)
2017-10-20 16:14:24 -04:00
2017-12-21 22:38:59 -05:00
@blacklist.group ( name = ' get ' , aliases = [ ' g ' ] , brief = ' (G) Get a blacklist \n \n Usage: \n \ { p \ }bl get \ { blacklist \ } ' )
2017-10-20 16:14:24 -04:00
async def _get_blacklist ( self , ctx ) :
2017-11-19 12:03:49 -05:00
if not ctx . invoked_subcommand :
await ctx . send ( ' **Invalid blacklist** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
2017-12-21 22:38:59 -05:00
@_get_blacklist.command ( name = ' global ' , aliases = [ ' gl ' , ' g ' ] , brief = ' Get current global blacklist ' , description = ' Get current global blacklist \n \n This applies to all booru commands, in accordance with Discord \' s ToS agreement \n \n Example: \n \ { p \ }bl get global ' )
2017-10-20 16:14:24 -04:00
async def __get_global_blacklist ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
2017-11-06 02:00:58 -05:00
await dest . send ( ' \N{NO ENTRY SIGN} **Global blacklist:** \n ``` \n {} ``` ' . format ( formatter . tostring ( self . blacklists [ ' global_blacklist ' ] ) ) )
2017-10-14 15:29:53 -04:00
2017-12-21 22:38:59 -05:00
@_get_blacklist.command ( name = ' channel ' , aliases = [ ' ch ' , ' c ' ] , brief = ' Get current channel blacklist ' , description = ' Get current channel blacklist \n \n This is based on context - the channel where the command was executed \n \n Example: \ { p \ }bl get channel ' )
2017-10-20 16:14:24 -04:00
async def __get_channel_blacklist ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
2017-10-14 15:29:53 -04:00
2017-10-20 16:14:24 -04:00
guild = ctx . guild if isinstance (
ctx . guild , d . Guild ) else ctx . channel
2017-10-14 15:29:53 -04:00
2017-11-06 02:00:58 -05:00
await dest . send ( ' \N{NO ENTRY SIGN} {} **blacklist:** \n ``` \n {} ``` ' . format ( ctx . channel . mention , formatter . tostring ( self . blacklists [ ' guild_blacklist ' ] . get ( guild . id , { } ) . get ( ctx . channel . id , set ( ) ) ) ) )
2017-10-20 16:14:24 -04:00
2017-12-21 22:38:59 -05:00
@_get_blacklist.command ( name = ' me ' , aliases = [ ' m ' ] , brief = ' Get your personal blacklist ' , description = ' Get your personal blacklist \n \n Your blacklist is not viewable by anyone but you, except if you call this command in a public channel. The blacklist will be deleted soon after for your privacy \n \n Example: \n \ { p \ }bl get me ' )
2017-10-20 16:14:24 -04:00
async def __get_user_blacklist ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
2017-10-14 15:29:53 -04:00
2017-11-19 12:03:49 -05:00
await dest . send ( ' \N{NO ENTRY SIGN} {} ** \' s blacklist:** \n ``` \n {} ``` ' . format ( ctx . author . mention , formatter . tostring ( self . blacklists [ ' user_blacklist ' ] . get ( ctx . author . id , set ( ) ) ) ) , delete_after = 7 )
2017-10-14 15:29:53 -04:00
2017-12-21 22:38:59 -05:00
@_get_blacklist.command ( name = ' here ' , aliases = [ ' h ' ] , brief = ' Get current global and channel blacklists ' , description = ' Get current global and channel blacklists in a single message \n \n Example: \ { p \ }bl get here ' )
2017-10-20 16:14:24 -04:00
async def __get_here_blacklists ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
2017-10-15 17:21:08 -04:00
2017-10-20 16:14:24 -04:00
guild = ctx . guild if isinstance (
ctx . guild , d . Guild ) else ctx . channel
2017-10-15 17:21:08 -04:00
2017-11-06 02:00:58 -05:00
await dest . send ( ' \N{NO ENTRY SIGN} **__Blacklisted:__** \n \n **Global:** \n ``` \n {} ``` \n ** {} :** \n ``` \n {} ``` ' . format ( formatter . tostring ( self . blacklists [ ' global_blacklist ' ] ) , ctx . channel . mention , formatter . tostring ( self . blacklists [ ' guild_blacklist ' ] . get ( guild . id , { } ) . get ( ctx . channel . id , set ( ) ) ) ) )
2017-10-17 17:59:08 -04:00
2017-12-21 22:38:59 -05:00
@_get_blacklist.group ( name = ' all ' , aliases = [ ' a ' ] , hidden = True )
2017-10-20 16:14:24 -04:00
async def __get_all_blacklists ( self , ctx ) :
2017-11-19 23:41:51 -05:00
if not ctx . invoked_subcommand :
2017-10-28 16:28:16 -04:00
await ctx . send ( ' **Invalid blacklist** ' )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-14 15:29:53 -04:00
2017-10-20 16:14:24 -04:00
@__get_all_blacklists.command ( name = ' guild ' , aliases = [ ' g ' ] )
2017-11-20 06:18:42 -05:00
@cmds.has_permissions ( manage_channels = True )
2017-10-20 16:14:24 -04:00
async def ___get_all_guild_blacklists ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
2017-10-14 15:29:53 -04:00
2017-10-20 16:14:24 -04:00
guild = ctx . guild if isinstance (
ctx . guild , d . Guild ) else ctx . channel
2017-10-13 23:40:38 -04:00
2017-11-06 02:00:58 -05:00
await dest . send ( ' \N{NO ENTRY SIGN} **__ {} blacklists:__** \n \n {} ' . format ( guild . name , formatter . dict_tostring ( self . blacklists [ ' guild_blacklist ' ] . get ( guild . id , { } ) ) ) )
2017-10-20 16:14:24 -04:00
@__get_all_blacklists.command ( name = ' user ' , aliases = [ ' u ' , ' member ' , ' m ' ] )
2017-11-20 06:18:42 -05:00
@cmds.is_owner ( )
2017-10-20 16:14:24 -04:00
async def ___get_all_user_blacklists ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
2017-10-13 23:40:38 -04:00
2017-11-06 02:00:58 -05:00
await dest . send ( ' \N{NO ENTRY SIGN} **__User blacklists:__** \n \n {} ' . format ( formatter . dict_tostring ( self . blacklists [ ' user_blacklist ' ] ) ) )
2017-10-14 15:29:53 -04:00
2017-12-21 22:38:59 -05:00
@blacklist.group ( name = ' add ' , aliases = [ ' a ' ] , brief = ' (G) Add tag(s) to a blacklist \n \n Usage: \n \ { p \ }bl add \ { blacklist \ } \ { tags... \ } ' )
2017-10-20 16:14:24 -04:00
async def _add_tags ( self , ctx ) :
2017-11-19 12:03:49 -05:00
if not ctx . invoked_subcommand :
await ctx . send ( ' **Invalid blacklist** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
@_add_tags.command ( name = ' global ' , aliases = [ ' gl ' , ' g ' ] )
2017-11-20 06:18:42 -05:00
@cmds.is_owner ( )
2017-10-20 16:14:24 -04:00
async def __add_global_tags ( self , ctx , * args ) :
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
2017-10-12 22:34:48 -04:00
2017-10-20 16:14:24 -04:00
await dest . trigger_typing ( )
2017-10-17 17:59:08 -04:00
2017-10-20 16:14:24 -04:00
self . blacklists [ ' global_blacklist ' ] . update ( tags )
for tag in tags :
alias_request = await u . fetch ( ' https://e621.net/tag_alias/index.json ' , params = { ' aliased_to ' : tag , ' approved ' : ' true ' } , json = True )
if alias_request :
for dic in alias_request :
self . aliases . setdefault ( tag , set ( ) ) . add ( dic [ ' name ' ] )
else :
self . aliases . setdefault ( tag , set ( ) )
u . dump ( self . blacklists , ' cogs/blacklists.pkl ' )
u . dump ( self . aliases , ' cogs/aliases.pkl ' )
await dest . send ( ' **Added to global blacklist:** \n ``` \n {} ``` ' . format ( formatter . tostring ( tags ) ) , delete_after = 5 )
2017-10-13 23:40:38 -04:00
2017-12-21 22:38:59 -05:00
@_add_tags.command ( name = ' channel ' , aliases = [ ' ch ' , ' c ' ] , brief = ' @manage_channel@ Add tag(s) to the current channel blacklist (requires manage_channel) ' , description = ' Add tag(s) to the current channel blacklist ' )
2017-11-20 06:18:42 -05:00
@cmds.has_permissions ( manage_channels = True )
2017-10-20 16:14:24 -04:00
async def __add_channel_tags ( self , ctx , * args ) :
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
guild = ctx . guild if isinstance (
ctx . guild , d . Guild ) else ctx . channel
await dest . trigger_typing ( )
self . blacklists [ ' guild_blacklist ' ] . setdefault (
guild . id , { } ) . setdefault ( ctx . channel . id , set ( ) ) . update ( tags )
for tag in tags :
alias_request = await u . fetch ( ' https://e621.net/tag_alias/index.json ' , params = { ' aliased_to ' : tag , ' approved ' : ' true ' } , json = True )
if alias_request :
for dic in alias_request :
self . aliases . setdefault ( tag , set ( ) ) . add ( dic [ ' name ' ] )
else :
self . aliases . setdefault ( tag , set ( ) )
u . dump ( self . blacklists , ' cogs/blacklists.pkl ' )
u . dump ( self . aliases , ' cogs/aliases.pkl ' )
await dest . send ( ' **Added to** {} **blacklist:** \n ``` \n {} ``` ' . format ( ctx . channel . mention , formatter . tostring ( tags ) ) , delete_after = 5 )
@_add_tags.command ( name = ' me ' , aliases = [ ' m ' ] )
async def __add_user_tags ( self , ctx , * args ) :
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
await dest . trigger_typing ( )
2017-11-19 23:42:20 -05:00
self . blacklists [ ' user_blacklist ' ] . setdefault (
ctx . author . id , set ( ) ) . update ( tags )
2017-10-20 16:14:24 -04:00
for tag in tags :
alias_request = await u . fetch ( ' https://e621.net/tag_alias/index.json ' , params = { ' aliased_to ' : tag , ' approved ' : ' true ' } , json = True )
if alias_request :
for dic in alias_request :
self . aliases . setdefault ( tag , set ( ) ) . add ( dic [ ' name ' ] )
else :
self . aliases . setdefault ( tag , set ( ) )
u . dump ( self . blacklists , ' cogs/blacklists.pkl ' )
u . dump ( self . aliases , ' cogs/aliases.pkl ' )
await dest . send ( ' {} **added to their blacklist:** \n ``` \n {} ``` ' . format ( ctx . author . mention , formatter . tostring ( tags ) ) , delete_after = 5 )
@blacklist.group ( name = ' remove ' , aliases = [ ' rm ' , ' r ' ] )
async def _remove_tags ( self , ctx ) :
2017-11-19 12:03:49 -05:00
if not ctx . invoked_subcommand :
await ctx . send ( ' **Invalid blacklist** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
@_remove_tags.command ( name = ' global ' , aliases = [ ' gl ' , ' g ' ] )
2017-11-20 06:18:42 -05:00
@cmds.is_owner ( )
2017-10-20 16:14:24 -04:00
async def __remove_global_tags ( self , ctx , * args ) :
2017-10-02 19:37:58 -04:00
try :
2017-10-20 16:14:24 -04:00
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
for tag in tags :
try :
self . blacklists [ ' global_blacklist ' ] . remove ( tag )
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
except KeyError :
raise exc . TagError ( tag )
2017-10-14 15:29:53 -04:00
2017-10-20 16:14:24 -04:00
u . dump ( self . blacklists , ' cogs/blacklists.pkl ' )
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
await dest . send ( ' **Removed from global blacklist:** \n ``` \n {} ``` ' . format ( formatter . tostring ( tags ) ) , delete_after = 5 )
2017-10-12 22:34:48 -04:00
2017-10-20 16:14:24 -04:00
except exc . TagError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **not in blacklist** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-17 17:59:08 -04:00
2017-10-20 16:14:24 -04:00
@_remove_tags.command ( name = ' channel ' , aliases = [ ' ch ' , ' c ' ] )
2017-11-20 06:18:42 -05:00
@cmds.has_permissions ( manage_channels = True )
2017-10-20 16:14:24 -04:00
async def __remove_channel_tags ( self , ctx , * args ) :
2017-10-02 19:37:58 -04:00
try :
2017-10-20 16:14:24 -04:00
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
guild = ctx . guild if isinstance (
ctx . guild , d . Guild ) else ctx . channel
2017-10-14 15:29:53 -04:00
2017-10-20 16:14:24 -04:00
for tag in tags :
try :
2017-11-19 23:42:20 -05:00
self . blacklists [ ' guild_blacklist ' ] [ guild . id ] [ ctx . channel . id ] . remove (
tag )
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
except KeyError :
raise exc . TagError ( tag )
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
u . dump ( self . blacklists , ' cogs/blacklists.pkl ' )
2017-09-24 11:05:28 -04:00
2017-10-20 16:14:24 -04:00
await dest . send ( ' **Removed from** {} **blacklist:** \n ``` \n {} ``` ' . format ( ctx . channel . mention , formatter . tostring ( tags ) , delete_after = 5 ) )
2017-10-12 22:34:48 -04:00
2017-10-20 16:14:24 -04:00
except exc . TagError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **not in blacklist** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-17 17:59:08 -04:00
2017-10-20 16:14:24 -04:00
@_remove_tags.command ( name = ' me ' , aliases = [ ' m ' ] )
async def __remove_user_tags ( self , ctx , * args ) :
try :
kwargs = u . get_kwargs ( ctx , args )
dest , tags = kwargs [ ' destination ' ] , kwargs [ ' remaining ' ]
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
for tag in tags :
try :
2017-11-19 23:42:20 -05:00
self . blacklists [ ' user_blacklist ' ] [ ctx . author . id ] . remove (
tag )
2017-10-12 22:34:48 -04:00
2017-10-20 16:14:24 -04:00
except KeyError :
raise exc . TagError ( tag )
2017-10-17 17:59:08 -04:00
2017-10-20 16:14:24 -04:00
u . dump ( self . blacklists , ' cogs/blacklists.pkl ' )
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
await dest . send ( ' {} **removed from their blacklist:** \n ``` \n {} ``` ' . format ( ctx . author . mention , formatter . tostring ( tags ) ) , delete_after = 5 )
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
except exc . TagError as e :
2017-11-19 12:03:49 -05:00
await ctx . send ( ' ` {} ` **not in blacklist** ' . format ( e ) , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-12 22:34:48 -04:00
2017-10-20 16:14:24 -04:00
@blacklist.group ( name = ' clear ' , aliases = [ ' cl ' , ' c ' ] )
async def _clear_blacklist ( self , ctx ) :
2017-11-19 12:03:49 -05:00
if not ctx . invoked_subcommand :
await ctx . send ( ' **Invalid blacklist** ' , delete_after = 7 )
2017-11-06 02:00:58 -05:00
await ctx . message . add_reaction ( ' \N{CROSS MARK} ' )
2017-10-20 16:14:24 -04:00
@_clear_blacklist.command ( name = ' global ' , aliases = [ ' gl ' , ' g ' ] )
2017-11-20 06:18:42 -05:00
@cmds.is_owner ( )
2017-10-20 16:14:24 -04:00
async def __clear_global_blacklist ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
self . blacklists [ ' global_blacklist ' ] . clear ( )
u . dump ( self . blacklists , ' cogs/blacklists.pkl ' )
2017-10-28 16:28:16 -04:00
await dest . send ( ' **Global blacklist cleared** ' , delete_after = 5 )
2017-10-20 16:14:24 -04:00
@_clear_blacklist.command ( name = ' channel ' , aliases = [ ' ch ' , ' c ' ] )
2017-11-20 06:18:42 -05:00
@cmds.has_permissions ( manage_channels = True )
2017-10-20 16:14:24 -04:00
async def __clear_channel_blacklist ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
2017-10-17 17:59:08 -04:00
2017-10-20 16:14:24 -04:00
guild = ctx . guild if isinstance (
ctx . guild , d . Guild ) else ctx . channel
2017-10-13 23:40:38 -04:00
2017-10-20 16:14:24 -04:00
with suppress ( KeyError ) :
del self . blacklists [ ' guild_blacklist ' ] [ guild . id ] [ ctx . channel . id ]
u . dump ( self . blacklists , ' cogs/blacklists.pkl ' )
2017-10-28 16:28:16 -04:00
await dest . send ( ' {} **blacklist cleared** ' . format ( ctx . channel . mention ) , delete_after = 5 )
2017-10-20 16:14:24 -04:00
@_clear_blacklist.command ( name = ' me ' , aliases = [ ' m ' ] )
async def __clear_user_blacklist ( self , ctx , * args ) :
dest = u . get_kwargs ( ctx , args ) [ ' destination ' ]
with suppress ( KeyError ) :
del self . blacklists [ ' user_blacklist ' ] [ ctx . author . id ]
u . dump ( self . blacklists , ' cogs/blacklists.pkl ' )
2017-10-28 16:28:16 -04:00
await dest . send ( ' {} ** \' s blacklist cleared** ' . format ( ctx . author . mention ) , delete_after = 5 )