author | Mikael Berthe <mikael@lilotux.net> |
Wed, 02 May 2007 14:00:55 +0200 | |
changeset 21 | 2fea9969b088 |
parent 17 | 069f7fd5545d |
child 23 | f34555473aaf |
permissions | -rw-r--r-- |
0
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
1 |
#$ neutron_plugin 01 |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
2 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
3 |
import re |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
4 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
5 |
WTF_FILE = 'static/wtf.txt' |
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
6 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
7 |
def handler_wtf(type, source, parameters): |
12
d79701227a04
Small improvement to wtf_plugin
Mikael Berthe <mikael@lilotux.net>
parents:
10
diff
changeset
|
8 |
parameters = parameters.rstrip(" ?\n").lstrip() |
10 | 9 |
word = parameters.upper() + "\t" |
0
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
10 |
|
10 | 11 |
if not parameters: |
21
2fea9969b088
WTF: Do not answer in public places when no answer was found
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
12 |
if type == 'private': |
2fea9969b088
WTF: Do not answer in public places when no answer was found
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
13 |
smsg(type, source, "Gimme an acronym!") |
10 | 14 |
return |
15 |
||
12
d79701227a04
Small improvement to wtf_plugin
Mikael Berthe <mikael@lilotux.net>
parents:
10
diff
changeset
|
16 |
reply = ''.join(line for line in file(WTF_FILE) \ |
d79701227a04
Small improvement to wtf_plugin
Mikael Berthe <mikael@lilotux.net>
parents:
10
diff
changeset
|
17 |
if line.startswith(word)) |
0
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
18 |
|
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
19 |
if not reply: |
21
2fea9969b088
WTF: Do not answer in public places when no answer was found
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
20 |
if type == 'private': |
2fea9969b088
WTF: Do not answer in public places when no answer was found
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
21 |
reply = "Sorry, I don't know what " + parameters + \ |
2fea9969b088
WTF: Do not answer in public places when no answer was found
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
22 |
" means..." |
2fea9969b088
WTF: Do not answer in public places when no answer was found
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
23 |
else: |
2fea9969b088
WTF: Do not answer in public places when no answer was found
Mikael Berthe <mikael@lilotux.net>
parents:
17
diff
changeset
|
24 |
return |
12
d79701227a04
Small improvement to wtf_plugin
Mikael Berthe <mikael@lilotux.net>
parents:
10
diff
changeset
|
25 |
else: |
d79701227a04
Small improvement to wtf_plugin
Mikael Berthe <mikael@lilotux.net>
parents:
10
diff
changeset
|
26 |
reply= re.sub("\t+", ": ", reply.rstrip()) |
0
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
27 |
|
12
d79701227a04
Small improvement to wtf_plugin
Mikael Berthe <mikael@lilotux.net>
parents:
10
diff
changeset
|
28 |
smsg(type, source, reply) |
0
93b25987d3e5
Initial Mercurial repository
Mikael Berthe <mikael@lilotux.net>
parents:
diff
changeset
|
29 |
|
10 | 30 |
register_command_handler(handler_wtf, 'wtf', 0, |
31 |
'Translates acronyms for you', 'wtf', ['wtf wtf']) |