-
Notifications
You must be signed in to change notification settings - Fork 2
/
urbandict.py
27 lines (24 loc) · 987 Bytes
/
urbandict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import requests
import json
import willie
import random
@willie.module.commands('ud', 'urb')
def urbandict(phenny, input):
""".urb <word> - Search Urban Dictionary for a definition."""
word = input.group(2)
if not word:
return
response = requests.get("http://api.urbandictionary.com/v0/define", params={"term": word})
data = response.json()
if data['result_type'] == 'no_results':
phenny.say("No results found for {0}".format(word))
return
result = data['list'][0]
response = "{0}: {1} - {2}".format(word, result['definition'].strip()[:256], result["permalink"])
phenny.say(response)
@willie.module.commands('udrand', 'urbrand')
def udrand(bot, trigger):
data = requests.get("http://api.urbandictionary.com/v0/random").json()
result = random.choice(data["list"])
response = "{0}: {1} - {2}".format(result['word'], result['definition'].strip()[:256], result["permalink"])
bot.say(response)