def edit(self,widget): self.treeView.set_model(self.create_model()) model=self.treeView.get_model() edit.edit(self.fname) #print 1 update_list.main(self.fname) self.treeView.set_model(self.create_model()) model=self.treeView.get_model() '''print 1 for i in model: for j in i: print j, print print 2 ''' self.graphs(1) self.graphs(2) stats.update(self.fname) stats.treeView.set_model(stats.create_model(self)) try: viewer.update(self,'') viewer.treeView.set_model(viewer.create_model(self)) except AttributeError: pass
def changed_item_years(self,widget): #activated when combobox value holding years is changed #creates a file(if not present) and opens it and reads its contents self.fname=app.data_location+str(widget.get_active_text())+'_'+self.combobox.get_active_text() f=open(self.fname,'a') f.close() f=open(self.fname,'r') x=f.readlines() f.close() #print 1 update_list.main(self.fname) try: self.treeView.set_model(self.create_model()) #model=self.treeView.get_model() except AttributeError: pass self.graphs(1) self.graphs(2) stats.update(self.fname) stats.treeView.set_model(stats.create_model(self)) try: viewer.update(self,'') viewer.treeView.set_model(viewer.create_model(self)) except AttributeError: pass
def replyAll(self, gen_reply, include_read=False): self.tm.gc() self.banned_list = [] if include_read: self.users.gc() if self.whitelist: messages = self.api.messages.getDialogs(unread=(0 if self.whitelist_includeread else 1), count=20) self.whitelist_includeread = False else: messages = self.api.messages.getDialogs(unread=1, count=200) try: messages = messages['items'][::-1] except TypeError: logging.warning('Unable to fetch messages') return self.loadUsers(messages, lambda x: x['message']['user_id']) self.loadUsers(messages, lambda x: x['message']['chat_id'], confs=True) for msg in sorted(messages, key=lambda m: m['message']['id']): cur = msg['message'] if cur['out']: continue if self.last_message_id and cur['id'] > self.last_message_id: continue self.replyOne(cur, gen_reply, 'getDialogs') stats.update('banned_messages', ' '.join(map(str, sorted(self.banned_list)))) else: messages = self.longpollMessages() self.loadUsers(messages, lambda x: x['user_id']) self.loadUsers(messages, lambda x: x['chat_id'], confs=True) for cur in sorted(messages, key=lambda m: m['id']): self.last_message_id = max(self.last_message_id, cur['id']) self.replyOne(cur, gen_reply)
def finish(self): worldData = self.w.to_dict() worldData['id'] = self.game_id worldData['time'] = -1 self.mc[self.game_id].update({}, worldData, upsert=True) print 'FINISHING' models = self.models testmode = self.testmode nrobots = self.nrobots procs = self.procs tournament = self.tournament alive = [model for model in models.values() if model.alive] if not testmode and len(alive)==1: model = alive[0] print 'WINNER:', model.name winner = model model._kills = nrobots-1 elif not testmode: winner = None if self.rnd >= conf.maxtime*60: print 'Battle stopped after maximum time:', conf.maxtime, 'seconds.' else: print 'Battle stopped after', int(self.rnd/60), 'seconds.' print 'STILL ALIVE:' for model in alive: print ' ', model.name else: winner = None for robotname, model in models.items(): print robotname, 'caused', model._damage_caused, 'damage' if robotname in procs: line = 'FINISH\n' proc = procs[robotname] proc.stdin.write(line) proc.stdin.flush() proc.stdin.close() proc.stdout.close() del procs[robotname] if winner is None and model.alive: model._kills = nrobots - len(alive) if model == winner: win = 1 else: win = 0 if not testmode: stats.update(model.kind, win, nrobots-1, model._kills, model._damage_caused) if tournament is not None: stats.tournament_update(tournament, model.kind, model.name, win, nrobots-1, model._kills, model._damage_caused)
def __init__(self, username='', password='', get_dialogs_interval=60): self.delay_on_reply = config.get('vkbot_timing.delay_on_reply', 'i') self.chars_per_second = config.get('vkbot_timing.chars_per_second', 'i') self.same_user_interval = config.get('vkbot_timing.same_user_interval', 'i') self.same_conf_interval = config.get('vkbot_timing.same_conf_interval', 'i') self.forget_interval = config.get('vkbot_timing.forget_interval', 'i') self.delay_on_first_reply = config.get( 'vkbot_timing.delay_on_first_reply', 'i') self.stats_dialog_count = config.get('stats.dialog_count', 'i') self.no_leave_conf = config.get('vkbot.no_leave_conf', 'b') self.api = vkapi.VkApi(username, password, ignored_errors=ignored_errors, timeout=config.get( 'vkbot_timing.default_timeout', 'i'), token_file=accounts.getFile('token.txt'), log_file=accounts.getFile('inf.log') if args.args['logging'] else '', captcha_handler=createCaptchaHandler()) stats.update('logging', bool(self.api.log_file)) # hi java self.users = UserCache( self.api, self.fields + ',' + FriendController.requiredFields(_getFriendControllerParams()), config.get('cache.user_invalidate_interval', 'i')) self.confs = ConfCache( self.api, config.get('cache.conf_invalidate_interval', 'i')) self.vars = json.load(open('data/defaultvars.json', encoding='utf-8')) self.vars['default_bf'] = self.vars['bf']['id'] self.initSelf(True) self.guid = int(time.time() * 5) self.last_viewed_comment = stats.get('last_comment', 0) self.good_conf = {} self.tm = ThreadManager() self.last_message = MessageCache() if os.path.isfile(accounts.getFile('msgdump.json')): try: data = json.load(open(accounts.getFile('msgdump.json'))) self.last_message.load(data['cache']) self.api.longpoll = data['longpoll'] except json.JSONDecodeError: logging.warning('Failed to load messages') os.remove(accounts.getFile('msgdump.json')) else: logging.info('Message dump does not exist') self.bad_conf_title = lambda s: False self.admin = None self.banned_list = [] self.message_lock = threading.Lock() self.banned = set() self.receiver = MessageReceiver(self.api, get_dialogs_interval) self.receiver.longpoll_callback = self.longpollCallback
def replyAll(self, gen_reply): self.tm.gc() self.banned_list = [] messages = self.receiver.getMessages() self.loadUsers(messages, lambda x: x['user_id']) self.loadUsers(messages, lambda x: x['chat_id'] + CONF_START) for cur in messages: self.replyOne(cur, gen_reply) if self.receiver.used_get_dialogs: stats.update('banned_messages', ' '.join(map(str, sorted(self.banned_list))))
def finish(self): print 'FINISHING' models = self.models testmode = self.testmode ntanks = self.ntanks procs = self.procs tournament = self.tournament alive = [model for model in models.values() if model.alive] if not testmode and len(alive)==1: model = alive[0] print 'WINNER:', model.name winner = model model._kills = ntanks-1 elif not testmode: winner = None if self.rnd >= conf.maxtime*60: print 'The battle finished after maximum time:', conf.maxtime, 'seconds.' else: print 'The battle finished after', int(self.rnd/60), 'seconds.' print 'STILL ALIVE:' for model in alive: print ' ', model.name else: winner = None for tankname, model in models.items(): print tankname, 'caused', model._damage_caused, 'damage' if tankname in procs: line = 'FINISH\n' proc = procs[tankname] proc.stdin.write(line) proc.stdin.flush() proc.stdin.close() proc.stdout.close() del procs[tankname] if winner is None and model.alive: model._kills = ntanks - len(alive) if model == winner: win = 1 else: win = 0 if not testmode: stats.update(model.kind, win, ntanks-1, model._kills, model._damage_caused) if tournament is not None: stats.tournament_update(tournament, model.kind, model.name, win, ntanks-1, model._kills, model._damage_caused)
def filterComments(self, test): data = self.api.notifications.get(start_time=self.last_viewed_comment + 1, count=100)['items'] to_del = set() to_bl = set() self.loadUsers(data, lambda x: x['feedback']['from_id'], True) for rep in data: if rep['date'] != 'i': self.last_viewed_comment = max(self.last_viewed_comment, int(rep['date'])) def _check(s): if 'photo' in s: return s['photo']['owner_id'] == self.self_id if 'video' in s: return s['video']['owner_id'] == self.self_id if 'post' in s: return s['post']['to_id'] == self.self_id if rep['type'].startswith('comment_') or ( rep['type'].startswith('reply_comment') and _check(rep['parent'])) or rep['type'] == 'wall': txt = html.escape(rep['feedback']['text']) res = 'good' frid = int(rep['feedback']['from_id']) if self.users[frid]['blacklisted']: res = 'blacklisted' log.write( 'comments', self.loggableName(frid) + ' (blacklisted): ' + txt) self.deleteComment(rep) to_bl.add(frid) elif test(txt): res = 'bad' log.write('comments', self.loggableName(frid) + ': ' + txt) self.deleteComment(rep) to_del.add(frid) elif 'attachments' in rep['feedback'] and any( i.get('type') in ['video', 'link'] for i in rep['feedback']['attachments']): res = 'attachment' log.write('comments', self.loggableName(frid) + ' (attachment)') self.deleteComment(rep) self.logSender( 'Comment {} (by %sender%) - {}'.format(txt, res), {'user_id': frid}) stats.update('last_comment', self.last_viewed_comment) for i in to_bl: self.blacklist(i) return to_del
def changed_item(self,widget): #activated when combobox value holding months is changed #self.yy='2012' a= widget.get_active_text() try: #print type(self.combobox2.get_active_text()) self.fname=app.data_location+self.combobox2.get_active_text()+'_'+a #print self.fname f=open(self.fname,'a') f.close() f=open(self.fname,'r') x=f.readlines() f.close() #print 1 update_list.main(self.fname) except AttributeError: f=open(app.data_location+str(self.yy)+'_'+str(self.months[self.mm]),'a') f.close() update_list.main(app.data_location+str(self.yy)+'_'+self.combobox.get_active_text()) pass try: self.treeView.set_model(self.create_model()) #model=self.treeView.get_model() except AttributeError: pass #del self.line self.graphs(1) self.graphs(2) try: stats.update(self.fname) stats.treeView.set_model(stats.create_model(self)) viewer.update(self,self.fname) viewer.treeView.set_model(viewer.create_model(self)) except AttributeError: pass viewer.treeView.set_model(viewer.create_model(self)) except AttributeError: pass
def filterComments(self, test): data = self.api.notifications.get(start_time=self.last_viewed_comment + 1, count=100)['items'] to_del = set() to_bl = set() self.loadUsers(data, lambda x: x['feedback']['from_id'], True) for rep in data: if rep['date'] != 'i': self.last_viewed_comment = max(self.last_viewed_comment, int(rep['date'])) stats.update('last_comment', self.last_viewed_comment) def _check(s): if 'photo' in s: return s['photo']['owner_id'] == self.self_id if 'video' in s: return s['video']['owner_id'] == self.self_id if 'post' in s: return s['post']['to_id'] == self.self_id if rep['type'].startswith('comment_') or rep['type'].startswith('reply_comment') and _check(rep['parent']): txt = html.escape(rep['feedback']['text']) res = 'good' if self.users[rep['feedback']['from_id']]['blacklisted']: res = 'blacklisted' log.write('comments', self.loggableName(rep['feedback']['from_id']) + ' (blacklisted): ' + txt) self.deleteComment(rep) to_bl.add(rep['feedback']['from_id']) elif test(txt): res = 'bad' log.write('comments', self.loggableName(rep['feedback']['from_id']) + ': ' + txt) self.deleteComment(rep) to_del.add(rep['feedback']['from_id']) elif 'attachments' in rep['feedback'] and any(i.get('type') in ['video', 'link'] for i in rep['feedback']['attachments']): res = 'attachment' log.write('comments', self.loggableName(rep['feedback']['from_id']) + ' (attachment)') self.deleteComment(rep) self.logSender('Comment {} (by %sender%) - {}'.format(txt, res), {'user_id': rep['feedback']['from_id']}) for i in to_bl: self.blacklist(i) return to_del
def main(): if not pygame.font: print 'Warning, fonts disabled' return if not pygame.mixer: print 'Warning, sound disabled' pygame.font.init() music = pygame.mixer.music if config.music: try: music.load(os.path.join('data', 'music.ogg')) except: print "No music" config.music = False pygame.init() screen = pygame.display.set_mode(config.size) pygame.display.set_caption('SpaceFight') pygame.mouse.set_visible(0) background = pygame.image.load(os.path.join('data', \ 'background.png')).convert() screen.blit(background, (0, 0)) pygame.display.flip() clock = pygame.time.Clock() spawn = True lastCast = pygame.time.get_ticks() lastPowerUp = pygame.time.get_ticks() enemies = pygame.sprite.RenderPlain(Ufo()) fighter = Fighter(enemies) fighterGroup = pygame.sprite.RenderPlain(fighter) powerups = pygame.sprite.RenderPlain(choice(config.powerups)(fighter)) if config.music: music.set_volume(0.8) music.play(-1) while 1: clock.tick(50) for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN: if event.key == K_ESCAPE or event.key == K_q: return ####################################################### # DEBUG # ####################################################### elif event.key == K_s: enemies.add(Ufo()) lastCast = pygame.time.get_ticks() elif event.key == K_p: powerups.add(choice(config.powerups)(fighter)) lastPowerUp = pygame.time.get_ticks() ####################################################### elif event.key == K_SPACE: fighter.shotType = fighter.shootRocket fighter.shooting = True elif event.key == K_c: fighter.shotType = fighter.shootSuperChicken fighter.shooting = True elif event.key == K_UP or event.key == K_l: fighter.shotType = fighter.shootLaser fighter.shooting = True elif event.key == K_RIGHT: fighter.dx = min(fighter.speed, fighter.maxspeed) elif event.key == K_LEFT: fighter.dx = -min(fighter.speed, fighter.maxspeed) elif event.key == K_f: pygame.display.toggle_fullscreen() elif event.type == KEYUP: if event.key == K_RIGHT and fighter.dx > 0: fighter.dx = 0 elif event.key == K_LEFT and fighter.dx < 0: fighter.dx = 0 elif event.key == K_SPACE and fighter.shotType == fighter.shootRocket: fighter.shooting = False elif (event.key == K_UP or event.key == K_l) and fighter.shotType == fighter.shootLaser: fighter.shooting = False elif event.key == K_c and fighter.shotType == fighter.shootSuperChicken: fighter.shooting = False if pygame.time.get_ticks() - lastCast >= config.levels[stats.level['level']]['spawnSpeed'] and stats.level['spawned'] < config.levels[stats.level['level']]['spawns']: enemies.add(Ufo()) lastCast = pygame.time.get_ticks() stats.level['spawned'] += 1 if pygame.time.get_ticks() - lastPowerUp >= config.levels[stats.level['level']]['powerUpSpeed']: powerups.add(choice(config.powerups)(fighter)) lastPowerUp = pygame.time.get_ticks() if stats.level['spawned'] == config.levels[stats.level['level']]['spawns']: # spawn endboss pass screen.blit(background, (0, 0)) stats.update() fighterGroup.update() fighterGroup.draw(screen) powerups.update() powerups.draw(screen) enemies.update() enemies.draw(screen) pygame.display.flip()
def processFile(bench, result, tool): stats = {"tool": tool, "ans": "", "time": "", "mem": "", "inst": ""} if result is None: stats.update({"ans": "ERR"}) return {bench: stats}, stats if tool == "JPF": for r in result.splitlines(): if 'no errors detected' in r: #stat('Result-JPF', 'SAFE') stats.update({"ans": "SAFE"}) if 'elapsed time' in r: t = r.split() time = t[len(t) - 1] stats.update({"time": str(time)}) if 'max memory' in r: t = r.split() mem = t[len(t) - 1] stats.update({"mem": str(mem)}) if 'instructions' in r: t = r.split() ins = t[len(t) - 1] stats.update({"inst": str(ins)}) if 'java.lang.AssertionError' in r: #stat('Result-JPF', 'CEX') stats.update({"ans": "CEX"}) elif tool == "Z3" or tool == "ELD": if "checker says true" in result: #if tool == "Z3": stat('Result-Z3', 'SAFE') #if tool == "ELD": stat('Result-ELDARICA', 'SAFE') stats.update({"ans": "SAFE"}) if "checker says false" in result: #if tool == "Z3": stat('Result-Z3', 'CEX') #if tool == "ELD": stat('Result-ELDARICA', 'CEX') stats.update({"ans": "CEX"}) return {bench: stats}, stats
def processFile(bench, result, tool): stats = {"tool": tool, "ans":"", "time":"", "mem":"", "inst":""} if result is None: stats.update({"ans":"ERR"}) return {bench:stats}, stats if tool == "JPF": for r in result.splitlines(): if 'no errors detected' in r: #stat('Result-JPF', 'SAFE') stats.update({"ans":"SAFE"}) if 'elapsed time' in r: t = r.split() time = t[len(t)-1] stats.update({"time":str(time)}) if 'max memory' in r: t = r.split() mem = t[len(t)-1] stats.update({"mem":str(mem)}) if 'instructions' in r: t = r.split() ins = t[len(t)-1] stats.update({"inst":str(ins)}) if 'java.lang.AssertionError' in r: #stat('Result-JPF', 'CEX') stats.update({"ans":"CEX"}) elif tool == "Z3" or tool == "ELD": if "checker says true" in result: #if tool == "Z3": stat('Result-Z3', 'SAFE') #if tool == "ELD": stat('Result-ELDARICA', 'SAFE') stats.update({"ans":"SAFE"}) if "checker says false" in result: #if tool == "Z3": stat('Result-Z3', 'CEX') #if tool == "ELD": stat('Result-ELDARICA', 'CEX') stats.update({"ans":"CEX"}) return {bench:stats}, stats
def finish(self, update_stats=True): print 'FINISHING' if hasattr(self, '_FINISHED'): print 'ALREADY FINISHED' return self._FINISHED = True models = self.models testmode = self.testmode nrobots = self.nrobots procs = self.procs tournament = self.tournament alive = [model for model in models.values() if model.alive] if not testmode and len(alive)==1: model = alive[0] print 'WINNER:', model.name winner = model model._outlasted = nrobots-1 elif not testmode: winner = None if self.rnd >= conf.maxtime*60: print 'Battle stopped after maximum time:', conf.maxtime, 'seconds.' else: print 'Battle stopped after', int(self.rnd/60), 'seconds.' print 'STILL ALIVE:' for model in alive: print ' ', model.name else: print 'Test mode ended' winner = None for robotname, model in models.items(): print robotname, 'caused', model._damage_caused, 'damage' if robotname in procs: line = 'FINISH\n' proc = procs[robotname] proc.stdin.write(line) proc.stdin.flush() proc.stdin.close() proc.stdout.close() del procs[robotname] if winner is None and model.alive: model._outlasted = nrobots - len(alive) if model == winner: win = 1 else: win = 0 if update_stats and not testmode: stats.update(model.kind, win, nrobots-1, model._outlasted, model._damage_caused, model._kills) if update_stats and tournament is not None: stats.tournament_update(tournament, model.kind, model.name, win, nrobots-1, model._outlasted, model._damage_caused, model._kills)
def writeNoadd(): with open(accounts.getFile('noadd.txt'), 'w') as f: f.write('\n'.join(map(str, sorted(noadd)))) stats.update('ignored', len(noadd))
def appendNoadd(users): noadd.update(users) with open(accounts.getFile('noadd.txt'), 'a') as f: f.write('\n' + '\n'.join(map(str, sorted(users)))) stats.update('ignored', len(noadd))
def graphs(self,option): # when option==1, the first graph, self.a is redrawn # when option==2, the second graph, self.c is redrawn #self.f.text(0.5,0.92,'',fontsize=14) #self.f.text(0.5,0.92,self.combobox.get_active_text()+' '+self.combobox2.get_active_text(),fontsize=14,horizontalalignment='center') #print self.get_suptitle() matplotlib.rc('xtick', labelsize=11) matplotlib.rc('ytick', labelsize=11) try: if option==1: self.a = self.f.add_subplot(221) self.a.patch.set_color('black') self.a.patch.set_alpha(0.05) #print self.a.get_yticks() self.a.yaxis.grid('True') #print self.combobox.get_active_text() self.a.set_xlabel(self.combobox.get_active_text()+' '+self.combobox2.get_active_text(),fontsize=12) #print self.a.get_xlabel() self.a.set_ylabel('Daily Expense',fontsize=12) model=self.treeView.get_model() total_list=[0] counter=0 for i in model: for j in i: counter+=1 if counter%7==0: total_list.append(j) #print j, type(j), #print '\n' #print range(len(total_list)) #print total_list if max(total_list)==0: M=1 else: M=max(total_list)+0.1*max(total_list) self.a.set_ylim(0,M) self.a.set_xlim(1,len(total_list)-1) days=[] for i in range(len(total_list)): if i%2!=0: days.append(i) self.a.set_xticks(days) self.a.set_xticklabels(days,fontsize=9) #print total_list, len(total_list) #total_list.append(100) while len(self.line1)!=0: l=self.line1.pop(0) l.remove() total_list.append(0) #self.a.set_antialiased(False) #print total_list self.line1=self.a.fill(total_list,'blue',alpha=0.6) self.canvas.draw() #print line self.b=self.f.add_subplot(222) self.b.patch.set_color('black') self.b.patch.set_alpha(0.05) self.b.yaxis.grid('True') self.b.set_xlabel('Categories',fontsize=12) self.b.set_ylabel('Category Expense',fontsize=12) total_list=[0] counter=0 #print 1 stats.update(self.fname) counter=0 cat=[] for i in stats.create_model(self): for j in i: counter+=1 if counter%2==0: total_list.append(j) else: cat.append(j) del total_list[-1] del cat[-1] #print cat #print total_list #print 'sfdf' if max(total_list)==0: M=1 else: M=max(total_list)+0.1*max(total_list) self.b.set_ylim(0,M) self.b.set_xlim(0.5,5.5) self.b.set_xticks([1,2,3,4,5]) self.b.set_xticklabels(cat,fontsize=9) #print total_list, len(total_list) #total_list.append(100) while len(self.line1b)!=0: l2=self.line1b.pop(0) l2.remove() #self.line1b=[] #print 3 total_list.append(0) #self.a.set_antialiased(False) #print total_list self.line1b=self.b.fill(total_list,'yellow',alpha=0.6) self.canvas.draw() else: self.c = self.f.add_subplot(212) self.c.patch.set_color('black') self.c.patch.set_alpha(0.05) self.c.yaxis.grid('True') self.c.set_xlabel(self.combobox2.get_active_text(),fontsize=12) self.c.set_ylabel('Monthly Expense',fontsize=12) self.c.set_xlim(0,13) self.c.set_xticks(range(1,13)) #self.c.set_xticks(range(5)) #for i in max(monthly_totals_list): #print self.c.get_yticks() self.c.set_xticklabels(self.months,fontsize=11) year=self.combobox2.get_active_text() monthly_totals_list=[0] for i in range(12): cost=0 s=year+'_'+str(self.months[i]) #print s try: f=open(app.data_location+s,'r') s=f.readlines() f.close() #print 0 for i in s: #print i[19:22] #print i cost+=float(i[19:27].strip()) #print cost, except IOError: #print 2 pass #print cost monthly_totals_list.append(cost) #print if max(monthly_totals_list)==0: M=1 else: M=max(monthly_totals_list)+0.1*max(monthly_totals_list) self.c.set_ylim(0,M) while len(self.line2)!=0: l=self.line2.pop(0) l.remove() monthly_totals_list.append(0) self.line2=self.c.fill(monthly_totals_list,'green',alpha=0.6) self.canvas.draw() ##print line except AttributeError: pass
def update(): """Update global game stats.""" stats.update(bottle.request.forms) return [ "OK" ]
def main_loop(): try: if timeto('setonline', setonline_interval): vk.setOnline() if timeto('filtercomments', filtercomments_interval): noaddUsers(vk.filterComments(lambda s: getBotReplyComment(s)), reason='bad comment') if timeto('unfollow', unfollow_interval): noaddUsers(vk.unfollow(), reason='deleted me') if timeto('addfriends', addfriends_interval): vk.addFriends(reply, testFriend) if includeread_interval >= 0: vk.replyAll(reply) else: vk.replyAll(lambda x: None) time.sleep(1) if timeto('stats', stats_interval): vk.initSelf(True) stats.update('ignored', len(friend_controller.noadd)) stats.update('blacklisted', vk.blacklistedCount()) count, dialogs, confs, invited = vk.lastDialogs() if count is not None: vk.loadUsers(dialogs, lambda x: x[0]) dialogs = [[uid, vk.printableName(uid, '{name}', conf_fmt='Conf "%s"' % confs.get(uid).replace('{', '{{').replace('}', '}}')), cnt, invited.get(uid)] for uid, cnt in dialogs if uid > 0] stats.update('dialogs', count) stats.update('dialogs_list', dialogs) stats.update('phone', vk.vars['phone']) stats.update('bf', vk.printableSender({'user_id': vk.vars['bf']['id']}, True)) stats.update('overload', vk.tracker.overload()) if timeto('groupinvites', groupinvites_interval): vk.acceptGroupInvites() bot.reloadIfChanged() except Exception as e: logging.exception('global {}: {}'.format(e.__class__.__name__, str(e))) time.sleep(2)
srv.addHandler('stem', lambda x: bot.interact('stem ' + x, False)) srv.addHandler('ignore', ignoreHandler) srv.addHandler('unignore', unignoreHandler) srv.addHandler('ban', banHandler) srv.addHandler('unban', unbanHandler) srv.addHandler('reload', reloadHandler) srv.addHandler('isignored', isignoredHandler) srv.addHandler('leave', leaveHandler) srv.addHandler('banlist', banlistHandler) srv.addHandler('ignlist', ignlistHandler) srv.listen() logging.info('Running TCP server on port ' + config.get('server.port')) friend_controller = vkbot.createFriendController() friend_controller.writeNoadd() stats.update('started', time.time()) def main_loop(): try: if timeto('setonline', setonline_interval): vk.setOnline() if timeto('filtercomments', filtercomments_interval): noaddUsers(vk.filterComments(lambda s: getBotReplyComment(s)), reason='bad comment') if timeto('unfollow', unfollow_interval): noaddUsers(vk.unfollow(), reason='deleted me') if timeto('addfriends', addfriends_interval): vk.addFriends(reply, testFriend) if includeread_interval >= 0: vk.replyAll(reply) else: vk.replyAll(lambda x: None)