Beispiel #1
0
    def presence_control(self, stanza):
        msg = unicode(stanza.get_from())
        t = stanza.get_type()
        frm = stanza.get_from()
        frm_email = "%s@%s" % (frm.node, frm.domain)
        if frm_email == DAEMONACCOUNT[0]:
            p = Presence(to_jid=frm, stanza_type="subscibe")
            return stanza.make_accept_response(), p
        if t == "subscribe":
            msg += u" has requested presence subscription."
            body = "%s 加入群" % frm.node
            p = Presence(to_jid=frm, stanza_type="subscibe")
            send_all_msg(stanza, body)
            add_member(frm)
        elif t == "subscribed":
            msg += u" has accepted our presence subscription request."
            p = Presence(to_jid=frm, stanza_type="subscibe")
            add_member(frm)
        elif t == "unsubscribe":
            msg += u" has canceled his subscription of our."
            body = "%s 离开群" % frm.node
            send_all_msg(stanza, body)
            del_member(frm)
        elif t == "unsubscribed":
            msg += u" has canceled our subscription of his presence."
            del_member(frm)

        logger.info(msg)

        return stanza.make_accept_response(), p
Beispiel #2
0
    def message(self, stanza):
        body = stanza.get_body()
        subject = stanza.get_subject()
        t = stanza.get_type()
        logger.info(u"Message from %s received." % (unicode(stanza.get_from())))
        if subject:
            logger.info(u'Subject: "%s".' % (subject,))
        if t:
            logger.info(u'Type: "%s".' % (t,))
        else:
            logger.info(u'Type: "normal".')
        if stanza.get_type() == "headline":
            # 'headline' messages should never be replied to
            return True
        if subject:
            subject = u"Re: " + subject
        if not body:
            logger.info(u'Body: "%s".' % (body,))
            return
        if body.startswith("$"):
            m = send_command(stanza, body)
        else:
            m = send_all_msg(stanza, body)
        if not DEBUG:
            return m
        logger.info("message %s", m)
        if isinstance(m, list):
            for i in m:
                logger.info("message to %s", i.get_to())
                logger.info("message type %s", i.get_type())
                logger.info("message body %s", i.get_body())
        else:
            logger.info("message to %s", m.get_to())
            logger.info("message body %s", m.get_body())
            logger.info("message type %s", m.get_type())

        return m