dict: We can specify the Dict database now
authorMikael Berthe <mikael@lilotux.net>
Thu, 03 May 2007 19:02:04 +0200
changeset 31 a707bfd53b26
parent 30 33af762962f1
child 32 dcb1b0459f1c
dict: We can specify the Dict database now Usage: "dict name" or "dict [dbname] word"
plugins/dict_plugin.py
--- a/plugins/dict_plugin.py	Thu May 03 18:56:34 2007 +0200
+++ b/plugins/dict_plugin.py	Thu May 03 19:02:04 2007 +0200
@@ -2,14 +2,22 @@
 
 import DICT
 import urllib
+import re
 
 def handler_dict_define(type, source, parameters):
 	dc = DICT.DictConnection('dict.org')
+	db = "*"
+        parameters = parameters.strip()
+        m = re.match(r"\[([\w\d-]+)\] ", parameters)
+	if m:
+		db = m.group(1)
+		parameters = parameters[parameters.find(' ')+1:]
 	try:
-		results = dc.get_definition(parameters.strip())
+		results = dc.get_definition(parameters, db)
 		if len(results):
 			#reply = string.join(results[0], '\n')
-			reply = 'http://www.dict.org/bin/Dict?Form=Dict1&Query=' + urllib.quote(parameters) + '&Strategy=*&Database=*'
+			#reply = 'http://www.dict.org/bin/Dict?Form=Dict1&Query=' + urllib.quote(parameters) + '&Strategy=*&Database=*'
+			reply = ''
 			for result in results[:3]:
 				reply += '\n\n' + string.join(result[:8], '\n')[:500][4:]
 				if len(result) > 8:
@@ -20,6 +28,8 @@
 	except:
 		raise
 		reply = 'Error'
-	smsg(type, source, reply.rstrip())
+	smsg(type, source, reply.strip())
 
-register_command_handler(handler_dict_define, 'dict', 0, 'Defines a word using the DICT protocol.', 'dict <word>', ['dict jabber'])
+register_command_handler(handler_dict_define, 'dict', 0,
+                         'Defines a word using the DICT protocol.',
+                         'dict [db] <word>', ['dict jabber'])