Exemple #1
0
 def _switch_channel(self, email, channel):
     """ 切换频道 """
     oldch = get_info("channel", email)
     self._logger.info("{0} switch channel from {1} to {2}".format(email, oldch, channel))
     del_channel_user(oldch)
     add_info("channel", channel, email)
     add_channel_user(channel)
Exemple #2
0
    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)