searchbot-discord/extensions/utils/online.py

39 lines
935 B
Python
Raw Normal View History

2020-03-02 23:37:34 +00:00
# -*- coding: utf-8 -*-
# tacibot online util
# Provides utils for various online tools.
'''Online File'''
2020-03-03 04:08:20 +00:00
import discord
2020-03-02 23:37:34 +00:00
class Online():
2020-03-03 04:08:20 +00:00
"""Provides various online utilities for your bot."""
2020-03-02 23:37:34 +00:00
def __init__(self, bot):
self.bot = bot
self.request = bot.request
async def hastebin(self, string):
"""Posts a string to hastebin."""
url = "https://hasteb.in/documents"
2020-03-02 23:37:34 +00:00
data = string.encode('utf-8')
async with self.request.post(url=url, data=data) as haste_response:
haste_key = (await haste_response.json())['key']
haste_url = f"http://hasteb.in/{haste_key}"
2020-03-02 23:37:34 +00:00
return haste_url
2020-03-03 04:08:20 +00:00
def get_webhook(self, url: str):
"""Easily gets a webhook from a url."""
return discord.Webhook.from_url(
url,
adapter=discord.AsyncWebhookAdapter(self.request)
)
2020-03-02 23:37:34 +00:00
def setup(bot):
bot.online = Online(bot)