chmullig avatar chmullig committed 1c24b0c

Adding pipe as a weapon (for Broken Pipe. Get it? I crack myself up.) and urban dictionary lookup

Comments (0)

Files changed (2)

 		return 'Wikipedia says: ' + res
+@command("urbandict", aliases=("urb", 'ud', 'urbandictionary', 'urbandefine', 'urbandef', 'urbdef'), doc="Define a word with Urban Dictionary")
+def urbandefit(client, event, channel, nick, rest):
+        word = rest.strip()
+        newword, res = urbanlookup(word)
+        if res is None:
+                return "Arg!  I didn't find a definition for that."
+        else:
+                newword = plaintext(newword)
+                res = plaintext(res)
+                return 'Urban Dictionary says %s: %s' % (newword, res)
 @command("acronym", aliases=("ac",), doc="Look up an acronym")
 def acit(client, event, channel, nick, rest):
 'cocktail sword',
 weapon_adjs = [
 wiki_exp = re.compile(r"(.*?)en\.wikipedia\.org\/wiki\/", re.MULTILINE | re.DOTALL)
 def_exp = re.compile(r"<li>([^<]+)", re.MULTILINE)
+urbd_exp = re.compile(r"<td class='word'>(.+?)^</td>$(?:.+?)<div class='definition'>(.+?)</div>", re.MULTILINE | re.DOTALL )
 def lookup(word):
 	'''Gets a wikipedia summary for a word.
 	show_def = all_defs[-1].group(1)
 	return show_def.strip()
+def urbanlookup(word):
+        '''Gets a Urban Dictionary summary for a word.
+        '''
+        word = urllib.quote_plus(word)
+        html = get_html('' % word)
+        match =
+        if not match:
+                return None, None
+        word, definition = match.groups()
+        definition = ' '.join(definition.replace('<br/>', '').splitlines())
+        return word.strip(), definition.strip()
 html_strip = re.compile(r'<[^>]+?>')
 NUM_ACS = 3
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.