$onr, $xkcd
[halbot.git] / globals.py
blob8e66943d9cc75e906b9f944820122f51060f5437
1 import atexit, bz2, threadsafe_sched, ircbot, cPickle, perms
3 DEBUG = False
4 nick = "Hal"
5 server = "localhost"
6 port = 6667
7 autojoin_channels = ("#casualgameplay", "#hal")
9 # Dummy where entry for privmsgs.
10 private = "p"
12 scheduler = threadsafe_sched.scheduler()
14 commands = {}
16 from ircbot import IRCDict
17 my_users = IRCDict()
18 factoid_dbs = IRCDict()
19 locked_dbs = IRCDict()
20 reminder_dbs = IRCDict()
21 subscription_dbs = IRCDict()
22 poke_via_msg = IRCDict()
23 unlower = {}
25 SAVE_VERSION = 4
26 from cPickle import dumps as pickle, loads as depickle
27 import perms
28 try:
29 db = open("hal.db")
30 zipped = db.read()
31 pickled = bz2.decompress(zipped)
32 (version, data) = depickle(pickled)
33 if version == SAVE_VERSION:
34 (my_users, factoid_dbs, locked_dbs, reminder_dbs, subscription_dbs, \
35 unlower, poke_via_msg) = data
36 elif version == 3:
37 (my_users, factoid_dbs, locked_dbs, reminder_dbs, subscription_dbs, \
38 unlower) = data
39 else:
40 sys.exit("Unrecognized database version.")
41 db.close()
42 del db, zipped, pickled
43 except IOError:
44 pass
46 def save(who=None, where=None, args=None):
47 pickled = pickle((
48 SAVE_VERSION,
49 (my_users, factoid_dbs, locked_dbs, reminder_dbs,
50 subscription_dbs, unlower, poke_via_msg)
52 zipped = bz2.compress(pickled)
53 db = open("hal.db", "w")
54 db.write(zipped)
55 db.close()
56 if who:
57 from basic_commands import reply
58 reply(who, where, "Database saved.")
60 atexit.register(save)
62 commands['save'] = (perms.ircop, save)