import discord
import asyncio
import urllib.request
import requests
from discord.ext import commands
class ShortenUrl:
def __init__(self, bot):
self.bot = bot
@commands.command(pass_context=True)
"""
Checks if the user exists in the database and returns a shortened link on success.
Database format is {"USERID":"APIKEY","117450987848990720":"B3Nm9g8L?s="}
"""
async def ouo(self, ctx):
with open('data.json') as data_file:
data_loaded = json.load(data_file)
if data_loaded.get(ctx.message.author.id):
url = ("http://ouo.io/api/" + data_loaded.get(ctx.message.author.id) + ctx.message.content)
handle = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
html = urllib.request.urlopen(handle).read().decode('utf-8')
await self.bot.say("Shortened: " + html)
else:
await self.bot.say("nope")
def setup(bot):
bot.add_cog(ShortenUrl(bot))
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"text\/x-go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"mysql","xml":"xml","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","ecmascript":"javascript","groovy":"text\/x-groovy","haskell":"text\/x-haskell","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mysql":"mysql","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"plsql","properties":"text\/x-properties","scheme":"text\/x-scheme","vb":"text\/vbscript","vbnet":"text\/vbscript","verilog":"text\/x-verilog","yaml":"text\/x-yaml"}