plugins/wtf_plugin.py
author Mikael Berthe <mikael@lilotux.net>
Tue, 01 May 2007 13:33:46 +0200
changeset 4 3454a7b7c818
parent 0 93b25987d3e5
child 10 7de2fee2986f
permissions -rwxr-xr-x
wtf_plugin: fix behaviour when a parameter is missing

#$ neutron_plugin 01

import re

WTF_FILE = 'static/wtf.txt'

def handler_wtf(type, source, parameters):
	parameters = parameters.rstrip()
	parameters = parameters.lstrip()

	if parameters == '':
		smsg(type, source, "Gimme an acronym!")
		return;

	#acronyms = open(WTF_FILE, 'r').readlines()

	word = string.upper(parameters)+"\t"
	reply = ""

	reader = open(WTF_FILE,'r')
	while 1:
		line = reader.readline()
		if not line:
			break
		if line.startswith(word):
			reply = reply + re.sub("\t+", ": ", line)

	if not reply:
		reply = "Sorry, I don't know what "+parameters+" means..."

	smsg(type, source, reply.rstrip())

register_command_handler(handler_wtf, 'wtf', 0, 'Translates acronyms for you', 'wtf', ['wtf wtf'])