-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunbot.py
48 lines (36 loc) · 1.07 KB
/
runbot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys
from irc.client import ServerConnectionError
from cardreader import card_lookup
import argparse
import itertools
import irc.client
import irc.logging
target = "#hmrs"
server = "localhost"
port = 6667
nickname = "AJBot"
call_name = "!mtg"
def on_connect(connection, event):
connection.join(target)
def on_disconnect(connection, event):
raise SystemExit()
def on_pubmsg(connection, event):
line = event.arguments[0]
if line.startswith(call_name):
empty, arguments = line.split(call_name)
card_name = arguments.strip()
response = card_lookup(card_name)
connection.privmsg(event.target, response)
def main():
client = irc.client.IRC()
try:
c = client.server().connect(server, port, nickname)
except irc.client.ServerConnectionError:
print(sys.exc_info()[1])
raise SystemExit(1)
c.add_global_handler("welcome", on_connect)
c.add_global_handler("disconnect", on_disconnect)
c.add_global_handler("pubmsg", on_pubmsg)
client.process_forever()
if __name__ == "__main__":
main()