Пример #1
0
 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)
Пример #2
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)