3 import re |
3 import re |
4 |
4 |
5 WTF_FILE = 'static/wtf.txt' |
5 WTF_FILE = 'static/wtf.txt' |
6 |
6 |
7 def handler_wtf(type, source, parameters): |
7 def handler_wtf(type, source, parameters): |
8 parameters = parameters.rstrip() |
8 parameters = parameters.rstrip(" ?\n") |
9 parameters = parameters.lstrip() |
9 parameters = parameters.lstrip() |
10 |
10 word = parameters.upper() + "\t" |
11 if parameters == '': |
|
12 smsg(type, source, "Gimme an acronym!") |
|
13 return; |
|
14 |
|
15 #acronyms = open(WTF_FILE, 'r').readlines() |
|
16 |
|
17 word = string.upper(parameters)+"\t" |
|
18 reply = "" |
11 reply = "" |
19 |
12 |
20 reader = open(WTF_FILE,'r') |
13 if not parameters: |
21 while 1: |
14 smsg(type, source, "Gimme an acronym!") |
22 line = reader.readline() |
15 return |
23 if not line: |
16 |
24 break |
17 for line in file(WTF_FILE): |
25 if line.startswith(word): |
18 if line.startswith(word): |
26 reply = reply + re.sub("\t+", ": ", line) |
19 reply += re.sub("\t+", ": ", line) |
27 |
20 |
28 if not reply: |
21 if not reply: |
29 reply = "Sorry, I don't know what "+parameters+" means..." |
22 reply = "Sorry, I don't know what " + parameters + " means..." |
30 |
23 |
31 smsg(type, source, reply.rstrip()) |
24 smsg(type, source, reply.rstrip()) |
32 |
25 |
33 register_command_handler(handler_wtf, 'wtf', 0, 'Translates acronyms for you', 'wtf', ['wtf wtf']) |
26 register_command_handler(handler_wtf, 'wtf', 0, |
|
27 'Translates acronyms for you', 'wtf', ['wtf wtf']) |