2 from __future__
import generators
6 from globals import commands
, nick
, factoid_dbs
, locked_dbs
7 from basic_commands
import reply
, troggie
8 from common
import extract_my_db
10 is_re
= re
.compile(" (is|are|was|were)( |$)", re
.IGNORECASE
)
11 nick_re
= re
.compile(nick
+ "[:,] ", re
.IGNORECASE
)
13 def get_fact_dbs(who
, where
):
14 factoids
= extract_my_db(factoid_dbs
, who
, where
, ircbot
.IRCDict
)
15 locked
= extract_my_db(locked_dbs
, who
, where
, ircbot
.IRCDict
)
16 return (factoids
, locked
)
18 def do_is(who
, where
, args
):
19 "Handles implicit factoid setting."
20 (key
, to_be
, garbage
, fact
) = args
21 (factoids
, locked
) = get_fact_dbs(who
, where
)
25 #reply(who, where, "I'm sorry, %s, I'm afraid I can't do that." % who, all=True)
28 factoids
[key
] = (to_be
, fact
)
31 do_is
= troggie(do_is
)
32 commands
['do is'] = (perms
.voice
, do_is
)
34 def forget(who
, where
, args
):
35 "$forget <prompt>: Asks Hal to forget his factoid for the given prompt."
36 (factoids
, locked
) = get_fact_dbs(who
, where
)
39 reply(who
, where
, "I'm sorry, %s, I'm afraid I can't do that." % who
, all
=True)
42 reply(who
, where
, "I forgot %s." % key
)
44 reply(who
, where
, "I don't have anything matching '%s'." % key
)
45 forget
= troggie(forget
)
46 commands
['forget'] = (perms
.voice
, forget
)
48 def force(who
, where
, args
):
49 "$force <prompt> (is/was/are/were) <something>: Sets a factoid, even if it's locked."
50 (factoids
, locked
) = get_fact_dbs(who
, where
)
51 if not is_re
.search(args
):
52 reply(who
, where
, "Syntax: $force a (is/are/was/were) b")
54 (key
, to_be
, garbage
, fact
) = resize(is_re
.split(args
, 1),4)
58 factoids
[key
] = (to_be
, fact
)
61 commands
['force'] = (perms
.op
, force
)
63 def lock(who
, where
, args
):
64 "$lock <prompt>: Locks Hal's factoid for a given prompt."
65 (factoids
, locked
) = get_fact_dbs(who
, where
)
66 if args
.endswith('?'):
68 if not locked
.get(args
):
70 reply(who
, where
, "Done.")
72 reply(who
, where
, "It's already locked.")
73 commands
['lock'] = (perms
.op
, lock
)
75 def unlock(who
, where
, args
):
76 "$unlock <prompt>: Unlocks the factoid for a given prompt."
77 (factoids
, locked
) = get_fact_dbs(who
, where
)
78 if args
.endswith('?'):
82 reply(who
, where
, "Done.")
84 reply(who
, where
, "It's not locked.")
85 commands
['unlock'] = (perms
.op
, unlock
)
87 def factoid(who
, where
, args
, implicit
=False):
88 "$fact <prompt> or $factoid <prompt>: Asks Hal to look up his factoid for the given prompt."
89 (factoids
, locked
) = get_fact_dbs(who
, where
)
90 if args
.endswith('?'):
93 (to_be
, fact
) = factoids
[args
]
94 if not implicit
and fact
.count("$who"):
98 if lfact
.startswith("<"):
99 if lfact
.startswith("<raw>"):
100 response
= fact
[5:].lstrip()
101 elif lfact
.startswith("<reply>"):
102 response
= fact
[7:].lstrip()
103 elif lfact
.startswith("<action>"):
104 response
= "\x01ACTION %s\x01" % fact
[8:].lstrip()
106 response
= "I hear that %s %s %s" % (args
, to_be
, fact
)
107 response
= response
.replace("$who", who
)
108 reply(who
, where
, response
, all
=implicit
)
110 reply(who
, where
, "I don't have anything matching '%s'." % args
)
111 commands
['fact'] = (perms
.voice
, factoid
)
112 commands
['factoid'] = (perms
.voice
, factoid
)
114 def factoid_implicit(who
, where
, args
):
115 "Implicit form of $fact[oid]."
116 factoid(who
, where
, args
, implicit
=True)
117 factoid_implicit
= troggie(factoid_implicit
)
118 commands
['factoid implicit'] = (perms
.voice
, factoid_implicit
)