def list(self, stanza, *args): """列出所有成员""" frm = stanza.get_from() femail = "%s@%s" % (frm.node, frm.domain) members = get_members() body = [] for m in members: email = m.get('email') r = '%s <%s>' % (m.get('nick'), m.get('email')) if email == femail: r = '** ' + r elif is_online(email): r = ' * ' + r else: r = ' ' + r body.append(r) body = sorted(body, key = lambda k:k[1], reverse=True) body.insert(0, 'Pythoner Club 所有成员(** 表示你自己, * 表示在线):') return self._send_cmd_result(stanza, '\n'.join(body))
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