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(" ?\n") |
8 parameters = parameters.rstrip(" ?\n").lstrip() |
9 parameters = parameters.lstrip() |
|
10 word = parameters.upper() + "\t" |
9 word = parameters.upper() + "\t" |
11 reply = "" |
|
12 |
10 |
13 if not parameters: |
11 if not parameters: |
14 smsg(type, source, "Gimme an acronym!") |
12 smsg(type, source, "Gimme an acronym!") |
15 return |
13 return |
16 |
14 |
17 for line in file(WTF_FILE): |
15 reply = ''.join(line for line in file(WTF_FILE) \ |
18 if line.startswith(word): |
16 if line.startswith(word)) |
19 reply += re.sub("\t+", ": ", line) |
|
20 |
17 |
21 if not reply: |
18 if not reply: |
22 reply = "Sorry, I don't know what " + parameters + " means..." |
19 reply = "Sorry, I don't know what " + parameters + " means..." |
|
20 else: |
|
21 reply= re.sub("\t+", ": ", reply.rstrip()) |
23 |
22 |
24 smsg(type, source, reply.rstrip()) |
23 smsg(type, source, reply) |
25 |
24 |
26 register_command_handler(handler_wtf, 'wtf', 0, |
25 register_command_handler(handler_wtf, 'wtf', 0, |
27 'Translates acronyms for you', 'wtf', ['wtf wtf']) |
26 'Translates acronyms for you', 'wtf', ['wtf wtf']) |