5
""" start the bot from standalone directory """
7
__copyright__ = 'this file is in the public domain'
12
print "don't run the bot as root"
17
if vi[0] < 2 or (vi[0] == 2 and vi[1] < 4):
18
print "i need at least python version >= 2.4"
24
print 'changed dir to %s' % i
27
sys.path.insert(0, os.getcwd())
28
sys.path.insert(1, os.path.abspath(os.path.join(os.getcwd(), 'myplugs', 'addons')))
30
from optparse import OptionParser
32
parser = OptionParser(usage='usage: %prog [options]', version='%prog 0.8.1')
34
parser.add_option('', '-a', action='store_true', default=False, dest='doascii',
35
help="Use ASCII as the default encoding instead of UTF-8")
36
parser.add_option('', '-b', action='store_true', default=False, dest='dobackup',
38
parser.add_option('', '-u', action='store_false', default=True, dest='doumode',
39
help="Check permissions on the gozerdata folder")
40
parser.add_option('', '-r', type='string', default=False, dest='doresume',
42
help="Resume the bot from the folder specified")
44
opts, args = parser.parse_args()
49
sys.setdefaultencoding('utf-8')
51
sys.setcheckinterval(50)
52
socket.setdefaulttimeout(30)
54
from gozerbot.generic import handle_exception
57
from gozerbot.config import config, writeconfig, writeloadlist
58
from gozerbot.datadir import makedirs
59
from gozerbot.generic import enable_logging
70
from gozerbot.generic import rlog, handle_exception, checkpermissions
71
from gozerbot.bot import Bot
72
from gozerbot.fleet import fleet
73
from gozerbot.plugins import plugins
74
from gozerbot.eventhandler import mainhandler
75
from gozerbot.users import users
76
from gozerbot.thr import start_new_thread
77
from gozerbot.partyline import partyline
78
from gozerbot.exit import globalshutdown
83
import time, signal, gc, types
85
# enable garbage collection
88
# provide sigterm support
93
signal.signal(signal.SIGTERM, dostop)
96
rlog(10, 'GOZERBOT', 'starting %s' % config['version'])
97
rlog(5, 'gozerbot', 'default encoding is %s' % sys.getdefaultencoding())
100
umask = config['umask']
102
checkpermissions('gozerdata', 0700)
104
checkpermissions('gozerdata', umask)
106
# write pid to pidfile
107
k = open('gozerbot.pid','w')
108
k.write(str(os.getpid()))
111
# see if owner already has a user account if not merge otherwise add
114
if config['jabberenable']:
115
if type(config['jabberowner']) != types.ListType:
116
owner.append(config['jabberowner'])
118
owner = config['jabberowner']
120
if type(config['owneruserhost']) != types.ListType:
121
owner.append(config['owneruserhost'])
123
owner += config['owneruserhost']
127
username = users.getname(i)
129
if not users.merge('owner', i):
130
users.add('owner', [i, ], perms = ['USER', 'OPER'])
131
except Exception, ex:
136
start_new_thread(plugins.regplugins, ())
138
# create the bot and connect
139
if config['jabberenable']:
141
from gozerbot.jabberbot import Jabberbot
145
bot = Jabberbot('jabbermain', config['jabberowner'])
146
bot.host = config['jabberhost']
147
bot.user = config['jabberuser']
148
bot.password = config['jabberpass']
153
if not config['ircdisable']:
154
bot = Bot('main', config['owneruserhost'])
155
bot.nick = config['nick'] or 'gb1'
156
bot.server = config['server'] or 'localhost'
157
bot.port = config['port'] or 6667
158
bot.password = config['password'] or ""
159
bot.ipv6 = config['ipv6'] or 0
160
bot.ssl = config['ssl'] or 0
164
if opts.doresume and os.path.isfile(opts.doresume):
165
fleet.resume(opts.doresume)
167
partyline.resume(opts.doresume)
168
os.unlink(opts.doresume) # bye
175
mainhandler.handle_one()
176
except KeyboardInterrupt:
179
except Exception, ex: