def test_cmnds(self): for cmnd in sorted(cmnds.handlers.keys()): if cmnd in ["test", "fetcher"]: continue event = Event() event.txt = cmnd + " arg1" event._bot = bot event.origin = "tester@bot" event.parse() logging.warn("< %s" % event.txt) func = cmnds.get(event.cmnd) if func: launcher.launch(func, event) events.append(event) for event in events: event.wait(3.0)
def messaged(self, data): from meds.mods import cmnds logging.debug("< %s.read %s" % (self.type, data)) m = Event() m.update(data) m._bot = self if m.type == "error": logging.error("^ %s" % m.error) ; return m.cc = self.cc m["from"] = str(m["from"]) if self.user in m["from"]: logging.info("< %s.%s %s" % (self.type, m.type, m["from"])) ; return m.origin = m["from"] m.channel = m.origin m.to = m.origin m.element = "message" m.txt = m["body"] if '<delay xmlns="urn:xmpp:delay"' in str(data): logging.info("# %s.ignore %s %s" % (self.type, m.type, m.origin)) return logging.info("< %s.%s %s" % (self.type, m.type, m.origin)) m.parse() func = cmnds.get(m.cmnd) if func: func(m)
def presenced(self, data): from meds.mods import cmnds logging.debug("< %s.read %s" % (self.type, data)) o = Event() o.update(data) o._bot = self o["from"] = str(o["from"]) o.origin = o["from"] if "txt" not in o: o.txt = "" o.element = "presence" if o.type == 'subscribe': pres = Event({'to': o["from"], 'type': 'subscribed'}) self.client.send_presence(pres) pres = Event({'to': o["from"], 'type': 'subscribe'}) self.client.send_presence(pres) elif o.type == "unavailable" and o.origin in self.channels: self.channels.remove(o.origin) elif o.origin != self.user and o.origin not in self.channels: self.channels.append(o.origin) o.no_dispatch = True logging.info("< %s.%s %s" % (self.type, o.type, o.origin)) o.parse() func = cmnds.get(o.cmnd) if func: func(o)
def dccloop(self, event, s): from meds.mods import cmnds sockfile = s.makefile('rw') s.setblocking(True) while 1: try: res = sockfile.readline() if not res: break res = res.rstrip() logging.info("< %s.loop %s" % (self.type, event.origin)) e = Event() e._bot = self e.txt = res e.outer = sockfile e.origin = event.origin e.parse() func = cmnds.get(e.cmnd) if func: func(e) except socket.timeout: time.sleep(0.01) except socket.error as ex: if ex.errno in [socket.EAGAIN, ]: continue else: raise except Exception as ex: logging.error(get_exception()) sockfile.close()
def dispatch(self, event): from meds.mods import cmnds func = cmnds.get(event.cmnd) if func: launcher.launch(func, event) else: event.ready()