def processJsonResponse(response, ytid): try: j = json.loads(response) except(ValueError): clog.error('ProcessJsonResponse: Error decoding JSON: %s' % response, syst) return j
def cacheKey(self, res, nickname): clog.error('the key is %s:' % res[0], sys) assert res, 'no res at cacheKey' if res: clog.info("(cacheKey) cached %s's key %s" % (nickname, res[0])) self.nickdict[nickname]['keyId'] = res[0] return defer.succeed(res[0])
def _com_tweet(self, yuka, user, args, source): if source != 'chat' or not self.allowed: #only cytube clog.info('tweet called from invalid source', syst) return if not args: return if args == 'reload' and self.allowed: # only the first person on the list can reload if self.allowed[0] == user: self._load_allowed() yuka.reply('[tweet] Reloaded allowed list.', source, user) else: yuka.reply("[tweet] You can't do that.", source, user) return if user not in self.allowed: yuka.reply('[tweet] You are not allowed to do that..', source, user) return if not self._count_tweet(user, args): yuka.reply('Tweet too long.', source, user) return try: status = self._create_status(user, args) headers = self._create_header(status) except Exception as e: clog.error(e, syst) self.last_error = e yuka.reply('Something went wrong!', source, user) return d = self.tweet(status, headers) d.addCallback(self.cbAnagramRequest) d.addCallback(self.parseTwitterResponse, yuka, source, user) d.addCallback(self.sendAnagram, yuka, args, source, user)
def logProcess(self, user, msg, flag): timeNow = getTime() nickname = user.split('!')[0] i = user.find('~') j = user.find('@') username = user[i+1:j] host = user[j+1:] if nickname in self.nickdict: keyId = self.nickdict[nickname]['keyId'] if keyId is None: # a callback for the keyId must already be registered clog.error('(logProcess) key None for user %s' % nickname, sys) dd = self.nickdict[nickname]['deferred'] dd.addCallback(self.logChat, 3, timeNow, msg, flag) if keyId: d = self.logChat(keyId, 3, timeNow, msg, flag) else: self.nickdict[nickname] = {'keyId': None, 'deferred': None} clog.debug('(logProcess) added %s to nickdict' % nickname, sys) values = (nickname.lower(), username, host, nickname, 0) d = database.queryIrcuser(nickname.lower(), username, host) d.addCallback(self.cbQueryIrcuser, values) d.addCallback(self.cacheKey, nickname) d.addCallback(self.logChat, 3, timeNow, msg, flag) #dd = self.queryOrAddUser(nickname, username, host) #dd.addCallback(self.logChat, 3, timeNow, msg, flag) self.nickdict[nickname]['deferred'] = d
def processJsonResponse(response, ytid): try: j = json.loads(response) except (ValueError): clog.error('ProcessJsonResponse: Error decoding JSON: %s' % response, syst) return j
def _cyCall_queue(self, fdict): timeNow = round(time.time(), 2) item = fdict['args'][0]['item'] isTemp = item['temp'] media = item['media'] queueby = item['queueby'] afterUid = fdict['args'][0]['after'] mType = media['type'] mId = media['id'] self.addToPlaylist(item, afterUid) if queueby: # anonymous add is an empty string userId = self.userdict[queueby]['keyId'] else: userId = 3 if userId: d = self.queryOrInsertMedia(media, userId) else: clog.error('(_cyCall_queue) user id not cached.', sys) return if isTemp: flag = 1 else: flag = None d.addCallback(self.writeQueue, userId, timeNow, flag) d.addCallback(self.checkMedia, mType, mId) d.addCallback(self.flagOrDelete, media, mType, mId) if mType == 'yt' and vdb: timeNow = round(time.time(), 2) # since this callback is added after checkMedia which has a delay, # this also gets delayed d.addCallback(vdbapi.requestSongByPv ,mType, mId, 1, timeNow, 0)
def userLeft(self, user, channel): clog.info('%s has left %s' % (user, channel), sys) if channel == self.channelName: self.factory.handle.ircUserCount -= 1 try: self.nicklist.remove(user) except(ValueError): clog.error('(userLeft) User %s not in nicklist' % user)
def restartConnection(self, *args): clog.error('restarting connection in %s' % self.cyRetryWait, sys) msg = ('[status] Could not connect to server. Attempting to reconnect ' 'in %d seconds.' % self.cyRetryWait) #self.sendToIrc(msg) reactor.callLater(self.cyRetryWait, self.startCytubeClient) self.cyRetryWait = min((self.cyRetryWait + 1)**(1 + random.random()), 300)
def startService(self): if self.running: clog.error("DCListenerService is already running") else: self.f = DCListenerFactory(self) self._port = reactor.callLater(3, reactor.connectTCP,"localhost", PORT, self.f)
def userLeft(self, user, channel): clog.info('%s has left %s' % (user, channel), sys) if channel == self.channelName: self.factory.handle.ircUserCount -= 1 try: self.nicklist.remove(user) except (ValueError): clog.error('(userLeft) User %s not in nicklist' % user)
def userKicked(self, kickee, channel, kicker, message): clog.info('%s was kicked by %s from %s: %s' % (kickee, kicker, channel, message)) if channel == self.channelName: self.factory.handle.ircUserCount -= 1 try: self.nicklist.remove(kickee) except (ValueError): clog.error('(userKiced) User %s not in nicklist' % kickee)
def cbGetPage(response, callback): if response.code == 200: clog.debug('Received OK response: %s' % response.code, syst) d = readBody(response) d.addCallback(callback) return d else: clog.error('Received bad response: %s' % response.code, syst) return defer.fail(response)
def userKicked(self, kickee, channel, kicker, message): clog.info('%s was kicked by %s from %s: %s' % (kickee, kicker, channel, message)) if channel == self.channelName: self.factory.handle.ircUserCount -= 1 try: self.nicklist.remove(kickee) except(ValueError): clog.error('(userKiced) User %s not in nicklist' % kickee)
def retryDatabase(error, operation, sql, binds, attempt): if attempt >= 5: clog.error(error.getBriefTraceback(), 'Reached max attempts: %s' % attempt) return clog.warning(error.getBriefTraceback(), 'retrying attempt: %s' % attempt) if operation == 'operate': return operate(sql, binds, attempt) elif operation == 'query': return query(sql, binds, attempt)
def main(): clog.error('test custom log', 'cLog tester') clog.warning('test custom log', 'cLog tester') yukari = Connections() yukari.startCytubeClient() yukari.ircConnect() reactor.callWhenRunning(createShellServer, yukari) reactor.addSystemEventTrigger('before', 'shutdown', yukari.cleanup) reactor.run()
def importPlugins(path): try: files = os.listdir(path) except(OSError): clog.error('Error importing plugins. Invalid path.', syst) importPath = path.replace('/', '.') moduleNames = [importPath + i[:-3] for i in files if not i.startswith('_') and i.endswith('.py') and not i.startswith('test')] modules = map(importlib.import_module, moduleNames) return modules
def getIndexFromUid(self, uid): """ Return video index of self.playlist given an UID """ try: media = (i for i in self.playlist if i['uid'] == uid).next() index = self.playlist.index(media) clog.debug('(getIndexFromUid) Looking up uid %s, index is %s' % (uid, index), sys) return index except StopIteration as e: clog.error('(getIndexFromUid) media UID %s not found' % uid, sys)
def _load_allowed(self): # blocking try: with open('plugins/twitter.allowed') as f: return [x.strip('\n') for x in f.readlines()] except(IOError): clog.error("IOError", syst) return except: clog.error("Error loading allowed list!", syst) return
def removeUser(self, res, username): clog.debug('(removeUser) Removing user', sys) try: if not self.userdict[username]['inChannel']: del self.userdict[username] clog.debug('(removeUser) deleted %s' % username, sys) else: clog.error('(removeUser) skipping: user %s in channel' % username, sys) except(KeyError): clog.error('(removeUser) Failed: user %s not in userdict' % username, sys) return KeyError
def cbQueryIrcuser(self, res, values): try: keyId = res[0][0] if keyId is None: clog.error('received a NONE') raise IndexError else: return defer.succeed(keyId) except(IndexError): d = database.insertIrcuser(*values) d.addCallback(lambda resp: defer.succeed(resp[0][0])) return d
def importPlugins(path): try: files = os.listdir(path) except (OSError): clog.error('Error importing plugins. Invalid path.', sys) importPath = path.replace('/', '.') moduleNames = [ importPath + i[:-3] for i in files if not i.startswith('_') and i.endswith('.py') and not i.startswith('test') ] modules = map(importlib.import_module, moduleNames) return modules
def cancelChatLog(self): try: self.dChat.cancel() clog.debug('(cancelChatLog) Cancelled log timer', sys) except AttributeError as e: clog.debug('(cancelChatLog): %s' % e, sys) except AlreadyCancelled as e: clog.debug('(cancelChatLog): %s' % e, sys) except AlreadyCalled as e: clog.debug('(cancelChatLog): %s' % e, sys) except NameError as e: clog.error('(cancelChatLog): %s' % e, sys)
def connectionLost(self, reason): self.factory.service.parent.ds = False clog.error("connection lost at protocol", syst) self._connectionLost(reason) self.cleanUp() try: if self.heartbeat.running: self.heartbeat.stop() except(AttributeError): pass if self.factory.service.parent.dcRestart: self.factory.service.checkChannelConfig(self.factory.ws)
def parseTwitterResponse(self, body, yuka, source, user): try: res = json.loads(body) except(ValueError, TypeError): clog.error("Error decoding json", syst) return if res.get("errors"): clog.error("error from Twitter! %s" % body, syst) msg = "Something went wrong .. .." elif res.get("created_at") and res.get("id_str"): msg = "https://twitter.com/statuses/%s" % res.get("id_str") else: msg = "Something isn't right..." yuka.reply('[tweet] %s' % msg, source, user)
def cbChangeProfile(self, res): #clog.debug('(cbChangeProfile) %s' % res, sys) if len(res) < 2: # no flagged row clog.error('(cbChangeProfile) CyProfile table incorrect.', sys) return defer.fail(None) currentRow = res[0][0] maxRow = res[1][0] if currentRow == maxRow: nextRow = 1 else: nextRow = currentRow + 1 d = database.getProfile(nextRow) d.addCallback(self.setNewProfile, currentRow, nextRow) return d
def cbChangeProfile(self, res): #clog.debug('(cbChangeProfile) %s' % res, syst) if len(res) < 2: # no flagged row clog.error('(cbChangeProfile) CyProfile table incorrect.', syst) return defer.fail(None) currentRow = res[0][0] maxRow = res[1][0] if currentRow == maxRow: nextRow = 1 else: nextRow = currentRow + 1 d = database.getProfile(nextRow) d.addCallback(self.setNewProfile, currentRow, nextRow) return d
def connectCy(self, startresults): if not startresults[0][0]: clog.error('Failed to retrieve server socket.io configuration') self.restartConnection() else: sioClientConfig = json.loads(startresults[0][1]) host = config['Cytube']['domain'] s = sioClientConfig['servers'][1]['url'] ws = 'ws://{0}/socket.io/?transport=websocket'.format( s[s.find('//') + 2:]) clog.debug('(cySocketIo) Cytube ws uri: %s' % ws, sys) self.wsFactory = WsFactory(ws) self.wsFactory.handle = self connectWS(self.wsFactory)
def checkRegistered(self, username): """ Return wether a Cytube user is registered (1) or a guest (0) given a username. Checks self.userdict for rank information.""" if username == '[server]': return 1 else: try: user = self.userdict[username] except KeyError as e: clog.error('(checkRegistered): %s' % e, sys) #raise if user['rank'] == 0: return 0 else: return 1
def loadLikes(self, cy, mType, mId): uid = cy.getUidFromTypeId(mType, mId) i = cy.getIndexFromUid(uid) if i is None: clog.error('Got None for index getIndexFromUid', syst) try: queueId = cy.playlist[i]['qid'] d = database.getLikes(queueId) except (KeyError): clog.error('(loadLikes) Key is not ready!', syst) d = cy.playlist[i]['qDeferred'] d.addCallback(database.getLikes) # result [(userId, 1), (6, 1)] d.addCallback(self.sendLikes, cy) return d
def _com_vocadb(self, username, msg): if not vdb: return try: songId = int(msg.split()[1]) except IndexError: clog.error('(_com_vocadb) Index Error by %s' % username, sys) return except ValueError: clog.error('(_com_vocadb) Value Error by %s' % username, sys) return userId = self.userdict[username]['keyId'] timeNow = round(time.time(), 2) mType, mId, mTitle = self.nowPlaying d = vdbapi.requestSongById(mType, mId, songId, userId, timeNow, 4)
def loadLikes(self, cy, mType, mId): uid = cy.getUidFromTypeId(mType, mId) i = cy.getIndexFromUid(uid) if i is None: clog.error('Got None for index getIndexFromUid', syst) try: queueId = cy.playlist[i]['qid'] d = database.getLikes(queueId) except(KeyError): clog.error('(loadLikes) Key is not ready!', syst) d = cy.playlist[i]['qDeferred'] d.addCallback(database.getLikes) # result [(userId, 1), (6, 1)] d.addCallback(self.sendLikes, cy) return d
def processYtCheck(body, ytId): clog.info(body) try: res = json.loads(body) except(ValueError): # not valid json clog.error('(proccessYtCheck) Error processing JSON') return 'BadResponse' accesses = res['entry']['yt$accessControl'] for access in accesses: if access['action'] == 'embed': embeddable = access['permission'] clog.info('(processYtInfo) embed allowed: %s' % embeddable) if embeddable != 'allowed': return 'NoEmbed' return 'EmbedOk'
def processVdbJson(body): clog.info('(processVdbJson) Received reply from VocaDB', syst) # clog.debug('(processVdbJson) %s' % body, syst) body = body.decode('UTF-8') try: pbody = json.loads(body) except (ValueError): return defer.fail(None) try: if 'message' in pbody: clog.error(pbody['message'], syst) except (TypeError): # body is null (pbody is None) clog.warning('(processVdbJson) null from Vocadb', syst) return defer.succeed(0) return defer.succeed((pbody))
def processVdbJson(body): clog.info('(processVdbJson) Received reply from VocaDB', syst) # clog.debug('(processVdbJson) %s' % body, syst) body = body.decode('UTF-8') try: pbody = json.loads(body) except(ValueError): return defer.fail(None) try: if 'message' in pbody: clog.error(pbody['message'], syst) except(TypeError): # body is null (pbody is None) clog.warning('(processVdbJson) null from Vocadb', syst) return defer.succeed(0) return defer.succeed((pbody))
def processVdbJson(body): clog.info("(processVdbJson) Received reply from VocaDB", syst) clog.debug("(processVdbJson) %s" % body, syst) body = body.decode("UTF-8") try: pbody = json.loads(body) except (ValueError): return defer.fail(None) try: if "message" in pbody: clog.error(pbody["message"], syst) except (TypeError): # body is null (pbody is None) clog.error("(processVdbJson) null from Vocadb", syst) return defer.succeed(0) songId = pbody["id"] return defer.succeed((body, songId))
def lineReceived(self, line): clog.info(line, sys) d = checkLine(line) if not d: self.sendBadArgs('Unknown', 'Invalid JSON') return request = self.parseDict(d) if request: callType, args = request thunk = getattr(self, '_rin_%s' % (callType, ), None) if thunk is not None: thunk(args) elif thunk is None: response = {'callType': None, 'result': 'badname'} self.sendLineAndLog(json.dumps(response)) else: clog.error('improper request', sys)
def searchYtDesc(jsonResponse, mType, mId, timeNow): items = jsonResponse['items'] if not items: clog.error('searchYtDesc: no video found', syst) return defer.fail(Exception('No video found')) desc = items[0]['snippet']['description'] m = nicoMatch.search(desc) if m: nicoId = m.group(0) clog.debug(nicoId, 'searchYtDesc') d = requestApiByPv('NicoNico', nicoId, timeNow) d.addCallback(nicoAcquire) d.addCallback(database.insertMediaSongPv, mType, mId, 1, timeNow) return d else: database.insertMediaSongPv(0, mType, mId, 1, timeNow) return defer.fail(Exception('No NicoId in Description found'))
def flagOrDelete(self, res, media, mType, mId): if res == 'EmbedOk': database.unflagMedia(0b1, mType, mId) elif res == 'Status503': clog.error('(flagOrDelete) Youtube service unavailable.', sys) elif res == 'NetworkError': clog.error('(flagOrDelete) There was a network error.', sys) elif res in ('NoEmbed', 'Status403', 'Status404'): self.doDeleteMedia(media['type'], media['id']) mediaTitle = media['title'].encode('utf-8') msg = 'Removing non-playable media %s' % mediaTitle database.flagMedia(0b1, mType, mId) self.doSendChat(msg) clog.info(msg)
def _com_reprint(self, cy, username, args, source): if not args or len(args) > 11 or not args.startswith('sm'): clog.debug('reprint - no args or bad args', syst) return # user must be rank at least rank 3 AND be on the allowed.txt list rank = cy._getRank(username) if rank < 2: clog.debug('not enough rank for $reprint', syst) return try: with open('connections/cytube/plugins/loaders/allowed.cfg') as f: allowed = f.read().lower().split() except (IOError): clog.error("Reprint cancelled - No allowed.txt found", syst) return if username.lower() not in allowed: clog.debug('not in allowed.txt for $reprint', syst) return try: if cy.reprint is False: clog.debug('cy.reprint is False', syst) return elif self.reprint == 'IP': cy.doSendChat('[reprint] Busy with another request.', toIrc=False) return except (AttributeError): cy.reprint = True path = 'connections/cytube/plugins/loaders' try: d = json.load(open('%s/videos.json' % path)) except (IOError, ValueError): #No file, #not a JSON clog.error('Error loading file "videos.json"', syst) return if args in d: cy.doSendChat('[reprint] This video has already been reprinted', toIrc=False) return p = ReprintProtocol(self, cy) clog.warning('Spawning Reprint process!', syst) subprocess = reactor.spawnProcess(p, sys.executable, [ 'python', 'reprinter.py', '--smid', args, '--user', config['reprinter']['nicoid'], '--pass', config['reprinter']['nicopass'] ], os.environ, path)
def _com_reprint(self, cy, username, args, source): if not args or len(args) > 11 or not args.startswith('sm'): clog.debug('reprint - no args or bad args', syst) return # user must be rank at least rank 3 AND be on the allowed.txt list rank = cy._getRank(username) if rank < 2: clog.debug('not enough rank for $reprint', syst) return try: with open('connections/cytube/plugins/loaders/allowed.cfg') as f: allowed = f.read().lower().split() except(IOError): clog.error("Reprint cancelled - No allowed.txt found", syst) return if username.lower() not in allowed: clog.debug('not in allowed.txt for $reprint', syst) return try: if cy.reprint is False: clog.debug('cy.reprint is False', syst) return elif self.reprint == 'IP': cy.doSendChat('[reprint] Busy with another request.', toIrc=False) return except(AttributeError): cy.reprint = True path = 'connections/cytube/plugins/loaders' try: d = json.load(open('%s/videos.json' % path)) except(IOError, ValueError): #No file, #not a JSON clog.error('Error loading file "videos.json"', syst) return if args in d: cy.doSendChat('[reprint] This video has already been reprinted', toIrc=False) return p = ReprintProtocol(self, cy) clog.warning('Spawning Reprint process!', syst) subprocess = reactor.spawnProcess(p, sys.executable, ['python', 'reprinter.py', '--smid', args, '--user', config['reprinter']['nicoid'], '--pass', config['reprinter']['nicopass']], os.environ, path)
def _cbYtDesc(result, mType, mId, nameLower, isReg): items = result['items'] if not items: clog.error('no youtube description', syst) saveSongResults(None, mType, mId, nameLower, isReg, 1) return desc = items[0]['snippet']['description'] rx = r'sm[0-9]{6,9}|nm[0-9]{6,9}' m = re.search(rx, desc) clog.info('looking for smid in yt desc', syst) if m: nicoId = m.group(0) clog.info('found nicoid: %s' % nicoId, syst) d = getVdbByPvId('nico', nicoId) d.addCallback(saveSongResults, mType, mId, nameLower, isReg, 1) return d else: clog.info('did not find nicoid in description', syst) return saveSongResults(None, mType, mId, nameLower, isReg, 0)
def _likeMedia(self, cy, username, args, source, value): if not cy.nowPlayingMedia: return if args is not None: mType, mId = args.split(', ') else: mType = cy.nowPlayingMedia['type'] mId = cy.nowPlayingMedia['id'] clog.info('(_com_like):type:%s, id:%s' % (mType, mId), syst) uid = cy.getUidFromTypeId(mType, mId) if uid is None: clog.error('Got None for UID _likeMedia', syst) i = cy.getIndexFromUid(uid) userId = cy.userdict[username]['keyId'] qid = cy.playlist[i]['qid'] d = database.queryMediaId(mType, mId) d.addCallback(self.processResult) d.addCallback(database.insertReplaceLike, qid, userId, getTime(), value) d.addCallback(self.updateCurrentLikes, cy, username, value)
def _q_announceQueue(self, cy, fdict): if not self.announce: return try: title = fdict['args'][0]['item']['media']['title'] queueby = fdict['args'][0]['item']['queueby'] after = fdict['args'][0]['after'] except(KeyError): clog.error('KeyError unpacking frame.', syst) return # if the 2nd to last (becuase last is the one we just added) media's # UID is same as after, then it means it as placed at the end try: last = cy.playlist[-2]['uid'] except(IndexError): # when the playlist is empty (before this queue) last = 0 if last == after: next = ':' else: next = 'next:' if time.time() - self.lastCycallQueue < self.queueThreshold: self.queueCounter += 1 try: self.later.reset(self.queueThreshold) except(AlreadyCalled, AlreadyCancelled, NameError, TypeError, AttributeError): self.queueCounter = 1 self.later = reactor.callLater(self.queueThreshold, self.sendAnnounce, cy, title, queueby, next) else: self.queueCounter = 0 self.sendAnnounce(cy, title, queueby, next) self.lastCycallQueue = time.time()
def logProcess(self, user, msg, flag): timeNow = getTime() nickname = user.split('!')[0] i = user.find('~') j = user.find('@') username = user[i + 1:j] host = user[j + 1:] if nickname in self.nickdict: keyId = self.nickdict[nickname]['keyId'] if keyId is None: # a callback for the keyId must already be registered clog.error('(logProcess) key None for user %s' % nickname, sys) dd = self.nickdict[nickname]['deferred'] dd.addCallback(self.logChat, 3, timeNow, msg, flag) if keyId: d = self.logChat(keyId, 3, timeNow, msg, flag) else: self.nickdict[nickname] = {'keyId': None, 'deferred': None} clog.debug('(logProcess) added %s to nickdict' % nickname, sys) dd = self.queryOrAddUser(nickname, username, host) dd.addCallback(self.logChat, 3, timeNow, msg, flag) self.nickdict[nickname]['deferred'] = dd
def logProcess(self, user, msg): timeNow = round(time.time(), 2) nickname = user.split('!')[0] i = user.find('~') j = user.find('@') username = user[i+1:j] host = user[j+1:] if nickname in self.nickdict: keyId = self.nickdict[nickname]['keyId'] if keyId is None: # a callback for the keyId must already be registered clog.error('(logProcess) key None for user %s' % nickname, sys) dd = self.nickdict[nickname]['deferred'] dd.addCallback(self.logChat, 3, timeNow, msg) if keyId: d = self.logChat(keyId, 3, timeNow, msg) else: self.nickdict[nickname] = {'keyId': None, 'deferred': None} clog.debug('(logProcess) added %s to nickdict' % nickname, sys) dd = self.queryOrAddUser(nickname, username, host) dd.addCallback(self.logChat, 3, timeNow, msg) self.nickdict[nickname]['deferred'] = dd
def processVdbJsonForSongId(body): clog.info('(processVdbJsonForSongId) Received reply from VocaDB', syst) # clog.debug('(processVdbJsonForSongId) %s' % body, syst) body = body.decode('UTF-8') try: pbody = json.loads(body) except (ValueError): return defer.fail(None) try: if 'message' in pbody: clog.error(pbody['message'], syst) except (TypeError): # body is null (pbody is None) clog.warning('(processVdbJsonForSongId) null from Vocadb', syst) return defer.succeed(0) songId = pbody.get('id') # Couldn't find songId, this might be a list of songs...so pick the first ;) if not songId: items = pbody.get('items') if items and items[0]: songId = items[0]['id'] return defer.succeed((body, songId))
def _q_announceQueue(self, cy, fdict): if not self.announce: return try: title = fdict['args'][0]['item']['media']['title'] queueby = fdict['args'][0]['item']['queueby'] after = fdict['args'][0]['after'] except (KeyError): clog.error('KeyError unpacking frame.', syst) return # if the 2nd to last (becuase last is the one we just added) media's # UID is same as after, then it means it as placed at the end try: last = cy.playlist[-2]['uid'] except (IndexError): # when the playlist is empty (before this queue) cy.sendCyWhisper('%s added: %s!!!' % (queueby, title)) return if last == after: next = ':' else: next = 'next:' cy.sendCyWhisper('%s added %s %s!' % (queueby, next, title))
def startPokeTimer(self, cy): """ Starts poke timer if only one user left (besides Yukari) in the channel and timer hasn't been run for past 24h. It will be cancelled on: -user join -user leave """ self.stopTimer(cy) if ((time.time() - self.lastPoke < self.pokeInterval) or (len(cy.userdict) != 2)): return username = None for name in cy.userdict.iterkeys(): if name != cy.name: username = name if not username: clog.error('Error at startTimer. 2 users but no non-Yukari name', syst) return from twisted.internet import reactor self.pokeTimer = reactor.callLater(self.pokeTime, self.yukariPoke, cy, username) cy.laters.append(self.pokeTimer) clog.warning('Started poke timer for %s!' % username, syst) self.lastChatAtTimer = cy.factory.handle.lastIrcChat
def cyPostErr(self, err): clog.error(err, sys) return err
def errReceived(self, data): clog.error('[errRec] %s' % data.decode('utf8'), syst)
def printError(err): clog.error('Error %s' % err) return err
def networkError(err): clog.error('Network Error %s' % err.value) return 'NetworkError'
def dbErr(self, err): clog.error('(dbErr): %s' % err.value, sys) clog.error('(dbErr): %s' % dir(err), sys) clog.error('(dbErr): %s' % err.printTraceback(), sys)
def errorHandler(failure): clog.error(failure, syst) return failure
def failedStartCytube(self, result): clog.error(result) self.restartConnection()