def scheduling(self, timeout=None): logging.info("! start %s" % sname(self)) self._connected.wait() while self._status: event = self._queue.get(timeout=timeout) if not event: break try: self.handle_event(event) except: logging.error(get_exception()) logging.info("! stop %s" % sname(self)) self.ready()
def event(self): event = Event() event.btype = sname(self) event.txt = str(os.read(fd, 512), "utf-8") event.txt = event.txt.rstrip() event.origin = "root@shell" yield event
def cmnd(self, txt): event = Event() event._server = self._cfg.server event.btype = sname(self) event.origin = "user@bot" event.txt = txt self.dispatch(event) return event
def event(self): e = Event() e.server = self._cfg.server e.btype = sname(self) e.txt = input() e.txt = e.txt.rstrip() e.origin = "root@shell" return e
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._connected = Object() self._poll = select.epoll() self._resume = Object() self._status = "running" self._starttime = time.time() thr = self.launch(self._start, name="%s.engine" % sname(self), daemon=True) self._thrs.append(thr)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._connected = Object() self._queue = queue.Queue() self._cbs = OOL() self._table = Object() self._handlers = OOL() self._status = "running" self._thrs = [] thr = self.launch(self.scheduling, name="%s.schedule" % sname(self), daemon=True) self._thrs.append(thr)
def run(self): self._status = "working" while self._status: _func, args = self._queue.get() if not self._status or not _func: break self._name = self.name or sname(_func) self.setName(self._name) self._begin = time.time() self._result = _func(*args) self._last = time.time() try: args[0].ready() except: pass if self.once: break self.ready() return self._result
def parsing(self, txt): rawstr = str(txt) obj = Event() obj.server = self._cfg.server obj.cc = self.cc obj.btype = sname(self) obj.arguments = [] arguments = rawstr.split() obj.origin = arguments[0] if obj.origin.startswith(":"): obj.origin = obj.origin[1:] if len(arguments) > 1: obj.command = arguments[1] if len(arguments) > 2: txtlist = [] adding = False for arg in arguments[2:]: if arg.startswith(":"): adding = True txtlist.append(arg[1:]) continue if adding: txtlist.append(arg) else: obj.arguments.append(arg) obj.txt = " ".join(txtlist) else: obj.command = obj.origin obj.origin = self._cfg.server try: obj.nick, obj.userhost = obj.origin.split("!") except: pass if obj.arguments: obj.target = obj.arguments[-1] else: obj.target = "" if obj.target.startswith("#"): obj.channel = obj.target if not obj.txt and len(arguments) == 1: obj.txt = arguments[1] if not obj.txt: obj.txt = rawstr.split(":")[-1] return obj
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.channels = [] self._cfg = Config() self._cfg.load(sname(self).lower()) if not self._cfg.server: self._cfg.server = "host"
def fleet(event): """ show list of running bots. """ for bot in _fleet: if event._parsed.rest and event._parsed.rest not in sname(bot).lower(): continue event.reply(bot.nice())