commit
d943b52880
@ -0,0 +1,5 @@
|
||||
from .sayurl import SayUrl
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(SayUrl(bot))
|
@ -0,0 +1,19 @@
|
||||
{
|
||||
"author": [
|
||||
"Bobloy"
|
||||
],
|
||||
"bot_version": [
|
||||
3,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"description": "Convert any website into text and post it in chat",
|
||||
"hidden": true,
|
||||
"install_msg": "Thank you for installing SayUrl",
|
||||
"requirements": [],
|
||||
"short": "Convert URL to text",
|
||||
"tags": [
|
||||
"bobloy",
|
||||
"tools"
|
||||
]
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
import aiohttp
|
||||
import html2text
|
||||
from discord.ext import commands
|
||||
from redbot.core import Config, RedContext
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.utils.chat_formatting import pagify
|
||||
|
||||
|
||||
async def fetch_url(session, url):
|
||||
with aiohttp.Timeout(20):
|
||||
async with session.get(url) as response:
|
||||
assert response.status == 200
|
||||
return await response.text()
|
||||
|
||||
|
||||
class SayUrl:
|
||||
"""
|
||||
V3 Cog Template
|
||||
"""
|
||||
|
||||
def __init__(self, bot: Red):
|
||||
self.bot = bot
|
||||
self.config = Config.get_conf(self, identifier=9811198108111121, force_registration=True)
|
||||
default_global = {}
|
||||
default_guild = {}
|
||||
|
||||
self.config.register_global(**default_global)
|
||||
self.config.register_guild(**default_guild)
|
||||
|
||||
@commands.command()
|
||||
async def sayurl(self, ctx: RedContext, url):
|
||||
"""
|
||||
Converts a URL to something readable
|
||||
|
||||
:param url:
|
||||
:return:
|
||||
"""
|
||||
|
||||
h = html2text.HTML2Text()
|
||||
h.ignore_links = True
|
||||
# h.ignore_images = True
|
||||
h.images_to_alt = True
|
||||
|
||||
h.escape_snob = True
|
||||
h.skip_internal_links = True
|
||||
h.ignore_tables = True
|
||||
h.single_line_break = True
|
||||
h.mark_code = True
|
||||
h.wrap_links = True
|
||||
h.ul_item_mark = '-'
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
site = await fetch_url(session, url)
|
||||
|
||||
for page in pagify(h.handle(site)):
|
||||
await ctx.send(page)
|
Loading…
Reference in new issue