예제 #1
0
파일: cmd.py 프로젝트: beiliubei/clubot
    def mv(self, stanza, *args):
        """ 移动用户到指定频道 """
        if len(args) < 2:
            body = u"Usage: -mv NICK CHANNLE"
            return self._send_cmd_result(stanza, body)
        if args[1] == ".":
            distch = get_info("channel", stanza.from_jid)
        else:
            distch = args[1]
        if args[0] == "*":
            members = get_members(stanza.from_jid)
            emails = [v for v in members if get_info("channel", v) != distch]
        else:
            info = get_member(nick=args[0])
            emails = [info.get("email")]
        channel = get_channel(distch)
        if not emails:
            body = u"{0} 成员不存在".format(args[0])
            return self._send_cmd_result(stanza, body)

        if not channel:
            body = u"{0} 频道不存在".format(args[1])
            return self._send_cmd_result(stanza, body)
        nick = get_nick(stanza.from_jid)
        body = "{0} 将你移动到 {1} 频道".format(nick, distch)
        nicks = []
        for email in emails:
            nicks.append(get_nick(email))
            self._switch_channel(email, distch)
            self._message_bus.send_message(stanza, email, body)
        body = "你将 {0} 移动到 {1} 频道".format(",".join(nicks), distch)
        self._send_cmd_result(stanza, body)
예제 #2
0
파일: cmd.py 프로젝트: beiliubei/clubot
 def _ls_channels(self, stanza):
     channels = get_channel()
     body = [u"当前所有频道"]
     for c in channels:
         name = c.get("name")
         passwd = c.get("passwd")
         if passwd:
             name += " *"
         body.append(name)
     self._send_cmd_result(stanza, "\n".join(body))
예제 #3
0
파일: cmd.py 프로젝트: beiliubei/clubot
 def _show_channel(self, stanza, name):
     channel = get_channel(name)
     name = channel.get("name")
     usernum = channel.get("usernum")
     passwd = channel.get("passwd")
     isencrypt = u"是" if passwd else u"否"
     owner = channel.get("owner")
     nick = get_nick(owner) if owner != "bot" else owner
     body = "频道名称: {0}           频道人数: {1}\n" "是否加密: {2}           拥有者:{3}".format(name, usernum, isencrypt, nick)
     if owner == stanza.from_jid.bare().as_string() and passwd:
         body += "\n频道密码: " + passwd
     self._send_cmd_result(stanza, body)
예제 #4
0
파일: cmd.py 프로젝트: beiliubei/clubot
 def nick(self, stanza, *args):
     """更改昵称 eg. -nick yournewnickname"""
     if len(args) < 1:
         return self.help(stanza, "nick")
     nick = " ".join(args[0:])
     channels = [v.get("name") for v in get_channel()]
     if nick in self._invaild or nick in channels:
         return self._send_cmd_result(stanza, "昵称不合法")
     frm = stanza.from_jid
     oldnick = get_nick(frm)
     r = edit_member(frm, nick=nick)
     if r:
         body = "%s 更改昵称为 %s" % (oldnick, nick)
         self._message_bus.send_sys_msg(stanza, body)
         self._send_cmd_result(stanza, u"你的昵称现在的已经已经更改为 {0}".format(nick))
     else:
         self._send_cmd_result(stanza, "昵称已存在")
예제 #5
0
파일: cmd.py 프로젝트: beiliubei/clubot
 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)
예제 #6
0
파일: cmd.py 프로젝트: beiliubei/clubot
    def cd(self, stanza, *args):
        """ 进入模式/频道 """
        mode = args[0] if len(args) >= 1 else None
        channels = get_channel()
        cnames = [v.get("name") for v in channels]
        if not mode or (mode not in self._modes and mode not in cnames):
            body = "Usage:\n\
                    -cd MODE/CHANNEL    进入MODE模式,使用-ls m查看允许的模式"
        else:
            if mode in self._modes:
                add_info("mode", mode, stanza.from_jid)
                body = " 你已进入{0}".format(self._modes[mode])
            else:
                current_channel = [v for v in channels if v.get("name") == mode][0]
                uc = get_info("channel", stanza.from_jid)
                uc = uc if uc else "main"
                if uc == current_channel.get("name"):
                    body = u"你已经在 {0}  频道".format(mode)
                    return self._send_cmd_result(stanza, body)
                else:
                    del_channel_user(uc)
                if current_channel.get("passwd"):
                    pwd = args[1] if len(args) == 2 else None
                    if pwd == current_channel.get("passwd"):
                        add_info("channel", mode, stanza.from_jid)
                        add_channel_user(mode)
                        body = " 你已进入 {0} 频道".format(mode)
                    else:
                        body = " 频道密码错误"
                        if not pwd:
                            body = u"频道已加密,需要密码"
                else:
                    add_info("channel", mode, stanza.from_jid)
                    add_channel_user(mode)
                    body = " 你已进入 {0} 频道".format(mode)

        self._send_cmd_result(stanza, body)