plugins/dict_plugin.py
changeset 0 93b25987d3e5
child 17 069f7fd5545d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/dict_plugin.py	Tue May 01 12:26:35 2007 +0200
@@ -0,0 +1,25 @@
+#$ neutron_plugin 01
+
+import DICT
+import urllib
+
+def handler_dict_define(type, source, parameters):
+	dc = DICT.DictConnection('dict.org')
+	try:
+		results = dc.get_definition(parameters.strip())
+		if len(results):
+			#reply = string.join(results[0], '\n')
+			reply = 'http://www.dict.org/bin/Dict?Form=Dict1&Query=' + urllib.quote(parameters) + '&Strategy=*&Database=*'
+			for result in results[:3]:
+				reply += '\n\n' + string.join(result[:8], '\n')[:500][4:]
+				if len(result) > 8:
+					reply += ' . . .'
+			reply = reply.replace('\n\n\n', '\n\n')
+		else:
+			reply = 'No Results'
+	except:
+		raise
+		reply = 'Error'
+	smsg(type, source, reply.rstrip())
+
+register_command_handler(handler_dict_define, 'dict', 0, 'Defines a word using the DICT protocol.', 'dict <word>', ['dict jabber'])