def handle_fleetconnect(bot, ievent): """ arguments: <botname> - connect a fleet bot to it's server. """ try: botname = ievent.args[0] except IndexError: ievent.missing('<botname>') return try: fleet = getfleet() fleetbot = fleet.byname(botname) if fleetbot: start_new_thread(fleetbot.connect, ()) ievent.reply('%s connect thread started' % botname) else: ievent.reply("can't connect %s .. trying enable" % botname) cfg = Config('fleet' + os.sep + stripname(botname) + os.sep + 'config') cfg['disable'] = 0 if not cfg.name: cfg.name = botname cfg.save() bot = fleet.makebot(cfg.type, cfg.name, cfg) if bot: ievent.reply('enabled and started %s bot' % botname) start_new_thread(bot.start, ()) else: ievent.reply("can't make %s bot" % cfg.name) except Exception as ex: ievent.reply(str(ex))
def handle_privmsg(self, ievent): """ check if PRIVMSG is command, if so dispatch. """ if ievent.nick in self.nicks401: logging.debug("%s - %s is available again" % (self.cfg,name, ievent.nick)) self.nicks401.remove(ievent.nick) if not ievent.txt: return ievent.nodispatch = False chat = re.search(dccchatre, ievent.txt) if chat: if self.users.allowed(ievent.userhost, 'USER'): start_new_thread(self._dccconnect, (ievent.nick, ievent.userhost, chat.group(1), chat.group(2))) return if '\001' in ievent.txt: Irc.handle_privmsg(self, ievent) return ievent.bot = self ievent.sock = self.sock chan = ievent.channel if chan == self.cfg.nick: ievent.msg = True ievent.speed = 4 ievent.printto = ievent.nick ccs = ['!', '@', self.cfg['defaultcc']] if ievent.isresponse: return if self.cfg['noccinmsg'] and self.msg: self.put(ievent) elif ievent.txt[0] in ccs: self.put(ievent) return self.put(ievent)
def fleet_add(bot, ievent): """ arguments: <name> <type> <server>|<botjid> <nick>|<jabberpasswd> [<ircpass>] - add a newly created bot to the fleet. """ try: name, type, server, nick, password = ievent.rest.split() except ValueError: try: name, type, server, nick = ievent.rest.split() password = "" except ValueError: ievent.missing("<name> <type> <server>|<botjid> <nick>|<jabberpass> [<ircpasswd>]") ; return type = type.lower() fleet = getfleet() bot = fleet.byname(name) if bot: ievent.reply("%s bot already exists" % name) ; return cfg = Config('fleet' + os.sep + stripname(name) + os.sep + 'config') cfg.disable = 0 if type == "irc": cfg.port = 6667 cfg.server = server cfg.nick = nick cfg.password = password elif type in ["xmpp", "sxmpp"]: cfg.port = 4442 cfg.host = server try: n, serv = cfg.host.split("@") except (ValueError, TypeError): pass cfg.server = serv cfg.password = nick cfg.save() bot = fleet.makebot(type, name, cfg) fleet.addbot(bot) if bot: ievent.reply('enabled and started %s bot - %s' % (name, cfg.filename)) start_new_thread(bot.start, ()) else: ievent.reply("can't make %s bot" % cfg.name)
def incoming(self, data): """ process incoming hubbub data. """ result = feedparser.parse(data) url = find_self_url(result.feed.links) logging.debug("%s - %s" % (url, data)) try: item = self.byurl(url) if not item: logging.warn("can't find feed for %s" % url) ; return if not item.data.running: logging.warn("%s is not in running mode" % item.data.url) ; return if not item.data.url or item.data.url == 'urlnotset': item.data.url = url item.save() if item: loopover = item.data.watchchannels name = item.data.name else: logging.warn("can't find %s item" % url) ; return logging.warn("loopover in %s peek is: %s" % (name, loopover)) counter = 1 for i in loopover: if len(i) == 3: try: (botname, type, channel) = i except: try: (botname, type, channel) = loads(i) except: logging.warn('%s is not in the format (botname, bottype, channel)' % str(item)) continue else: logging.warn('%s is not in the format (botname, bottype, channel)' % item.data.url) continue counter += 1 start_new_thread(self.work, (botname, type, channel, result.entries, url), {"_countdown": counter}) except Exception as ex: handle_exception(txt=url) return True
def check(self): """ run check to see if job needs to be scheduled. """ if self.nextjob <= time.time(): logging.info('running %s - %s' % (str(self.func), self.description)) self.next = time.time() + self.interval thr.start_new_thread(self.do, ()) self.counts += 1 if self.repeat > 0 and self.counts >= self.repeat: return False return True
def init(): """ init plugin """ if not cfg.get("enable"): return 1 callbacks.add("PRIVMSG", cb_markovtalk, cb_markovtalk_test, threaded=True) callbacks.add("JOIN", cb_markovjoin, threaded=True) callbacks.add("MESSAGE", cb_markovtalk, cb_markovtalk_test, threaded=True) callbacks.add("CONSOLE", cb_markovtalk, cb_markovtalk_test, threaded=True) start_new_thread(markovtrain, (markovlearn.data.l,)) return 1
def _dodcc(self, sock, nick, userhost, channel=None): """ send welcome message and loop for dcc commands. """ if not nick or not userhost: return try: sock.send(bytes('Welcome to the T I M E L I N E partyline ' + nick + " ;]\n", self.encoding or "utf-8")) partylist = partyline.list_nicks() if partylist: sock.send(bytes("people on the partyline: %s\n" % ' .. '.join(partylist, self.encoding or "utf-8"))) sock.send(bytes("control character is ! .. bot broadcast is @\n", self.encoding or "utf-8")) except Exception as ex: handle_exception() logging.error('%s - dcc error: %s' % (self.cfg.name, str(ex))) return start_new_thread(self._dccloop, (sock, nick, userhost, channel))
def handle_markovlearnadd(bot, ievent): """ add log or url to be learned at startup or reload """ try: item = ievent.args[0] except IndexError: ievent.missing("<channel>|<url>|spider:<url>") return if item in markovlearn.data.l: ievent.reply("%s is already in learnlist" % item) return markovlearn.data.l.append(item) markovlearn.save() start_new_thread(markovtrain, (markovlearn.data.l,)) ievent.reply("done")
def markovtrain(l): """ train items in list """ time.sleep(1) logging.warn("list to scan is: %s" % ",".join(l)) for i in l: if i.startswith("http://"): start_new_thread(markovlearnurl, (i,)) elif i.startswith("spider://"): start_new_thread(markovlearnspider, (i,)) elif i.startswith("spiders://"): start_new_thread(markovlearnspider, (i,)) else: start_new_thread(markovlearnlog, (i,)) return 1
def init(): """ init the udp plugin. """ if cfg['udp']: global udplistener start_new_thread(udplistener._listen, ()) start_new_thread(udplistener._handleloop, ()) start_new_thread(udplistener._outloop, ()) return 1
def init_threaded(): global server if server: logging.warn("irccat server is already running.") ; return if not cfg.enable: logging.warn("irccat is not enabled.") ; return time.sleep(2) if not cfg.host or not cfg.port: cfg["host"] = "localhost" cfg["port"] = 54321 cfg["botnames"] = ["default-sxmpp",] cfg["aliases"] = {} if not cfg.aliases: cfg.aliases = {} cfg.save() try: server = socketserver.TCPServer((cfg["host"], int(cfg["port"])), IrcCatListener) except Exception as ex: logging.error("%s - %s:%s" % (str(ex), cfg["host"], cfg["port"])) ; return logging.warn("starting irccat server on %s:%s" % (cfg["host"], cfg["port"])) thr = start_new_thread(server.serve_forever, ()) thr.join(3)
def start(self): """ start the watcher. """ self.running = True start_new_thread(self.watch, ())
def session_start(self, event): logging.warn("LOGGED ON %s" % self.cfg.server or self.cfg.host) time.sleep(0.01) start_new_thread(self.joinchannels, ())
def shutdown(): global server if server: logging.warn("shutting down the irccat server") start_new_thread(server.shutdown, ()) time.sleep(2)
def _dccresume(self, sock, nick, userhost, channel=None): """ resume dcc loop. """ if not nick or not userhost: return start_new_thread(self._dccloop, (sock, nick, userhost, channel))