1 import irclib
, ircbot
, time
4 from globals import DEBUG
, nick
, server
, port
, autojoin_channels
, commands
, \
5 my_users
, private
, password
, kill_channels
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
)
21 for channel
in kill_channels
:
22 hal
.connection
.join(channel
)
25 irc
.add_global_handler("whoisuser", whois
.got_whois
)
26 irc
.add_global_handler("nosuchnick", whois
.got_whois
)
27 irc
.add_global_handler("307", whois
.got_registered
)
28 irc
.add_global_handler("whoischannels", whois
.got_channels
)
29 irc
.add_global_handler("whoisoperator", whois
.got_servop
)
30 irc
.add_global_handler("endofwhois", whois
.got_whoend
)
31 irc
.add_global_handler("userhost", whois
.got_userhost
)
34 def got_invite(conn
, event
):
35 who
= irclib
.nm_to_n(event
.source())
36 where
= event
.arguments()[0]
37 got_command(who
, where
, "do join")
38 got_invite
= safe(got_invite
)
39 irc
.add_global_handler("invite", got_invite
)
41 def flood_protect(who
, where
, is_first
):
43 hal
.connection
.privmsg(where
, "The Definite Annoyance eViction Engine (D.A.V.E.) project is proud to present: Flood protection!")
44 from panic
import do_kickban
45 user
= irclib
.nm_to_n(who
)
46 whois
.userhost_callbacks
[user
] = (do_kickban
, ("Hal", where
, "Flooding."))
47 hal
.connection
.userhost([user
])
52 def got_msg(conn
, event
):
54 if irclib
.mask_matches(event
.source(), user
):
55 if my_users
[user
] == perms
.ban
:
57 msg
= event
.arguments()[0]
58 who
= irclib
.nm_to_n(event
.source())
61 (command
, args
) = resize(msg
.split(" ", 1),2)
62 if command
and command
[0] == "$":
65 if event
.eventtype() == 'privmsg':
68 where
= event
.target()
69 last_message_info
= last_messages
.setdefault(where
, ["",0])
70 if last_message_info
[0] == msg
:
71 last_message_info
[1] += 1
72 if last_message_info
[1] > 3:
73 flood_protect(event
.source(), where
, last_message_info
[1] == 4)
75 if last_message_info
[1] > 3:
76 hal
.connection
.privmsg(where
, "D.A.V.E. complete. Have a nice day!")
77 last_message_info
[0] = msg
78 last_message_info
[1] = 1
80 if msg
.count("http://"):
82 got_command(who
, where
, "title implicit", html
.extract_url(msg
))
84 if nick_re
.match(msg
):
85 (me
, command
, args
) = resize(msg
.split(" ", 2),3)
86 if command
in commands
:
88 elif is_re
.search(msg
):
90 args
= is_re
.split(msg
.split(" ", 1)[1], 1)
92 command
= "factoid implicit"
93 args
= msg
.split(" ", 1)[1]
95 if command
.lower() == "forget":
97 elif is_re
.search(msg
):
99 args
= is_re
.split(msg
, 1)
101 command
= "factoid implicit"
103 got_command(who
, where
, command
, args
)
104 got_msg
= safe(got_msg
)
105 irc
.add_global_handler("privmsg", got_msg
)
106 irc
.add_global_handler("pubmsg", got_msg
)
110 cmd
= sys
.stdin
.readline().strip()
112 hal
.connection
.send_raw(cmd
)
114 def process_events():
115 irc
.process_forever()