Should be fully separated now. Next up: How many times will it break before it runs?
[halbot.git] / connection.py
blobafe4b449553f8b69a25b46a2323a84f244e4f1fd
1 #!/usr/bin/env python
2 import irclib, ircbot
4 from globals import DEBUG, nick, server, port, autojoin_channels
5 from safety import safe
6 irclib.DEBUG = DEBUG
8 hal = ircbot.SingleServerIRCBot([(server, port)], nick, "Halbot")
9 hal.connect(server, port, nick)
10 time.sleep(0.1)
11 hal.connection.privmsg("NickServ", "identify Orqv)>y!")
12 for channel in autojoin_channels:
13 hal.connection.join(channel)
15 irc = hal.ircobj
17 #@safe
18 def got_invite(conn, event):
19 who = irclib.nm_to_n(event.source())
20 where = event.arguments()[0]
21 got_command(who, where, "do join")
22 got_invite = safe(got_invite)
23 irc.add_global_handler("invite", got_invite)
25 #@safe
26 def got_msg(conn, event):
27 for user in my_users:
28 if irclib.mask_matches(event.source(), user):
29 if my_users[user] == Perms.ban:
30 return
31 msg = event.arguments()[0]
32 who = irclib.nm_to_n(event.source())
33 (command, args) = resize(msg.split(" ", 1),2)
34 if command and command[0] == "$":
35 command = command[1:]
37 if event.eventtype() == 'privmsg':
38 where = private
39 else:
40 where = event.target()
41 if msg.count("http://"):
42 got_command(who, where, "title implicit", html.extract_url(msg))
43 if msg[0] != "$":
44 if nick_re.match(msg):
45 (me, command, args) = resize(msg.split(" ", 2),3)
46 if command in commands:
47 pass
48 elif is_re.search(msg):
49 command = "do is"
50 args = is_re.split(msg.split(" ", 1)[1], 1)
51 else:
52 command = "factoid implicit"
53 args = msg.split(" ", 1)[1]
54 else:
55 if command in commands and commands[command][0] <= Perms.voice:
56 pass
57 elif is_re.search(msg):
58 command = "do is"
59 args = is_re.split(msg, 1)
60 else:
61 command = "factoid implicit"
62 args = msg
63 got_command(who, where, command, args)
64 got_msg = safe(got_msg)
65 irc.add_global_handler("privmsg", got_msg)
66 irc.add_global_handler("pubmsg", got_msg)
68 def debug_console():
69 while DEBUG:
70 cmd = sys.stdin.readline().strip()
71 if cmd:
72 hal.connection.send_raw(cmd)
74 def process_events():
75 irc.process_forever(None)
77 thread.start_new_thread(debug_console, ())
78 thread.start_new_thread(run_reminders, ())