def getTime(self, target): self.usersInfo[target] = Sender(":" + target) self.usersInfo[target].ctcpEvent['TIME'] = threading.Event() self.sendMessage(target, CmdGenerator.getCTCP("TIME")) if not self.usersInfo[target].ctcpEvent['TIME'].wait(10): return timePatterns = ["%a %b %d %H:%M:%S", "%a %b %d %H:%M:%S %Y"] retval = None for pattern in timePatterns: try: retval = datetime.datetime.strptime( self.usersInfo[target].ctcpData['TIME'], pattern) break except Exception: pass if not retval: self.logger.error("Error while parsing time %s" % self.usersInfo[target].ctcpData['TIME']) retval = datetime.datetime(2014, retval.month, retval.day, retval.hour, retval.minute, retval.second) self.usersInfo[target].ctcpData['TIME'] = retval return self.usersInfo[target].ctcpData['TIME']
def requestDCC(self, bot, sender, dest, cmd, args): if self.dccActive: host, port = self.dccSocket.getAddr() if self.dccSocket.addPending(sender): self.sendRaw(CmdGenerator.getDCCCHAT(sender.nick, host, port)) else: self.sendNotice(sender.nick, "§BDCC is not active on this bot.")
def getUser(self, target): self.usersInfo[target] = Sender(":" + target) self.sendRaw(CmdGenerator.getWHOIS(target)) if not self.usersInfo[target].whoisEvent.wait(10): return return self.usersInfo[target]
def handle_write(self): if not self.sendBuffer.empty() and (time.time() - self.timeLastWrite > self.floodLimit): msg = self.sendBuffer.get_nowait() if not ':identify' in msg: self.logger.debug("Send >" + msg.strip()) self.send(msg) self.sendBuffer.task_done() self.timeLastWrite = time.time() else: time.sleep(0.001) if not self.bot.isIdentified: if self.bot.servpass != "": self.sendBuffer.put_nowait( CmdGenerator.getPASS(self.bot.servpass)) self.sendBuffer.put_nowait( CmdGenerator.getNICK(self.bot.nick, self.bot.nick)) self.sendBuffer.put_nowait(CmdGenerator.getUSER(self.bot.nick)) self.bot.isIdentified = True if self.bot.isTerminating or self.bot.isRestarting: sys.exit(187)
def whois(bot, sender, dest, cmd, args): bot.sendRaw(CmdGenerator.getWHOIS(args[0]))
def sendMessage(self, target, msg): msgColor = Color.doColors(str(msg)) if target in self.users and self.users[target].dccSocket: self.users[target].dccSocket.sendMsg(msgColor) else: self.sendRaw(CmdGenerator.getPRIVMSG(target, msgColor))
def sendNotice(self, target, msg): msgColor = Color.doColors(str(msg)) if target in self.users and self.users[target].dccSocket: self.users[target].dccSocket.sendMsg(msgColor) else: self.sendRaw(CmdGenerator.getNOTICE(target, msgColor))
def join(self, chan): self.sendRaw(CmdGenerator.getJOIN(chan))