1 from __future__
import generators
3 from irclib
import irc_lower
6 from globals import commands
, private
7 from safety
import safe_call
8 from common
import get_timestamp
, resize
12 def got_command(who
, where
, command
, args
=""):
13 from connection
import hal
14 if not command
in commands
:
15 command
= 'raise error'
16 args
= "I don't understand that."
17 waiting
= waiting_commands
.get(who
, [])
19 (required_perms
, do_it
, wants_perms
) = resize(commands
[command
], 3)
20 if where
== private
and required_perms
<= perms
.owner
:
22 safe_call(do_it
, (who
, where
, args
, perms
.owner
))
24 safe_call(do_it
, (who
, where
, args
))
25 elif not wants_perms
and required_perms
<= perms
.voice \
26 and where
in hal
.channels
:
27 if irc_lower(who
) in whois
.voice_or_better(where
):
28 safe_call(do_it
, (who
, where
, args
))
32 waiting_commands
[who
] = [(where
, command
, args
)]
33 hal
.connection
.whois((who
,))
35 waiting
.append((where
, command
, args
))
37 def do_commands(who
, info
):
38 for where
, command
, args
in waiting_commands
[who
]:
39 actual_perms
= perms
.get_perms(who
, where
, info
)
40 if command
not in commands
:
41 command
= 'raise error'
42 args
= "I don't understand that."
43 (required_perms
, do_it
, wants_perms
) = resize(commands
[command
], 3)
44 if required_perms
<= actual_perms
:
46 safe_call(do_it
, (who
, where
, args
))
48 safe_call(do_it
, (who
, where
, args
, actual_perms
))
49 elif required_perms
> perms
.voice
<= actual_perms
:
50 reply(who
, where
, "I'm sorry, %s, I'm afraid I can't do that." % who
,
52 waiting_commands
[who
] = []
53 whois
.callback
= do_commands
55 def reply(who
, where
, what
, all
=False):
56 from connection
import hal
58 hal
.connection
.privmsg(who
, what
)
60 hal
.connection
.privmsg(where
, what
)
62 hal
.connection
.privmsg(where
, "%s: %s" % (who
, what
))
64 commands
['raise error'] = (perms
.voice
, reply
)
66 def ping(who
, where
, args
):
67 reply(who
, where
, "Pong!")
68 commands
['ping'] = (perms
.voice
, ping
)
70 class TestException(Exception): pass
72 def error(who
, where
, args
):
73 raise TestException
, str(args
)
74 commands
['error'] = (perms
.ircop
, error
)
76 def join(who
, where
, args
):
77 from connection
import hal
78 hal
.connection
.join(where
)
79 commands
['do join'] = (perms
.op
, join
)
81 def shutdown(who
, where
, args
):
82 from connection
import hal
83 hal
.connection
.quit("Daisy, daaaisy...")
85 commands
['shutdown'] = (perms
.ircop
, shutdown
)
87 def get_time(who
, where
, args
):
88 reply(who
, where
, "Current time is: " + get_timestamp())
89 commands
['time'] = (perms
.voice
, get_time
)
91 def ignore(who
, where
, args
):
92 if args
.lower().strip() == "list":
93 banlist
= ", ".join([user
for user
in my_users
if my_users
[user
] == perms
.ban
])
94 reply(who
, where
, "Currently ignoring: %s" % banlist
)
96 if not weak_mask_re
.search(args
):
97 reply(who
, where
, "Please give a full nick!user@host mask.")
99 my_users
[args
] = perms
.ban
100 reply(who
, where
, "Done.")
101 commands
['ignore'] = (perms
.ircop
, ignore
)
103 def unignore(who
, where
, args
):
104 if args
in my_users
and my_users
[args
] == perms
.ban
:
105 my_users
[args
] = perms
.none
106 reply(who
, where
, "Done.")
108 reply(who
, where
, "I wasn't ignoring them.")
109 commands
['unignore'] = (perms
.ircop
, unignore
)
111 def tell_commands(who
, where
, args
, user_perms
):
112 command_list
= [command
for command
in commands
113 if " " not in command
114 if commands
[command
][0] <= user_perms
]
116 commands_str
= ", ".join(command_list
)
118 "Available commands at your permission level: " + commands_str
)
119 commands
['commands'] = (perms
.voice
, tell_commands
, "I want perms.")
122 def continue_if_no_troggie(who
, where
, *args
, **kwargs
):
123 from connection
import hal
124 if where
in hal
.channels
:
125 chan
= hal
.channels
[where
]
126 if "troggie" not in chan
.userdict
:
127 func(who
, where
, *args
, **kwargs
)
128 return continue_if_no_troggie