plugins/dict_plugin.py
author Mikael Berthe <mikael@lilotux.net>
Tue, 01 May 2007 23:17:36 +0200
changeset 15 c7bc5fcabc81
parent 0 93b25987d3e5
child 17 069f7fd5545d
permissions -rwxr-xr-x
Update wtf DB

#$ 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'])