5
""" this is where the config dict lives .. use pickle to persist config data
6
.. use this pickle on start until the config file has changed """
8
__copyright__ = 'this file is in the public domain'
10
from gozerbot.datadir import datadir
11
import os, pickle, subprocess
14
ver = 'GOZERBOT 0.8.1.1 RELEASE'
16
def diffdict(dictfrom, dictto):
17
""" check for differences between two dicts """
19
for i in dictto.iteritems():
20
if dictfrom.has_key(i[0]):
21
if dictfrom[i[0]] != i[1]:
22
temp.setdefault(i[0], i[1])
24
temp.setdefault(i[0], i[1])
29
""" config object is a dict """
31
def __init__(self, ddir, *args, **kw):
32
dict.__init__(self, *args, **kw)
34
self['dbtype'] = 'mysql'
36
def __getitem__(self, item):
37
""" get config item .. return None if not available"""
38
if not self.has_key(item):
41
return dict.__getitem__(self, item)
43
def set(self, item, value):
44
""" set a config item """
45
dict.__setitem__(self, item, value)
49
""" load the config file """
52
# first do reload of the data/config file
54
# see if there is a configpickle
56
picklemodtime = os.stat(self.dir + os.sep + 'configpickle')[8]
57
configpickle = open(self.dir + os.sep + 'configpickle', 'r')
58
frompickle = pickle.load(configpickle)
64
# see if data/config is more recent than the configpickle
65
configmodtime = os.stat(self.dir + os.sep + 'config')[8]
66
if picklemodtime and picklemodtime > configmodtime:
67
# if so update the config dict with the pickled data
68
# a = diffdict(self, frompickle)
69
self.update(frompickle)
72
self['version'] = ver + ' ' + self['dbtype'].upper()
77
""" save config data to pickled file """
78
picklefile = open(self.dir + os.sep + 'configpickle', 'w')
79
pickle.dump(self, picklefile)
83
""" use execfile to reload data/config """
85
execfile(self.dir + os.sep + 'config', self)
90
del self['__builtins__']
95
self['version'] = ver + ' ' + self['dbtype'].upper()
99
def defaultconfig(self):
100
""" init default config values if no config file is found """
101
self['loglevel'] = 100
102
self['jabberenable'] = 0
103
self['ircdisable'] = 0
104
self['stripident'] = 1
105
self['owneruserhost'] = ['bart@127.0.0.1', ]
106
self['nick'] = 'gozerbot'
107
self['server'] = 'localhost'
110
self['username'] = 'gozerbot'
111
self['realname'] = 'GOZERBOT'
112
self['defaultcc'] = "!"
113
self['nolimiter'] = 0
114
self['quitmsg'] = 'http://gozerbot.org'
118
self['mainbotname'] = 'main'
119
self['addonallow'] = 0
120
self['allowedchars'] = []
122
configtxt = """# config
126
__copyright__ = 'this file is in the public domain'
128
# gozerdata dir umask
131
# logging level .. the higher this value is the LESS the bot logs
137
jabberowner = 'bartholo@localhost'
138
jabberhost = 'localhost'
139
jabberuser = 'gozerbot@localhost'
147
# stripident .. enable stripping of ident from userhost
150
# userhost of owner .. make sure this matches your client's userhost
151
# if it doesn't match you will get an userhost denied message when you
152
# try to send commands to the bot
153
owneruserhost = ['bart@127.0.0.1', ]
155
# the nick the bot tries to use, only used if no nick is set
156
# otherwise the bot will use the last nick used by the !nick command
160
#alternick = 'gozerbot2'
162
# server to connect to
165
# irc port to connect to
168
# ircd password for main bot
174
# bindhost .. uncomment and edit to use
175
#bindhost = 'localhost'
178
username = 'gozerbot'
181
realname = 'GOZERBOT'
183
# default control character
190
quitmsg = 'http://gozerbot.org'
192
# nickserv .. set pass to enable nickserv ident
194
nickservtxt = ['set unfiltered on', ]
196
## if you want to use a database:
198
dbenable = 0 # set to 1 to enable
199
dbtype = 'mysql' # one of mysql or sqlite
204
dboldstyle = False # set to True if mysql database is <= 4.1
206
## if you want to use udp:
209
udp = 0 # set to 1 to enable
212
udphost = 'localhost'
214
udpmasks = ['192.168*', ]
215
udpallow = ['127.0.0.1', ]
216
udpallowednicks = ['#dunkbots', 'dunker']
217
udppassword = 'mekker'
218
udpseed = "" # set this to 16 char wide string if you want to encrypt the data
219
udpstrip = 1 # strip all chars < char(32)
220
udpsleep = 0 # sleep in sendloop .. can be used to delay packet traffic
223
tcp = 0 # set to 1 to enable
226
tcphost = 'localhost'
228
tcpmasks = ['192.168*', ]
229
tcpallow = ['127.0.0.1', ]
230
tcpallowednicks = ['#dunkbots', 'dunker', 'dunker@jabber.xs4all.nl']
231
tcppassword = 'mekker'
232
tcpseed = "bla1234567890bla"
233
# set this to 16 char wide string if you want to encrypt the data
240
pluginserver = 'http://gozerbot.org'
242
# upgradeurl .. only needed if mercurial repo changed
243
#upgradeurl = 'http://gozerbot.org/hg/gozerbot'
249
# collective boot server
250
collboot = "gozerbot.org:8088"
252
# name of the main bot
255
# allowed character for strippedtxt
258
# set to 1 to allow addons
266
""" wtite default config file to datadir/config """
267
if not os.path.isfile(datadir + os.sep + 'config'):
268
cfgfile = open(datadir + os.sep + 'config', 'w')
269
cfgfile.write(configtxt)
306
""" write loadlist to datadir """
307
if not os.path.isfile(datadir + os.sep + 'loadlist'):
308
cfgfile = open(datadir + os.sep + 'loadlist', 'w')
309
cfgfile.write(loadlist)
312
# create the config dict and load it from file
313
#config = Config(datadir)