plugins/dict_plugin.py
author Mikael Berthe <mikael@lilotux.net>
Tue, 01 May 2007 23:59:21 +0200
changeset 17 069f7fd5545d
parent 0 93b25987d3e5
child 31 a707bfd53b26
permissions -rw-r--r--
Fix permissions

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