m4pl1mp/plugins/ud_plugin.py
2022-02-02 23:04:48 -06:00

35 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
from irc3.plugins.command import command
import irc3
import requests
import urllib.parse
###########################################################################################
###########################################################################################
@irc3.plugin
class Plugin:
#######################################################################################
#######################################################################################
def __init__(self, bot):
self.bot = bot
#######################################################################################
#######################################################################################
@command(permission='view')
def ud(self, mask, target, args):
"""Urban Dictonary A Term
%%ud <term>...
"""
term = ' '.join(args['<term>'])
term = urllib.parse.quote(term)
r = requests.get('https://api.urbandictionary.com/v0/define?term={}'.format(term))
d = r.json()
term = urllib.parse.unquote(term)
try:
msg = "{} - {} - example: {}".format(term, d.get("list")[0].get("definition"), d.get("list")[0].get("example"))
except:
msg = "{} Term Not Found".format(term)
self.bot.privmsg(target,msg)
#######################################################################################
#######################################################################################
###########################################################################################
###########################################################################################