rendered paste body#import SpringBase, SpringExt, Protocol, Commands, Log, Consoleimport SpringBase, SpringExt, modulesimport sys, time, os, thread, getoptif not os.path.isdir('data'): os.mkdir('data')infofile = Nonetry: infofile = file('data/config.txt')except IOError: try: infofile = file('config.txt') except IOError: infofile = NoneAccount = NoneHost = Noneif infofile: Account = infofile.readline().strip('\n').split(' ') Host = infofile.readline().split(' ')def usage(): print 'Usage: uberbot.py [OPTION]...' print 'Starts uberbot.\n' print 'Options:' print ' -a, --autoconfig'.ljust(2)+'create data/config.txt with default values.' print ' -u, --user'.ljust(20)+'use non-default username' print ' -p, --pass'.ljust(20)+'use non-default password (unhashed)' print ' -r, --passhash'.ljust(20)+'use non-default password (hashed)' print 'If both pass and passhash are present, it defaults to passhash'try: opts, args = getopt.getopt(sys.argv[1:], "haupr:v", ["help", "autoconfig", "user=", "pass=", "passhash="])except getopt.GetoptError: # skips using command-line params passfor o, a in opts: if o == "-a": print 'Writing data/config.txt' f = open('./data/config.txt', 'w') f.write('user hash * * Uberbot 0.83\n') f.write('taspringmaster.clan-sy.com 8200') sys.exit() if o in ("-h", "--help"): usage() sys.exit() if o in ("-u", "--user"): username = a if o in ["-p", "--pass"]: password = a # need to hash <_< if o in ["-r", "--passhash"]: password = aif not infofile: if not username or not password: print 'Failed error loading the data/config.txt file...it can be automatically generated with the -a command line switch...please fill it in with the correct values.' sys.exit()if Account and Host: passelse: Account = [username, password, '*', '*', 'Uberbot', '0.83'] Host = ['taspringmaster.clan-sy.com', '8200']class root: def init(self): self.devmode = 0 self._spring = _spring self._ext = _ext self._modules = _modules self.commanddict = { 'owner':['owner','admin','chanfounder','chanadmin','public','bot','uf'], 'admin':['admin','chanfounder','chanadmin','public','uf'], 'user':['public','uf'], 'bot':['bot','uf'], 'channel founder':['chanfounder', 'chanadmin', 'public','uf'], 'channel admin':['chanadmin','public','uf']} #base dictionaries self.config = {'chanlist': {}, 'owner': '', 'admins': {}, 'bots': {_spring.Account[0]: ''}, 'cchars': {'!': ''}} self.channels = {} self.smurfs = {'global': {}, 'channel specific': {}} self.accounts = {} self.users = {} self.devmode = 0 if os.path.exists('devmode'): self.devmode = 1 if self.devmode: self.config['chanlist'] = {'notmain': '', 'uberbot': ''} self.config['owner'] = '[SBFS]aegis' else: self.config = _ext.loadPickle('./data/mainconfig.txt', self.config) self.channels = _ext.loadPickle('./data/channels.txt', self.channels) self.smurfs = _ext.loadPickle('./data/smurfs.txt', self.smurfs) self.accounts = _ext.loadPickle('./data/accounts.txt', self.accounts) print 'Initilizing channel configuration lists.' #self.initChanLists(self.channels) print 'Joining channels: ' + ' '.join(self.config['chanlist']) _spring.Join(self.config['chanlist']) for chan in self.config['chanlist']: self.channels[chan] = { 'config': {'chanfounder': '', 'kick_method': 'ban', 'op': False, 'spamprotection': {'enabled': True, 'limit': 5, 'bonus': 200, 'inc': 1, 'bonusinc': 2, 'doubleinc': 2}}, 'cmds': {}, 'banlist': {}, 'allowlist': {}, 'admins': {}} _spring.SayPM('!info #%s'%(chan), 'ChanServ') _spring.SayEX('is here','uberbot') _spring.SayEX('is here','notmain') def save(self): _ext.savePickle('./data/mainconfig.txt', self.config) _ext.savePickle('./data/channels.txt', self.channels) _ext.savePickle('./data/smurfs.txt', self.smurfs) _ext.savePickle('./data/accounts.txt', self.accounts) def load(self): _ext.savePickle('./data/mainconfig.txt', self.config) _ext.savePickle('./data/channels.txt', self.channels) _ext.savePickle('./data/smurfs.txt', self.smurfs) _ext.savePickle('./data/accounts.txt', self.accounts) def reconnect(self, reason='None'): _spring.Reset() _spring.SayEX('is reconnecting (Reason: %s)'%(reason), 'uberbot') while _spring.sendbuffer: time.sleep(0.1) _spring.conn.close() _spring.Reset() _spring.Connect() _spring.Login() def rights(self, user, chan): if user == self.config['owner'] or user in ['aegis', '[tN]aegis', '[SBFS]aegis', '[Kt]delfin', '[II]Naxon']: return 'owner' if user in self.config['bots']: return 'bot' if user in self.config['admins']: return 'admin' if not chan == '~pm': if self.channels[chan]['config']['op']: if user == self.channels[chan]['config']['chanfounder']: return 'channel founder' if user in self.channels[chan]['admins']: return 'channel admin' return 'user' def dokick(self, user, chan): rights = self.rights(user, chan) if rights in ['owner', 'admin', 'channel founder', 'channel admin']: return 0 kickmethod = self.channels[chan]['config']['kick_method'] if kickmethod == 'ban': if user in self.channels[chan]['banlist']: return '%s %s'%(user,self.channels[chan]['banlist'][user]) if kickmethod == 'allow': if not user in self.channels[chan]['allowlist']: return '%s You are not allowed here.'%(user) return 0 def log(self,file,entry): try: logentry = '['+time.asctime()+'] '+entry+'\n' file = _ext.makecasesense(file) f = open('./data/logs/' + file + '.txt', 'a') f.write(logentry) f.close() except IOError: time.sleep(.5) self.log(file,entry) def reply(self,user,chan,message): if message: null,command = sys._getframe(1).f_code.co_name.split('_',1) if not command: command = null allowed = self.isCommandAllowed(user,chan,command) if allowed and not chan == '~pm': _ext.Say(chan,message) elif allowed != None: _ext.SayPM(user,message) def replyex(self,user,chan,message): if message: null,command = sys._getframe(1).f_code.co_name.split('_',1) if not command: command = null if self.isCommandAllowed(user,chan,command) and not command == '~pm': _ext.SayEX(chan,message) else: _ext.SayPM(user,message) def isCommandAllowed(self,user,chan,command): try: rights = self.commanddict[self.rights(user,chan)] cmdrights = self.channels[chan]['cmds'][command] if 'chanadmin' in rights and cmdrights == 'public' or cmdrights == 'admin': return True if cmdrights == 'ignore': return None if 'public' in rights and cmdrights == 'public': return True except KeyError: pass return False def spawn(self,spawntype,account,password=None): if not password: if account in self.accounts: password = self.accounts[account]['password'] else: print account return script = sys.argv[1] # this script os.spawnv(P_NOWAIT, script, script, '-u %s'%account, '-r %s'%password)_spring = SpringBase.SpringBase()_ext = SpringExt.SpringExt(_spring)_modules = modules_modules._init()_root = root()_spring.Init(Account, Host)_spring.Connect()_spring.Login()_root.threading = True#console = Console.Console()#Ext = SpringExt.SpringExt(_spring)#log = Log.Log(root)#commands = Commands.Commands(Spring, Ext, root)#protocol = Protocol.Protocol(Spring, Ext, commands, root)#commands._protocol = protocolwhile _spring.active == 1: line = _spring.Recieve() if line: splitline = line.split(' ') what = splitline[0] del splitline[0] line = ' '.join(splitline) #thread.start_new_thread(log._handle,('log_'+what,line)) #log._handle('log_'+what,line) #thread.start_new_thread(console._handle,('output_'+what,line)) #protocol._handle('protocol_'+what,line) #thread.start_new_thread(protocol._handle,('protocol_'+what,line)) #thread.start_new_thread(modules._handle,(what,line)) if _root.threading: thread.start_new_thread(modules._handle,(_root,what,line)) else: _modules._handle(_root,what,line)_spring.conn.close()if not _root.devmode: _root.save()