diff options
author | romangraef <romangraef@loves.dicksinhisan.us> | 2018-10-14 09:38:05 +0200 |
---|---|---|
committer | romangraef <romangraef@loves.dicksinhisan.us> | 2018-10-14 09:38:05 +0200 |
commit | 2e09fe0b572d36367f448b008d6121e6a6436329 (patch) | |
tree | 90de2085eb9dc24d7f542c2356603cd4a13fce04 /modules | |
parent | 8282428a268f87a0a4d68790521e57904826309e (diff) | |
download | notaselfbotv2finalforsure-master.tar.gz notaselfbotv2finalforsure-master.tar.bz2 notaselfbotv2finalforsure-master.zip |
Diffstat (limited to 'modules')
-rw-r--r-- | modules/dump.py | 14 | ||||
-rw-r--r-- | modules/link.py | 39 |
2 files changed, 51 insertions, 2 deletions
diff --git a/modules/dump.py b/modules/dump.py index 05d10a9..183dba3 100644 --- a/modules/dump.py +++ b/modules/dump.py @@ -1,3 +1,4 @@ +import inspect import re from asyncio import sleep from functools import wraps @@ -5,7 +6,8 @@ from typing import List from discord import User, Embed, Profile, Guild, Member, Permissions, Message, Role, Emoji, TextChannel from discord.ext.commands import Bot, command, Context as CommandContext, Context - +from discord.ext.commands import Paginator +from datetime import datetime async def _context_react(self: Context, emoji): await self.message.add_reaction(emoji) @@ -39,6 +41,14 @@ class DumpCog(object): self.bot = bot @command() + async def show_off(self, ctx: CommandContext, name: str): + paginator = Paginator(prefix="```py") + for line in inspect.getsource(self.bot.get_command(name).callback).split('\n'): + paginator.add_line(line.replace("`", "`\u200B")) + for page in paginator.pages: + await ctx.send(page) + + @command() async def raw(self, ctx: CommandContext, message: Message): content: str = message.content escaped = content.replace('```', '``\u200B`') @@ -67,7 +77,7 @@ class DumpCog(object): role: Role = roles[0] if len(roles) > 0 else None embed = Embed(title=f"ID: {snowflake}") - embed.add_field(name="When", value=str(when)) + embed.add_field(name="When", value=str(when) + ' / ' + str(datetime.fromtimestamp(when))) embed.add_field(name="Worker", value=str(worker)) embed.add_field(name="Process", value=str(process)) embed.add_field(name="Increment", value=str(increment)) diff --git a/modules/link.py b/modules/link.py new file mode 100644 index 0000000..68f56e1 --- /dev/null +++ b/modules/link.py @@ -0,0 +1,39 @@ +from aiohttp import ClientSession, ClientResponse +from bs4 import BeautifulSoup +from discord import Embed +from discord.ext.commands import Bot, command, Context + + +class Link(object): + def __init__(self, bot: Bot): + self.bot = bot + + @command(aliases=['unshorten']) + async def retrace(self, ctx: Context, *, link: str): + found = set() + history = [] + async with ClientSession() as sess: + while link not in found: + async with sess.get(link, allow_redirects=False) as res: + res: ClientResponse + found.add(res.url) + if res.status // 100 == 3: + history.append(('header', res.url)) + link = res.headers['Location'] + continue + soup = BeautifulSoup((await res.text()), 'html5lib') + el = soup.find('meta', attrs={'http-equiv': 'refresh'}) + if el: + history.append(('meta', res.url)) + link = el['content'].split('=')[1] + continue + break + text = '\n'.join([f'{re[0]} - {re[1]}' for re in history] + [f'Final - {link}']) + await ctx.send( + embed=Embed( + description=text + )) + + +def setup(bot: Bot): + bot.add_cog(Link(bot)) |