Small improvement to wtf_plugin
authorMikael Berthe <mikael@lilotux.net>
Tue, 01 May 2007 20:18:54 +0200
changeset 12 d79701227a04
parent 11 024fa3e33982
child 13 d3207cb5a777
Small improvement to wtf_plugin
plugins/wtf_plugin.py
--- a/plugins/wtf_plugin.py	Tue May 01 19:16:35 2007 +0200
+++ b/plugins/wtf_plugin.py	Tue May 01 20:18:54 2007 +0200
@@ -5,23 +5,22 @@
 WTF_FILE = 'static/wtf.txt'
 
 def handler_wtf(type, source, parameters):
-	parameters = parameters.rstrip(" ?\n")
-	parameters = parameters.lstrip()
+	parameters = parameters.rstrip(" ?\n").lstrip()
 	word = parameters.upper() + "\t"
-	reply = ""
 
 	if not parameters:
 		smsg(type, source, "Gimme an acronym!")
 		return
 
-	for line in file(WTF_FILE):
-		if line.startswith(word):
-			reply += re.sub("\t+", ": ", line)
+	reply = ''.join(line for line in file(WTF_FILE) \
+		if line.startswith(word))
 
 	if not reply:
 		reply = "Sorry, I don't know what " + parameters + " means..."
+	else:
+		reply= re.sub("\t+", ": ", reply.rstrip())
 
-	smsg(type, source, reply.rstrip())
+	smsg(type, source, reply)
 
 register_command_handler(handler_wtf, 'wtf', 0,
                          'Translates acronyms for you', 'wtf', ['wtf wtf'])