def print_roster_item(self, item): if item.name: name = item.name else: name = u"" email = "%s@%s" % (item.jid.node, item.jid.domain) if not get_member(email): add_member(item.jid) print ( u'%s "%s" subscription=%s groups=%s' % (unicode(item.jid), name, item.subscription, u",".join(item.groups)) )
def msgto(self, stanza, *args): """单独给某用户发消息 eg $msgto nick hello(给nick发送hello) 也可以使用@<nick> 消息""" if len(args) > 1: nick = args[0] receiver = get_member(nick = nick) body = ' '.join(args[1:]) if not receiver: m = self._send_cmd_result(stanza, "%s 用户不存在" % nick) else: m = send_to_msg(stanza, receiver, body) else: m = self.help(stanza, 'mgsto') return m
def send_all_msg(stanza, body): frm = stanza.get_from() email = '%s@%s' % (frm.node, frm.domain) nick = get_nick(email) add_history(email, 'all', body) tos = get_members(email) ms = [] if '@' in body: r = re.findall(r'@<(.*?)>', body) mem = [get_member(nick=n) for n in r if get_member(nick = n)] if mem: if body.startswith('@<'): b = re.sub(r'^@<.*?>', '', body) return send_to_msg(stanza, mem[0], b) b = '%s 提到了你说: %s' % (nick, body) ml = [send_to_msg(stanza, to, b) for to in mem] ms += ml elif body.strip() == 'help': return send_command(stanza, '$help') body = "[%s] %s" % (nick, body) for to in tos: m = send_msg(stanza, to, body) ms.append(m) return ms
def rm(self, stanza, *args): """剔除用户($rm nick1 nick2 nick3...)""" emails = [get_member(nick = n) for n in args] if emails >= 1: p = [] for e in emails: jid = JID(e) p.append( Presence( to_jid = jid, stanza_type='unsubscribe' )) del_member(jid) else: p = self.help(stanza, 'rm') return p
def presence(self, stanza): frm = stanza.get_from() msg = u"%s has become " % (frm) t = stanza.get_type() status = stanza.get_status() show = stanza.get_show() frm_email = "%s@%s" % (frm.node, frm.domain) if frm_email != DAEMONACCOUNT[0]: if t == "unavailable": msg += u"unavailable" change_status(frm, 0, show) else: msg += u"available" if not get_member(frm_email) and frm_email != USER: add_member(frm) change_status(frm, 1, show) if show: msg += u"(%s)" % (show,) if status: msg += u": " + status logger.info(msg)