1 import irclib
, ircbot
, time
4 from globals import DEBUG
, nick
, server
, port
, autojoin_channels
, commands
, \
5 my_users
, private
, password
6 from safety
import safe
7 from common
import resize
8 from factoids
import nick_re
, is_re
9 from basic_commands
import got_command
12 hal
= ircbot
.SingleServerIRCBot([(server
, port
)], nick
, "Halbot")
13 hal
.connect(server
, port
, nick
)
16 hal
.connection
.privmsg("NickServ", "identify " + password
)
17 hal
.connection
.send_raw("OPER Hal " + password
)
18 hal
.connection
.send_raw("UMODE -hs")
19 for channel
in autojoin_channels
:
20 hal
.connection
.join(channel
)
23 irc
.add_global_handler("whoisuser", whois
.got_whois
)
24 irc
.add_global_handler("nosuchnick", whois
.got_whois
)
25 irc
.add_global_handler("307", whois
.got_registered
)
26 irc
.add_global_handler("whoischannels", whois
.got_channels
)
27 irc
.add_global_handler("whoisoperator", whois
.got_servop
)
28 irc
.add_global_handler("endofwhois", whois
.got_whoend
)
31 def got_invite(conn
, event
):
32 who
= irclib
.nm_to_n(event
.source())
33 where
= event
.arguments()[0]
34 got_command(who
, where
, "do join")
35 got_invite
= safe(got_invite
)
36 irc
.add_global_handler("invite", got_invite
)
39 def got_msg(conn
, event
):
41 if irclib
.mask_matches(event
.source(), user
):
42 if my_users
[user
] == perms
.ban
:
44 msg
= event
.arguments()[0]
45 who
= irclib
.nm_to_n(event
.source())
46 (command
, args
) = resize(msg
.split(" ", 1),2)
47 if command
and command
[0] == "$":
50 if event
.eventtype() == 'privmsg':
53 where
= event
.target()
54 if msg
.count("http://"):
56 got_command(who
, where
, "title implicit", html
.extract_url(msg
))
58 if nick_re
.match(msg
):
59 (me
, command
, args
) = resize(msg
.split(" ", 2),3)
60 if command
in commands
:
62 elif is_re
.search(msg
):
64 args
= is_re
.split(msg
.split(" ", 1)[1], 1)
66 command
= "factoid implicit"
67 args
= msg
.split(" ", 1)[1]
69 if command
.lower() == "forget":
71 elif is_re
.search(msg
):
73 args
= is_re
.split(msg
, 1)
75 command
= "factoid implicit"
77 got_command(who
, where
, command
, args
)
78 got_msg
= safe(got_msg
)
79 irc
.add_global_handler("privmsg", got_msg
)
80 irc
.add_global_handler("pubmsg", got_msg
)
84 cmd
= sys
.stdin
.readline().strip()
86 hal
.connection
.send_raw(cmd
)
89 irc
.process_forever(None)