Merge pull request #4 from bobloy/sayurl

Sayurl Initial
pull/6/head
bobloy 7 years ago committed by GitHub
commit d943b52880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,6 +14,7 @@ Cog Function
| leaver | **Incomplete** | <details><summary>Send a message in a channel when a user leaves the server</summary>Not yet ported to v3</details> |
| lseen | **Alpha** | <details><summary>Track when a member was last online</summary>Alpha release, please report bugs</details> |
| reactrestrict | **Alpha** | <details><summary>Removes reactions by role per channel</summary>A bit clunky, but functional</details> |
| sayurl | **Alpha** | <details><summary>Convert any URL into text and post to discord</summary>No error checking and pretty spammy</details> |
| secrethitler | **Incomplete** | <details><summary>Play the Secret Hitler game</summary>Concept, no work done yet</details> |
| stealemoji | **Alpha** | <details><summary>Steals any custom emoji it sees in a reaction</summary>Some planned upgrades for server generation</details> |
| werewolf | **Alpha** | <details><summary>Play the classic party game Werewolf within discord</summary>Another massive project currently being developed, will be fully customizable</details> |

@ -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…
Cancel
Save