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

Merge branch 'dev'

This commit is contained in:
Myned 2019-09-17 03:01:20 -04:00
commit be8a319312
10 changed files with 130 additions and 206 deletions

View file

@ -17,10 +17,9 @@ verify_ssl = true
[packages] [packages]
beautifulsoup4 = "*" beautifulsoup4 = "*"
"discord.py" = {extras = ["voice"],git = "https://github.com/Rapptz/discord.py",ref = "rewrite"} "discord.py" = {extras = ["voice"],git = "https://github.com/Rapptz/discord.py"}
"hurry.filesize" = "*" "hurry.filesize" = "*"
requests = "*" requests = "*"
[dev-packages] [dev-packages]
lxml = "*" lxml = "*"

View file

@ -21,7 +21,7 @@ from utils import utils as u
from utils import formatter, scraper from utils import formatter, scraper
class MsG: class MsG(cmds.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@ -106,8 +106,10 @@ class MsG:
return args return args
def _get_score(self, score): def _get_icon(self, score):
if score < 0: if score is 'SauceNAO':
return 'https://d2.alternativeto.net/dist/icons/saucenao_23437.png?width=64&height=64&mode=crop&upscale=false'
elif score < 0:
return 'https://emojipedia-us.s3.amazonaws.com/thumbs/320/twitter/103/pouting-face_1f621.png' return 'https://emojipedia-us.s3.amazonaws.com/thumbs/320/twitter/103/pouting-face_1f621.png'
elif score == 0: elif score == 0:
return 'https://emojipedia-us.s3.amazonaws.com/thumbs/320/mozilla/36/pile-of-poo_1f4a9.png' return 'https://emojipedia-us.s3.amazonaws.com/thumbs/320/mozilla/36/pile-of-poo_1f4a9.png'
@ -301,7 +303,7 @@ class MsG:
embed.set_author(name=f'{post["width"]} x {post["height"]}', embed.set_author(name=f'{post["width"]} x {post["height"]}',
url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=ctx.author.avatar_url) 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'], embed.set_footer(text=post['score'],
icon_url=self._get_score(post['score'])) icon_url=self._get_icon(post['score']))
except exc.MissingArgument: except exc.MissingArgument:
await ctx.send('\N{CROSS MARK} **Invalid url**') await ctx.send('\N{CROSS MARK} **Invalid url**')
@ -399,17 +401,21 @@ class MsG:
try: try:
await ctx.trigger_typing() await ctx.trigger_typing()
post = await scraper.get_post(url) post, source, similarity = await scraper.get_post(url)
embed = d.Embed( 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) title=', '.join(post['artist']),
url=source,
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
embed.set_image(url=post['file_url']) embed.set_image(url=post['file_url'])
embed.set_author(name=f'{post["width"]} x {post["height"]}', embed.set_author(
url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=ctx.author.avatar_url) name=similarity,
embed.set_footer(text=post['score'], icon_url=ctx.author.avatar_url)
icon_url=self._get_score(post['score'])) embed.set_footer(
text=post['score'],
icon_url=self._get_icon(post['score']))
await ctx.send('**Probable match**', embed=embed) await ctx.send(embed=embed)
c += 1 c += 1
@ -437,7 +443,7 @@ class MsG:
async def reversify(self, ctx, *args): async def reversify(self, ctx, *args):
try: try:
dest = ctx dest = ctx
kwargs = u.get_kwargs(ctx, args, limit=self.HISTORY_LIMIT / 5) kwargs = u.get_kwargs(ctx, args, limit=5)
remove, limit = kwargs['remove'], kwargs['limit'] remove, limit = kwargs['remove'], kwargs['limit']
links = {} links = {}
c = 0 c = 0
@ -470,17 +476,21 @@ class MsG:
try: try:
await ctx.trigger_typing() await ctx.trigger_typing()
post = await scraper.get_post(url) post, source, similarity = await scraper.get_post(url)
embed = d.Embed( 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) title=', '.join(post['artist']),
url=source,
color=ctx.me.color if isinstance(ctx.channel, d.TextChannel) else u.color)
embed.set_image(url=post['file_url']) embed.set_image(url=post['file_url'])
embed.set_author(name=f'{post["width"]} x {post["height"]}', embed.set_author(
url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=ctx.author.avatar_url) name=similarity,
icon_url=message.author.avatar_url)
embed.set_footer( embed.set_footer(
text=post['score'], icon_url=self._get_score(post['score'])) text=post['score'],
icon_url=self._get_icon(post['score']))
await dest.send(f'**Probable match from** {message.author.display_name}', embed=embed) await dest.send(embed=embed)
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
if remove: if remove:
@ -529,17 +539,21 @@ class MsG:
try: try:
await message.channel.trigger_typing() await message.channel.trigger_typing()
post = await scraper.get_post(url) post, source, similarity = await scraper.get_post(url)
embed = d.Embed( 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) title=', '.join(post['artist']),
url=source,
color=message.channel.guild.me.color if isinstance(message.channel, d.TextChannel) else u.color)
embed.set_image(url=post['file_url']) embed.set_image(url=post['file_url'])
embed.set_author(name=f'{post["width"]} x {post["height"]}', embed.set_author(
url=f'https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f}', icon_url=message.author.avatar_url) name=similarity,
embed.set_footer(text=post['score'], icon_url=message.author.avatar_url)
icon_url=self._get_score(post['score'])) embed.set_footer(
text=post['score'],
icon_url=self._get_icon(post['score']))
await message.channel.send('**Probable match from** {}'.format(message.author.display_name), embed=embed) await message.channel.send(embed=embed)
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
@ -768,7 +782,7 @@ class MsG:
embed.set_author(name=pool['name'], embed.set_author(name=pool['name'],
url='https://e621.net/pool/show?id={}'.format(pool['id']), icon_url=ctx.author.avatar_url) url='https://e621.net/pool/show?id={}'.format(pool['id']), icon_url=ctx.author.avatar_url)
embed.set_footer(text='{} / {}'.format(c, len(posts)), embed.set_footer(text='{} / {}'.format(c, len(posts)),
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_icon(values[c - 1]['score']))
paginator = await ctx.send(embed=embed) paginator = await ctx.send(embed=embed)
@ -799,7 +813,7 @@ class MsG:
embed.url = 'https://e621.net/post/show/{}'.format( embed.url = 'https://e621.net/post/show/{}'.format(
keys[c - 1]) keys[c - 1])
embed.set_footer(text='{} / {}'.format(c, len(posts)), embed.set_footer(text='{} / {}'.format(c, len(posts)),
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_icon(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['file_url']) embed.set_image(url=values[c - 1]['file_url'])
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed) await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
@ -817,7 +831,7 @@ class MsG:
embed.url = 'https://e621.net/post/show/{}'.format( embed.url = 'https://e621.net/post/show/{}'.format(
keys[c - 1]) keys[c - 1])
embed.set_footer(text='{} / {}'.format(c, len(posts)), embed.set_footer(text='{} / {}'.format(c, len(posts)),
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_icon(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['file_url']) embed.set_image(url=values[c - 1]['file_url'])
if ctx.channel is d.TextChannel: if ctx.channel is d.TextChannel:
@ -833,7 +847,7 @@ class MsG:
embed.url = 'https://e621.net/post/show/{}'.format( embed.url = 'https://e621.net/post/show/{}'.format(
keys[c - 1]) keys[c - 1])
embed.set_footer(text='{} / {}'.format(c, len(posts)), embed.set_footer(text='{} / {}'.format(c, len(posts)),
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_icon(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['file_url']) embed.set_image(url=values[c - 1]['file_url'])
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed) await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
@ -904,7 +918,7 @@ class MsG:
embed.set_author(name=' '.join(tags) if tags else order, embed.set_author(name=' '.join(tags) if tags else order,
url='https://{}.net/post?tags={}'.format(booru, ','.join(tags)), icon_url=ctx.author.avatar_url) url='https://{}.net/post?tags={}'.format(booru, ','.join(tags)), icon_url=ctx.author.avatar_url)
embed.set_footer(text=values[c - 1]['score'], embed.set_footer(text=values[c - 1]['score'],
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_icon(values[c - 1]['score']))
paginator = await ctx.send(embed=embed) paginator = await ctx.send(embed=embed)
@ -936,7 +950,7 @@ class MsG:
booru, booru,
keys[c - 1]) keys[c - 1])
embed.set_footer(text=values[c - 1]['score'], embed.set_footer(text=values[c - 1]['score'],
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_icon(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['file_url']) embed.set_image(url=values[c - 1]['file_url'])
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed) await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
@ -960,7 +974,7 @@ class MsG:
booru, booru,
keys[c - 1]) keys[c - 1])
embed.set_footer(text=values[c - 1]['score'], embed.set_footer(text=values[c - 1]['score'],
icon_url=self._get_score(values[c - 1]['score'])) icon_url=self._get_icon(values[c - 1]['score']))
embed.set_image(url=values[c - 1]['file_url']) embed.set_image(url=values[c - 1]['file_url'])
await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed) await paginator.edit(content='\N{HEAVY BLACK HEART}' if keys[c - 1] in hearted.keys() else None, embed=embed)
@ -1035,7 +1049,7 @@ class MsG:
embed.set_author(name=' '.join(tags) if tags else order, embed.set_author(name=' '.join(tags) if tags else order,
url='https://{}.net/post?tags={}'.format(booru, ','.join(tags)), icon_url=ctx.author.avatar_url) url='https://{}.net/post?tags={}'.format(booru, ','.join(tags)), icon_url=ctx.author.avatar_url)
embed.set_footer( embed.set_footer(
text=post['score'], icon_url=self._get_score(post['score'])) text=post['score'], icon_url=self._get_icon(post['score']))
message = await ctx.send(embed=embed) message = await ctx.send(embed=embed)

View file

@ -8,7 +8,7 @@ from misc import exceptions as exc
from utils import utils as u from utils import utils as u
class Info: class Info(cmds.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot

View file

@ -13,7 +13,7 @@ from misc import checks
from utils import utils as u from utils import utils as u
class Administration: class Admin(cmds.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot

View file

@ -16,7 +16,7 @@ from utils import utils as u
from utils import formatter from utils import formatter
class Bot: class Bot(cmds.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@ -182,7 +182,7 @@ class Bot:
await u.add_reaction(ctx.message, '\N{CROSS MARK}') await u.add_reaction(ctx.message, '\N{CROSS MARK}')
class Tools: class Tools(cmds.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot

View file

@ -12,7 +12,7 @@ from misc import checks
from utils import utils as u from utils import utils as u
class Post: class Post(cmds.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot

View file

@ -21,7 +21,7 @@ youtube = None
tempfile.tempdir = os.getcwd() tempfile.tempdir = os.getcwd()
class Utils: class Utils(cmds.Cog):
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot

View file

@ -1,18 +1,11 @@
import asyncio import asyncio
from datetime import datetime as dt
import json
import logging as log import logging as log
import subprocess
import sys import sys
import traceback as tb import traceback as tb
from contextlib import suppress from contextlib import suppress
from pprint import pprint
from hurry.filesize import size, alternative
from urllib.parse import urlparse
import discord as d import discord as d
from discord import errors as err from discord import errors as err
from discord import utils
from discord.ext import commands as cmds from discord.ext import commands as cmds
from discord.ext.commands import errors as errext from discord.ext.commands import errors as errext
@ -23,68 +16,41 @@ from utils import utils as u
log.basicConfig(level=log.WARNING) log.basicConfig(level=log.WARNING)
# class HelpFormatter(cmds.HelpFormatter):
#
# async def format(self):
# self._paginator = cmds.Paginator()
#
# # we need a padding of ~80 or so
#
# description = self.command.description if not self.is_cog() else inspect.getdoc(self.command)
#
# if description:
# # <description> portion
# self._paginator.add_line(description, empty=True)
#
# if isinstance(self.command, cmds.Command):
# # <signature portion>
# signature = self.get_command_signature()
# self._paginator.add_line(signature, empty=True)
#
# # <long doc> section
# if self.command.help:
# self._paginator.add_line(self.command.help, empty=True)
#
# # end it here if it's just a regular command
# if not self.has_subcommands():
# self._paginator.close_page()
# return self._paginator.pages
#
# max_width = self.max_name_size
def get_prefix(bot, message): def get_prefix(bot, message):
with suppress(AttributeError): with suppress(AttributeError):
return u.settings['prefixes'].get(message.guild.id, u.config['prefix']) return u.settings['prefixes'].get(message.guild.id, u.config['prefix'])
return u.config['prefix'] return u.config['prefix']
bot = cmds.Bot(command_prefix=get_prefix, self_bot=u.config['selfbot'], formatter=cmds.HelpFormatter(show_check_failure=True), description='Modufur - A booru bot with a side of management and automated tasking\nMade by @Myned#3985\n\nNSFW for Not Safe For Wumpus commands\n(G) for group commands\n@permission@ for required permissions\n!notice! for important information\np for prefix\n\n\{\} for mandatory argument\n[] for optional argument\n... for one or more arguments', help_attrs={'aliases': ['h']}, pm_help=None)
@bot.command(help='help', brief='brief', description='description', usage='usage', hidden=True) bot = cmds.Bot(
async def test(ctx): command_prefix=get_prefix,
await ctx.send('test') self_bot=u.config['selfbot'],
description='Modufur - A booru bot with a side of management and automated tasking'
# Send and print ready message to #testing and console after logon '\nMade by @Myned#3985')
@bot.event @bot.event
async def on_ready(): async def on_ready():
if not checks.ready: if not checks.ready:
# d.opus.load_opus('opuslib')
from cogs import booru, info, management, owner, tools from cogs import booru, info, management, owner, tools
for cog in (tools.Utils(bot), owner.Bot(bot), owner.Tools(bot), management.Administration(bot), info.Info(bot), booru.MsG(bot)): for cog in (
tools.Utils(bot),
owner.Bot(bot),
owner.Tools(bot),
management.Admin(bot),
info.Info(bot),
booru.MsG(bot)):
bot.add_cog(cog) bot.add_cog(cog)
u.cogs[type(cog).__name__] = cog u.cogs[type(cog).__name__] = cog
print(f'COG : {type(cog).__name__}') print(f'COG : {type(cog).__name__}')
# bot.loop.create_task(u.clear(booru.temp_urls, 30*60))
if u.config['playing'] is not '': if u.config['playing'] is not '':
await bot.change_presence(activity=d.Game(u.config['playing'])) await bot.change_presence(activity=d.Game(u.config['playing']))
print('\n> > > > > > > > >\nC O N N E C T E D : {}\n> > > > > > > > >\n'.format(bot.user.name)) print('\n> > > > > > > > >'
f'\nC O N N E C T E D : {bot.user.name}'
'\n> > > > > > > > >\n')
try: try:
if u.temp['startup']: if u.temp['startup']:
@ -93,7 +59,7 @@ async def on_ready():
ctx = bot.get_channel(u.temp['startup'][1]) ctx = bot.get_channel(u.temp['startup'][1])
else: else:
ctx = bot.get_user(u.temp['startup'][1]) ctx = bot.get_user(u.temp['startup'][1])
message = await ctx.get_message(u.temp['startup'][2]) message = await ctx.fetch_message(u.temp['startup'][2])
await message.add_reaction('\N{WHITE HEAVY CHECK MARK}') await message.add_reaction('\N{WHITE HEAVY CHECK MARK}')
@ -113,10 +79,10 @@ async def on_ready():
if u.tasks['auto_del']: if u.tasks['auto_del']:
for channel in u.tasks['auto_del']: for channel in u.tasks['auto_del']:
temp = bot.get_channel(channel) temp = bot.get_channel(channel)
bot.loop.create_task(u.cogs['Administration'].queue_for_deletion(temp)) bot.loop.create_task(u.cogs['Admin'].queue_for_deletion(temp))
print('RESTARTED : auto-deleting in #{}'.format(temp.name)) print(f'RESTARTED : auto-deleting in #{temp.name}')
u.cogs['Administration'].deleting = True u.cogs['Admin'].deleting = True
bot.loop.create_task(u.cogs['Administration'].delete()) bot.loop.create_task(u.cogs['Admin'].delete())
if u.config['playing'] is not '': if u.config['playing'] is not '':
await bot.change_presence(activity=d.Game(u.config['playing'])) await bot.change_presence(activity=d.Game(u.config['playing']))
@ -137,9 +103,9 @@ async def on_message(message):
@bot.event @bot.event
async def on_error(error, *args, **kwargs): async def on_error(error, *args, **kwargs):
print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(sys.exc_info()[1].text), file=sys.stderr) print(f'\n! ! ! ! !\nE R R O R : {sys.exc_info()[1].text}\n! ! ! ! !\n', file=sys.stderr)
tb.print_exc() tb.print_exc()
await bot.get_user(u.config['owner_id']).send('**ERROR** \N{WARNING SIGN}\n```\n{}```'.format(error)) await bot.get_user(u.config['owner_id']).send(f'**ERROR** \N{WARNING SIGN}\n```\n{error}```')
if u.temp['startup']: if u.temp['startup']:
u.temp.clear() u.temp.clear()
@ -171,41 +137,42 @@ async def on_command_error(ctx, error):
await ctx.send('**Insufficient permissions**') await ctx.send('**Insufficient permissions**')
await u.add_reaction(ctx.message, '\N{NO ENTRY}') await u.add_reaction(ctx.message, '\N{NO ENTRY}')
elif isinstance(error, errext.CommandNotFound): elif isinstance(error, errext.CommandNotFound):
print('INVALID COMMAND : {}'.format(error), file=sys.stderr) print(f'INVALID COMMAND : {error}', file=sys.stderr)
await u.add_reaction(ctx.message, '\N{BLACK QUESTION MARK ORNAMENT}') await u.add_reaction(ctx.message, '\N{BLACK QUESTION MARK ORNAMENT}')
else: else:
print('\n! ! ! ! ! ! ! ! ! ! ! !\nC O M M A N D E R R O R : {}\n! ! ! ! ! ! ! ! ! ! ! !\n'.format(error), file=sys.stderr) print('\n! ! ! ! ! ! ! ! ! ! ! !'
f'\nC O M M A N D E R R O R : {error}'
'\n! ! ! ! ! ! ! ! ! ! ! !\n', file=sys.stderr)
tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr) tb.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
await bot.get_user(u.config['owner_id']).send('**COMMAND ERROR** \N{WARNING SIGN} `{}` from {} in {}\n```\n{}```'.format(ctx.message.content, ctx.author.mention, ctx.channel.mention if isinstance(ctx.channel, d.channel.TextChannel) else 'DMs', error)) await bot.get_user(u.config['owner_id']).send(
'**COMMAND ERROR** \N{WARNING SIGN}'
f'`{ctx.message.content}`'
f'from {ctx.author.mention}'
f'in {ctx.channel.mention if isinstance(ctx.channel, d.channel.TextChannel) else "DMs"}'
'\n```\n'
f'{error}```')
await exc.send_error(ctx, error) await exc.send_error(ctx, error)
await u.add_reaction(ctx.message, '\N{WARNING SIGN}') await u.add_reaction(ctx.message, '\N{WARNING SIGN}')
# @bot.event
# async def on_command(ctx):
# if ctx.guild.id in u.settings['del_resp']:
# pass
@bot.event @bot.event
async def on_command_completion(ctx): async def on_command_completion(ctx):
with suppress(err.NotFound): with suppress(err.NotFound):
with suppress(AttributeError): with suppress(AttributeError):
if ctx.guild.id in u.settings['del_ctx'] and ctx.me.permissions_in(ctx.channel).manage_messages and isinstance(ctx.message.channel, d.TextChannel): if ctx.guild.id in u.settings['del_ctx'] and ctx.me.permissions_in(ctx.channel).manage_messages:
await ctx.message.delete() await ctx.message.delete()
# with suppress(err.Forbidden):
# await u.add_reaction(ctx.message, '\N{WHITE HEAVY CHECK MARK}')
for command in ('lastcommand', ',restart', ',die'):
if ctx.command.name == command:
return
u.last_commands[ctx.author.id] = ctx u.last_commands[ctx.author.id] = ctx
@bot.event @bot.event
async def on_guild_join(guild): async def on_guild_join(guild):
if str(guild.id) in u.block['guild_ids']: if str(guild.id) in u.block['guild_ids']:
print(f'LEAVING : {guild.name}') print(f'LEAVING : {guild.name}')
await guild.leave() await guild.leave()
else:
print(f'JOINING : {guild.name}')
@bot.event @bot.event
async def on_guild_remove(guild): async def on_guild_remove(guild):
@ -219,70 +186,10 @@ async def on_guild_remove(guild):
u.dump(u.tasks, 'cogs/tasks.pkl') u.dump(u.tasks, 'cogs/tasks.pkl')
async def wait(voice):
asyncio.sleep(5)
await voice.disconnect()
def after(voice, error):
coro = voice.disconnect()
future = asyncio.run_coroutine_threadsafe(coro, voice.loop)
future.result()
# suggested = u.setdefault('cogs/suggested.pkl', {'last_update': 'None', 'tags': {}, 'total': 0})
@bot.command(name=',test', hidden=True) @bot.command(name=',test', hidden=True)
@cmds.is_owner() @cmds.is_owner()
async def test(ctx): async def test(ctx):
post = await u.fetch('https://e621.net/post/show.json?id=1145042', json=True) pass
tags = []
if post['tags']:
temptags = post['tags'].split(' ')
cis = []
# for tag in suggested:
# pass
for tag in temptags:
tags.append(f'[{tag}](https://e621.net/post?tags={tag})')
# tags = ' '.join(tags)
else:
tags = 'None'
if post['description']:
post_description = post['description'] if len(post['description']) < 200 else f'{post["description"][:200]}...'
else:
post_description = 'None'
title = ', '.join(post['artist'])
description = f'posted by: *[{post["author"]}](https://e621.net/post?tags=user:{post["author"]})*'
url = f'https://e621.net/post?tags={",".join(post["artist"])}'
# timestamp = dt.utcnow()
color = ctx.me.color
footer = {'text': post['score'], 'icon_url': 'https://images-ext-1.discordapp.net/external/W2k0ZzhU7ngvN_-CdqAa3H3FmkfCNYQTxPG_DsvacB4/https/emojipedia-us.s3.amazonaws.com/thumbs/320/twitter/103/sparkles_2728.png'}
# image = 'https://e621.net/post/show/54360'
thumbnail = post['file_url']
author = {'name': post['id'], 'url': f'https://e621.net/post/show/{post["id"]}', 'icon_url': ctx.author.avatar_url}
fields = []
names = ('File', 'Sources', 'Description', 'tags', 'tags (ext.)')
values = (f'[{post["md5"]}]({post["file_url"]}) | [{post["file_ext"]}](https://e621.net/post?tags=type:{post["file_ext"]})\n\n**Size** [{size(post["file_size"], system=alternative)}](https://e621.net/post?tags=filesize:{post["file_size"]})\n**Resolution** [{post["width"]} x {post["height"]}](https://e621.net/post?tags=width:{post["width"]},height:{post["height"]}) | [{u.get_aspectratio(post["width"], post["height"])}](https://e621.net/post?tags=ratio:{post["width"]/post["height"]:.2f})', '\n'.join([f'[{urlparse(source).netloc}]({source})' for source in post['sources']]), post_description, ' '.join(tags[:20]), ' '.join(tags[20:]))
inlines = (False, False, False, True, True)
for name, value, inline in zip(names, values, inlines):
fields.append({'name': name, 'value': value, 'inline': inline})
embed = u.generate_embed(ctx, title=title, description=description, url=url, colour=color, footer=footer, thumbnail=thumbnail, author=author, fields=fields)
await ctx.send(embed=embed)
# print(ctx.args)
# print(ctx.kwargs)
# if '<:N_:368917475531816962>' in message:
# await ctx.send('<:N_:368917475531816962>')
# logs = []
# async for entry in ctx.guild.audit_logs(limit=None, action=d.AuditLogAction.message_delete):
# logs.append(
# f'@{entry.user.name} deleted {entry.extra.count} messages from @{entry.target.name} in #{entry.extra.channel.name}')
# pprint(logs)
# channel = bot.get_channel(int(cid))
# voice = await channel.connect()
# voice.play(d.AudioSource, after=lambda: after(voice))
bot.run(u.config['token'], bot=not u.config['selfbot']) bot.run(u.config['token'], bot=not u.config['selfbot'])

View file

@ -16,31 +16,51 @@ async def get_post(url):
if filesize > 8192 * 1024: if filesize > 8192 * 1024:
raise exc.SizeError(size(filesize, system=alternative)) raise exc.SizeError(size(filesize, system=alternative))
except (ValueError, KeyError): content = await u.fetch('http://iqdb.harry.lu', params={'url': url})
raise exc.MissingArgument soup = BeautifulSoup(content, 'html.parser')
source = soup.find_all('a', limit=2)[1].get('href')
content = await u.fetch('http://iqdb.harry.lu', params={'url': url}) if source != '#':
ident = re.search('show/([0-9]+)', source).group(1)
try:
value = BeautifulSoup(content, 'html.parser').find_all('a')[1].get('href')
if value != '#':
ident = re.search('show/([0-9]+)', value).group(1)
post = await u.fetch('http://e621.net/post/show.json', params={'id': ident}, json=True) post = await u.fetch('http://e621.net/post/show.json', params={'id': ident}, json=True)
if (post['status'] == 'deleted'): if (post['status'] == 'deleted'):
ident = re.search('#(\\d+)', post['delreason']).group(1) ident = re.search('#(\\d+)', post['delreason']).group(1)
post = await u.fetch('http://e621.net/post/show.json', params={'id': ident}, json=True) post = await u.fetch('http://e621.net/post/show.json', params={'id': ident}, json=True)
source = f'https://e621.net/post/show/{post["id"]}'
similarity = re.search('\\d+', soup.find(string=re.compile('similarity'))).group(0) + '% Match'
return post return post, source, similarity
else: else:
raise IndexError raise IndexError
except IndexError: except IndexError:
try: content = await u.fetch(
raise exc.MatchError(re.search('\\/([^\\/]+)$', url).group(1)) 'https://saucenao.com/search.php',
params={
'url': url,
'api_key': u.config['saucenao_api'],
'output_type': 2},
json=True)
result = content['results'][0]
if 'author_name' in result['data']:
artist = 'author_name'
elif 'member_name' in result['data']:
artist = 'member_name'
else:
artist = 'creator'
post = {
'file_url': result['header']['thumbnail'],
'artist': [result['data'][artist]],
'score': 'SauceNAO'}
source = result['data']['ext_urls'][0]
similarity = re.search('(\\d+)\\.', result['header']['similarity']).group(1) + '% Match'
except AttributeError: return post, source, similarity
raise exc.MissingArgument
raise exc.MatchError(re.search('\\/([^\\/]+)$', url).group(1))
except (AttributeError, ValueError, KeyError):
raise exc.MissingArgument
async def get_image(url): async def get_image(url):

View file

@ -2,11 +2,9 @@ import asyncio
import json as jsn import json as jsn
import os import os
import pickle as pkl import pickle as pkl
import subprocess
from contextlib import suppress from contextlib import suppress
from fractions import gcd from fractions import gcd
import math import math
from pprint import pprint
import aiohttp import aiohttp
import discord as d import discord as d
@ -28,7 +26,7 @@ try:
except FileNotFoundError: except FileNotFoundError:
with open('config.json', 'w') as outfile: with open('config.json', 'w') as outfile:
jsn.dump({'client_id': 0, 'owner_id': 0, 'permissions': 126016, jsn.dump({'client_id': 0, 'owner_id': 0, 'permissions': 126016,
'playing': 'a game', 'prefix': [',', 'm,'], 'selfbot': False, 'token': 'str'}, outfile, indent=4, sort_keys=True) 'playing': 'a game', 'prefix': [',', 'm,'], 'selfbot': False, 'token': 'str', 'saucenao_api': 'str'}, outfile, indent=4, sort_keys=True)
print('FILE NOT FOUND : config.json created with abstract values. Restart run.py with correct values') print('FILE NOT FOUND : config.json created with abstract values. Restart run.py with correct values')
@ -97,21 +95,6 @@ async def fetch(url, *, params={}, json=False, response=False):
return await r.read() return await r.read()
# async def clear(obj, interval=10 * 60, replace=None):
# if replace is None:
# if type(obj) is list:
# replace = []
# elif type(obj) is dict:
# replace = {}
# elif type(obj) is int:
# replace = 0
# elif type(obj) is str:
# replace = ''
#
# while True:
# obj = replace
# asyncio.sleep(interval)
def generate_embed(ctx, *, title=d.Embed.Empty, kind='rich', description=d.Embed.Empty, url=d.Embed.Empty, timestamp=d.Embed.Empty, colour=color, footer={}, image=d.Embed.Empty, thumbnail=d.Embed.Empty, author={}, fields=[]): def generate_embed(ctx, *, title=d.Embed.Empty, kind='rich', description=d.Embed.Empty, url=d.Embed.Empty, timestamp=d.Embed.Empty, colour=color, footer={}, image=d.Embed.Empty, thumbnail=d.Embed.Empty, author={}, fields=[]):
embed = d.Embed(title=title, type=kind, description=description, url=url, timestamp=timestamp, colour=colour if isinstance(ctx.channel, d.TextChannel) else color) embed = d.Embed(title=title, type=kind, description=description, url=url, timestamp=timestamp, colour=colour if isinstance(ctx.channel, d.TextChannel) else color)
@ -128,6 +111,7 @@ def generate_embed(ctx, *, title=d.Embed.Empty, kind='rich', description=d.Embed
return embed return embed
def kwargs(args): def kwargs(args):
params = list(args) params = list(args)
lst = 'blacklist' lst = 'blacklist'
@ -145,7 +129,7 @@ def get_kwargs(ctx, args, *, limit=False):
lim = 1 lim = 1
for flag in ('-r', '-rm', '--remove'): for flag in ('-r', '-rm', '--remove'):
if flag in remaining and ctx.author.permissions_in(ctx.channel).manage_messages: if flag in remaining:
rm = True rm = True
remaining.remove(flag) remaining.remove(flag)