Esempio n. 1
0
 def _ls_users(self, stanza):
     """ 列出成员 """
     frm = stanza.from_jid
     femail = get_email(frm)
     members = get_members_info()
     onlinebody = []
     offlinebody = []
     els = []
     for m in members:
         email = m.get("email")
         if email in els:
             continue
         els.append(email)
         if email == femail:
             r = "**{0}".format(m.get("nick"))
             onlinebody.append(r)
         elif m.get("isonline"):
             r = "*{0}".format(m.get("nick"))
             if m.get("status"):
                 r += " " + m.get("status")
             onlinebody.append(r)
         else:
             r = "  " + m.get("nick")
             offlinebody.append(r)
     onlinebody = sorted(onlinebody, key=lambda k: k.decode("utf-8")[1], reverse=False)
     offlinebody = sorted(offlinebody, key=lambda k: k.decode("utf-8")[1], reverse=False)
     body = []
     body.insert(0, "Pythoner Club 所有成员(** 表示你自己, * 表示在线):")
     body.extend(onlinebody)
     body.extend(offlinebody)
     online_num = len(onlinebody)
     total = online_num + len(offlinebody)
     body.append("共列出 {0} 位成员 {1} 位在线".format(total, online_num))
     self._send_cmd_result(stanza, "\n".join(body))
     return
Esempio n. 2
0
 def _ls_channel_users(self, stanza):
     channel = get_info("channel", stanza.from_jid)
     channel = channel if channel else "main"
     frm = stanza.from_jid
     femail = get_email(frm)
     members = get_members_info()
     onlinebody = []
     offlinebody = []
     els = []
     for m in members:
         email = m.get("email")
         ch = get_info("channel", email)
         ch = ch if ch else "main"
         if ch != channel:
             continue
         if email in els:
             continue
         els.append(email)
         if email == femail:
             r = "**{0}".format(m.get("nick"))
             onlinebody.append(r)
         elif m.get("isonline"):
             r = "*{0}".format(m.get("nick"))
             if m.get("status"):
                 r += " " + m.get("status")
             onlinebody.append(r)
         else:
             r = "  " + m.get("nick")
             offlinebody.append(r)
     onlinebody = sorted(onlinebody, key=lambda k: k.decode("utf-8")[1], reverse=False)
     offlinebody = sorted(offlinebody, key=lambda k: k.decode("utf-8")[1], reverse=False)
     body = []
     body.append("当前频道({0})所有成员".format(channel))
     body.extend(onlinebody)
     body.extend(offlinebody)
     online_num = len(onlinebody)
     total = online_num + len(offlinebody)
     body.append("共列出 {0} 位成员 {1} 位在线".format(total, online_num))
     self._send_cmd_result(stanza, "\n".join(body))
     return
Esempio n. 3
0
 def ls(self, stanza, *args):
     """列出成员/模式/允许的代码,发送-ls help查看用法"""
     mode = args[0] if len(args) >= 1 else None
     if mode in ["user", "u", "users"] or not mode:
         if len(args) > 1:
             nicks = args[1:]
             self._show_nicks(stanza, nicks)
         else:
             self._ls_channel_users(stanza)
         return
     if mode in ["a", "all"]:
         self._ls_users(stanza)
     elif mode in ["ct", "codetype", "code type", "codetypes", "code types"]:
         self._ct(stanza)
     elif mode in ["m", "mode", "modes"]:
         body = ""
         for m in self._modes:
             body += "{0}:{1}\n".format(m, self._modes[m])
         self._send_cmd_result(stanza, body.strip())
     elif mode in ["c", "channel"]:
         self._ls_channels(stanza)
     else:
         members = get_members_info()
         nicks = [m.get("nick") for m in members]
         channels = [v.get("name") for v in get_channel()]
         if mode in nicks:
             self._show_nicks(stanza, [mode])
         elif mode in channels:
             self._show_channel(stanza, mode)
         else:
             body = "Usage: \n\
                     -ls                   查看当前频道成员\n\
                     -ls [a|all]               查看所有成员\n\
                     -ls [u|user] [nick]   查看用户\n\
                     -ls nick              查看nick的详细信息\n\
                     -ls [ct|codetype]     查看允许的代码类型\n\
                     -ls [m|mode]          列出所有模式\n\
                     -ls [CHANNEL]         查看CHANNLE频道详细信息\n\
                     -ls [c|channel]       列出所有频道"
             self._send_cmd_result(stanza, body)