Ejemplo n.º 1
0
    def process(self, from_group: int, from_qq: int, command_list: List[str]):
        # %game register lightless233

        # 初始化数据
        self.from_qq = from_qq
        self.from_group = from_group

        # 1 检查该QQ是否已经有角色了
        has_pc = False
        with db:
            try:
                PlayerInfoModel.get(PlayerInfoModel.qq == from_qq)
                has_pc = True
            except DoesNotExist:
                pass
        if has_pc:
            self.send_msg(utils.build_at_msg(from_qq) + "\n已经有角色啦!暂不支持多个角色!")
            return

        # 2 创建角色
        try:
            nickname = command_list[2]
        except IndexError:
            self.send_msg(utils.build_at_msg(from_qq) + f"\n格式:{self.err_msg}")
            return

        with db:
            player = PlayerInfoModel()
            player.qq = from_qq
            player.nickname = nickname
            player.save()

        self.send_msg(utils.build_at_msg(from_qq) + "\n注册成功!")
Ejemplo n.º 2
0
    def process(self, from_group: int, from_qq: int, command_list: List[str]):

        if not self._check_admin(from_group, from_qq):
            return

        try:
            target_qq = command_list[1]
        except IndexError:
            self.api.send_group_msg(
                from_group,
                utils.build_at_msg(from_qq) + "\nError arguments.\n%unban qq")
            return

        at_qq = utils.get_qq_from_at_msg(target_qq)
        if at_qq is None:
            self.api.set_group_ban(group_id=from_group,
                                   user_id=int(target_qq),
                                   duration=0)
        else:
            self.api.set_group_ban(group_id=from_group,
                                   user_id=int(at_qq),
                                   duration=0)
        self.api.send_group_msg(
            from_group,
            utils.build_at_msg(from_qq) + "\nUnban operation success!")
Ejemplo n.º 3
0
 def _check_admin(self, from_group, from_qq) -> bool:
     if from_qq not in constant.ADMIN_QQ:
         at_msg = utils.build_at_msg(from_qq)
         self.api.send_group_msg(from_group, at_msg + "\n您还不是管理员呢!")
         self.api.set_group_ban(from_group, from_qq, 60)
         return False
     else:
         return True
Ejemplo n.º 4
0
    def process(self, msg: str, from_qq: int, from_group: int) -> bool:

        global last_message, repeat_count

        if msg == last_message:
            # 是复读的消息,累加计数
            repeat_count += 1
        else:
            # 不是复读的消息,更新计数
            last_message = msg
            repeat_count = 1

        self.logger.info(f"last_message: {last_message} -> {repeat_count}")

        # 根据复读次数,进行概率ban
        # 1次、2次 不禁言
        # 10次以上 100%禁言
        if repeat_count in (1, 2):
            return True

        if repeat_count >= 10:
            self.api.set_group_ban(from_group, from_qq, 10)

            m = utils.build_at_msg(from_qq) + "\n您怕不是个复读机吧?\n劝你次根香蕉冷静冷静"
            self.api.send_group_msg(from_group, m)
            return False

        # r = 1- (n-1)/n
        # n = 3 => r = 1/3
        # n = 4 => r = 1/4
        # n = 5 => r = 1/5
        # n = 6 => r = 1/6
        # ...
        # n = 9 => r = 1/9
        # 1 / (12 - n)
        prob = 1.0 / (11 - repeat_count)
        point = random.random()
        self.logger.info(f"prob: {prob}, point: {point}")
        if point < prob:
            m = utils.build_at_msg(from_qq) + "\n老哥被我抓住了吧?"
            self.api.send_group_msg(from_group, m)
            self.api.set_group_ban(from_group, from_qq,
                                   repeat_count * repeat_count / 2 * 60)
            return False

        return True
Ejemplo n.º 5
0
    def ubban(self, from_group, from_qq, command_list):
        if not self.__check_admin(from_qq):
            self.api.send_group_msg(from_group, "You are not admin!\n" + utils.build_at_msg(from_qq))
            self.api.set_group_ban(from_group, from_qq, 60)
            return

        try:
            target_qq = command_list[1]
        except IndexError:
            self.api.send_group_msg(from_group,
                                    utils.build_at_msg(from_qq) + "\nError arguments.\n%unban qq")
            return

        at_qq = utils.get_qq_from_at_msg(target_qq)
        if at_qq is None:
            self.api.set_group_ban(group_id=from_group, user_id=int(target_qq), duration=0)
        else:
            self.api.set_group_ban(group_id=from_group, user_id=int(at_qq), duration=0)
        self.api.send_group_msg(from_group, utils.build_at_msg(from_qq) + "\nUnban operation success!")
Ejemplo n.º 6
0
    def on_group_msg(self, params):
        """
        sub_type	int32
        msg_id	int32
        from_group	int64
        from_qq	int64
        msg	str
        font	int32
        is_anonymous	bool
        anonymous	dict
        """
        self.logging.info(f"{self.TAG} On receive group message")

        # 获取必要信息
        from_group = params.get("from_group")
        msg: str = params.get("msg")
        from_qq = params.get("from_qq")

        # 非目标Q群来的消息 直接返回
        if str(from_group) not in constant.TARGET_GROUP:
            return

        self.info("receive message: " + msg + ", from: " + str(from_qq))

        # pipeline start #
        should_process_command = True
        for _pipeline in self.pipelines:
            if not _pipeline.process(msg, from_qq, from_group):
                should_process_command = False
                break
        # pipeline end #

        # command start#
        if should_process_command:
            # 如果是 % 开头的消息,认为是命令消息,否则就是普通的消息,走正常的pipeline进行处理
            if msg.startswith("%"):
                command_list = re.split(r"\s+", msg)
                input_command_name = command_list[0]
                command_instance: Optional[BaseCommand] = self.commands.get(
                    input_command_name, None)
                if command_instance is None:
                    self.commands.get("%help").process(
                        from_group, from_qq, command_list=command_list)
                else:
                    try:
                        command_instance.process(from_group, from_qq,
                                                 command_list)
                    except Exception as e:
                        tbe = traceback.TracebackException(*sys.exc_info())
                        full_err = ''.join(tbe.format())
                        self.api.send_group_msg(
                            from_group,
                            utils.build_at_msg(from_qq) +
                            "\nUnknown Error! e: " + str(e) + "\n" + full_err)
Ejemplo n.º 7
0
    def process(self, msg: str, from_qq: int, from_group: int) -> bool:
        clean_msg = msg.replace(" ", "")
        for thumb in self.THUMBS_ID:
            if thumb in clean_msg:
                self.api.set_group_ban(group_id=from_group,
                                       user_id=from_qq,
                                       duration=120)
                self.api.send_group_msg(group_id=from_group,
                                        msg="发现大拇指!QNMD!\n" +
                                        utils.build_at_msg(from_qq))
                return False

        return True
Ejemplo n.º 8
0
    def handler(self, msg: str, from_group: int, from_qq: int):

        command_list = msg.split(" ")
        command = command_list[0]

        if command == "%helpxxxx":
            self.help(from_group, from_qq)
        elif command == "%ban":
            self.ban(from_group, from_qq, command_list)
        elif command == "%unban":
            self.ubban(from_group, from_qq, command_list)
        elif command == "%attack":
            self.attack(from_group, from_qq, command_list)
        else:
            self.api.send_group_msg(group_id=from_group, msg=utils.build_at_msg(from_qq) + "\nUnknown Command!")
Ejemplo n.º 9
0
    def process(self, from_group: int, from_qq: int, command_list: List[str]):
        """
        点数分配
        :param from_group:
        :param from_qq:
        :param command_list:
        """

        # 初始化数据
        self.from_qq = from_qq
        self.from_group = from_group

        # 获取参数
        try:
            prop = command_list[2]
            pt = int(command_list[3])
        except (IndexError, ValueError):
            self.send_err_msg()
            return

        if prop.upper() not in self.available_prop:
            self.send_err_msg()
            return

        # 获取这个玩家的所有剩余PT
        pc: PlayerInfoModel = self.player_info_service.get_player_info_by_qq(
            from_qq)
        if pc is None:
            self.send_err_msg("无此玩家")
            return
        player_rest_pt = pc.rest_pt
        if pt < 0 or pt > player_rest_pt:
            self.send_err_msg("PT点数不足")
            return
        """
        更新PT,要一起更新其他数值
        """
        if self.player_info_service.update_player_prop(prop, from_qq,
                                                       pt) is None:
            self.send_err_msg()
            return
        else:
            self.send_msg(utils.build_at_msg(from_qq) + "\n点数分配成功!")
Ejemplo n.º 10
0
    def process(self, from_group: int, from_qq: int, command_list: List[str]):

        try:
            target_qq = command_list[1]
            duration = command_list[2]
        except IndexError:
            self.api.send_group_msg(
                from_group,
                utils.build_at_msg(from_qq) + "\nError arguments.\n%attack qq duration(min.)"
            )
            return

        at_qq = utils.get_qq_from_at_msg(target_qq)
        if at_qq is None:
            self.api.send_group_msg(
                from_group,
                utils.build_at_msg(from_qq) + "\nError arguments.\n%attack qq duration(min.)"
            )
            return
        real_target = at_qq

        try:
            real_target = int(real_target)
            duration = int(duration)
        except:
            self.logger.info("[XYZ] err argument.")
            self.api.send_group_msg(
                from_group,
                utils.build_at_msg(from_qq) + "\nError arguments.\n%attack qq duration(min.)"
            )
            return

        at_attacker_qq_msg = utils.build_at_msg(from_qq)
        at_target_qq_msg = utils.build_at_msg(real_target)
        is_stake = False

        # 校验参数
        if duration < 0:
            self.api.send_group_msg(from_group, at_attacker_qq_msg + "\n你再乱搞试试?")
            self.api.set_group_ban(from_group, from_qq, 60)
            return
        if duration == 0:
            self.api.send_group_msg(from_group, at_attacker_qq_msg + "\n彩蛋已经修复咯!")
            self.api.set_group_ban(from_group, from_qq, 60 * 60)
            return

        # 如果这个傻子要打自己
        if int(real_target) == from_qq:
            self.api.set_group_ban(from_group, from_qq, duration * 60)
            self.api.send_group_msg(from_group, at_attacker_qq_msg + "\n小老弟你是个傻子?")
            return

        # 如果打群主
        # 群主作为木桩人使用
        if int(real_target) == 2522031536:
            # self.api.set_group_ban(from_group, from_qq, duration * 60 * 2)
            # self.api.send_group_msg(from_group, at_attacker_qq_msg + "\n二营长,你他娘的意大利炮呢?给老子拉上来!开炮!开炮!开炮!")
            is_stake = True

        # 正常攻击,先开始roll点
        attacker_pt = random.randint(0, 100)
        target_pt = random.randint(0, 100)

        base_msg = at_attacker_qq_msg + f"的点数:{attacker_pt}\n"
        base_msg += at_target_qq_msg + f"的点数:{target_pt}\n"

        # 如果俩人点数相等,统统干掉,但是时间减半
        # 如果攻击者和目标都是100点,统统禁言,并且翻倍时间
        if attacker_pt == target_pt and attacker_pt != 100:
            base_msg += "旗鼓相当的对手,两败俱伤!"
            self.api.send_group_msg(from_group, base_msg)

            # self.api.set_group_ban(from_group, from_qq, duration * 60 / 2)
            # self.api.set_group_ban(from_group, real_target, duration * 60 / 2)
            self.ban(is_stake, from_group, from_qq, duration * 60 / 2)
            self.ban(is_stake, from_group, real_target, duration * 60 / 2)
            return
        if attacker_pt == target_pt and attacker_pt == 100:
            base_msg += "你俩怎么一起开大招?"
            self.api.send_group_msg(from_group, base_msg)
            # self.api.set_group_ban(from_group, from_qq, duration * 60 * 2)
            # self.api.set_group_ban(from_group, real_target, duration * 60 * 2)
            self.ban(is_stake, from_group, from_qq, duration * 60 * 2)
            self.ban(is_stake, from_group, real_target, duration * 60 * 2)
            return

        # 如果攻击者roll到100点,无视防御
        if attacker_pt == 100 and target_pt != 100:
            base_msg += at_attacker_qq_msg + "居然开大了!无视防御!双倍伤害!"
            self.api.send_group_msg(from_group, base_msg)
            # self.api.set_group_ban(from_group, real_target, duration * 60 * 2)
            self.ban(is_stake, from_group, real_target, duration * 60 * 2)
            return

        # 如果目标roll到了100点,无视攻击
        if target_pt == 100 and attacker_pt != 100:
            base_msg += at_attacker_qq_msg + "发动了:绝 对 防 御,并且反击成功!"
            self.api.send_group_msg(from_group, base_msg)
            # self.api.set_group_ban(from_group, from_qq, duration * 60 / 2)
            self.ban(is_stake, from_group, from_qq, duration * 60 / 2)
            return

        # todo: 处理一下roll到0点的情况
        final_attacker_pt = math.floor(attacker_pt - (duration/60)*50*((random.randint(0, 10)+5)/20))

        base_msg = at_attacker_qq_msg + f"的点数:{attacker_pt},叠加debuff后的点数:{final_attacker_pt}\n"
        base_msg += at_target_qq_msg + f"的点数:{target_pt}\n"
        can_counter = False
        if final_attacker_pt > target_pt:
            # 攻击成功
            base_msg += at_attacker_qq_msg + "的攻击得手了!"
            # self.api.set_group_ban(from_group, real_target, duration * 60)
            self.ban(is_stake, from_group, real_target, duration * 60)
            self.api.send_group_msg(from_group, base_msg)
        elif final_attacker_pt < target_pt:
            # 攻击失败
            base_msg += at_attacker_qq_msg + "手滑了,啥也没打到。"
            self.api.send_group_msg(from_group, base_msg)
            can_counter = True
        else:
            # 相等了
            base_msg += "旗鼓相当的对手,两败俱伤,伤害均摊。"
            self.api.send_group_msg(from_group, base_msg)
            # self.api.set_group_ban(from_group, real_target, duration / 2 * 60)
            # self.api.set_group_ban(from_group, from_qq, duration / 2 * 60)
            self.ban(is_stake, from_group, real_target, duration / 2 * 60)
            self.ban(is_stake, from_group, from_qq, duration / 2 * 60)

        # 开始反击判定
        if not can_counter:
            return
        # 临时patch,在大时长下增强见切概率
        if duration >= 10 and duration <= 20:
            counter_attack_pt = math.floor(random.randint(0, 100) * 1.0)
        elif duration >= 20:
            counter_attack_pt = math.floor(random.randint(0, 100) * 1.2)
        else:
            counter_attack_pt = math.floor(random.randint(0, 100) * 1.0)
        self.logger.info(f"[XYZ] counter_attack_pt: {counter_attack_pt}")
        if counter_attack_pt > final_attacker_pt:
            # 反击成功
            self.api.send_group_msg(from_group, at_target_qq_msg + f"见切成功!斩于马下!反击值:{counter_attack_pt}")
            # self.api.set_group_ban(from_group, from_qq, duration * 60 * 0.2)
            self.ban(is_stake, from_group, from_qq, duration * 60 * 0.55)
        else:
            # 反击失败
            self.api.send_group_msg(from_group, at_target_qq_msg + f"反击失败了,真可惜。反击值:{counter_attack_pt}")
Ejemplo n.º 11
0
    def attack(self, from_group, from_qq, command_list):
        try:
            target_qq = command_list[1]
            duration = command_list[2]
        except IndexError:
            self.api.send_group_msg(from_group,
                                    utils.build_at_msg(from_qq) + "\nError arguments.\n%attack qq duration(min.)")
            return

        at_qq = utils.get_qq_from_at_msg(target_qq)
        if at_qq is not None:
            real_target = at_qq
        else:
            real_target = target_qq

        try:
            real_target = int(real_target)
            duration = int(duration)
        except:
            self.logger.info("[XYZ] err argument.")
            self.api.send_group_msg(from_group,
                                    utils.build_at_msg(from_qq) + "\nError arguments.\n%attack qq duration(min.)")
            return

        at_attacker_qq_msg = utils.build_at_msg(from_qq)
        at_target_qq_msg = utils.build_at_msg(real_target)
        # 校验参数
        if duration < 0:
            self.api.send_group_msg(from_group, at_attacker_qq_msg + "\n你再乱搞试试?")
            self.api.set_group_ban(from_group, from_qq, 60)
            return

        # 如果这个傻子要打自己
        if int(real_target) == from_qq:
            self.api.set_group_ban(from_group, from_qq, duration * 60)
            self.api.send_group_msg(from_group, at_attacker_qq_msg + "\n小老弟你是个傻子?")
            return

        # 如果打群主
        if int(real_target) == 2522031536:
            self.api.set_group_ban(from_group, from_qq, duration * 60 * 2)
            self.api.send_group_msg(from_group, at_attacker_qq_msg + "\n二营长,你他娘的意大利炮呢?给老子拉上来!开炮!开炮!开炮!")
            return

        # 正常攻击,先开始roll点
        attacker_pt = random.randint(0, 100)
        target_pt = random.randint(0, 100)

        base_msg = at_attacker_qq_msg + f"的点数:{attacker_pt}\n"
        base_msg += at_target_qq_msg + f"的点数:{target_pt}\n"

        # 如果俩人点数相等,统统干掉,但是时间减半
        # 如果攻击者和目标都是100点,统统禁言,并且翻倍时间
        if attacker_pt == target_pt and attacker_pt != 100:
            base_msg += "旗鼓相当的对手,两败俱伤!"
            self.api.send_group_msg(from_group, base_msg)
            self.api.set_group_ban(from_group, from_qq, duration * 60 / 2)
            self.api.set_group_ban(from_group, real_target, duration * 60 / 2)
            return
        if attacker_pt == target_pt and attacker_pt == 100:
            base_msg += "你俩怎么一起开大招?"
            self.api.send_group_msg(from_group, base_msg)
            self.api.set_group_ban(from_group, from_qq, duration * 60 * 2)
            self.api.set_group_ban(from_group, real_target, duration * 60 * 2)
            return

        # 如果攻击者roll到100点,无视防御
        if attacker_pt == 100 and target_pt != 100:
            base_msg += at_attacker_qq_msg + "居然开大了!无视防御!双倍伤害!"
            self.api.send_group_msg(from_group, base_msg)
            self.api.set_group_ban(from_group, real_target, duration * 60 * 2)
            return

        # 如果目标roll到了100点,无视攻击
        if target_pt == 100 and attacker_pt != 100:
            base_msg += at_attacker_qq_msg + "发动了:绝 对 防 御,并且反击成功!"
            self.api.send_group_msg(from_group, base_msg)
            self.api.set_group_ban(from_group, from_qq, duration * 60 / 2)
            return

        # todo: 处理一下roll到0点的情况

        # 正常情况了,开始计算攻击者的debuff
        # 重新生成base_msg
        # if duration >= 30:
        #     final_attacker_pt = math.floor(attacker_pt - (duration * 0.75 + 20))
        # elif duration < 10:
        #     final_attacker_pt = math.floor(attacker_pt - (duration / 2))
        # else:
        #     final_attacker_pt = math.floor(attacker_pt - (duration * 1.875 - 13.75))
        final_attacker_pt = math.floor(attacker_pt - (duration / 2))

        base_msg = at_attacker_qq_msg + f"的点数:{attacker_pt},叠加debuff后的点数:{final_attacker_pt}\n"
        base_msg += at_target_qq_msg + f"的点数:{target_pt}\n"
        can_counter = False
        if final_attacker_pt > target_pt:
            # 攻击成功
            base_msg += at_attacker_qq_msg + "的攻击得手了!"
            self.api.set_group_ban(from_group, real_target, duration * 60)
            self.api.send_group_msg(from_group, base_msg)
            attack_success = False
        elif final_attacker_pt < target_pt:
            # 攻击失败
            base_msg += at_attacker_qq_msg + "手滑了,啥也没打到。"
            self.api.send_group_msg(from_group, base_msg)
            can_counter = True
        else:
            # 相等了
            base_msg += "旗鼓相当的对手,两败俱伤,伤害均摊。"
            self.api.send_group_msg(from_group, base_msg)
            self.api.set_group_ban(from_group, real_target, duration / 2  * 60)
            self.api.set_group_ban(from_group, from_qq, duration / 2  * 60)
            can_counter = False

        # 开始反击判定
        if not can_counter:
            return
        counter_attack_pt = math.floor(random.randint(0, 100) * 0.9)
        self.logger.info(f"[XYZ] counter_attack_pt: {counter_attack_pt}")
        if counter_attack_pt > final_attacker_pt:
            # 反击成功
            self.api.send_group_msg(from_group, at_target_qq_msg + f"见切成功!斩于马下!反击值:{counter_attack_pt}")
            self.api.set_group_ban(from_group, from_qq, duration * 60 * 0.2)
        else:
            # 反击失败
            self.api.send_group_msg(from_group, at_target_qq_msg + f"反击失败了,真可惜。反击值:{counter_attack_pt}")
Ejemplo n.º 12
0
 def send_err_msg(self, msg=None):
     if msg is None:
         self.send_msg(
             utils.build_at_msg(self.from_qq) + f"\n格式错误!{self.err_msg}")
     else:
         self.send_msg(utils.build_at_msg(self.from_qq) + f"\n{msg}")
Ejemplo n.º 13
0
    def process(self, from_group: int, from_qq: int, command_list: List[str]):

        # 初始化数据
        self.from_qq = from_qq
        self.from_group = from_group
        target_pc = None
        target_type = None
        show_self = False

        try:
            target_pc = command_list[2]
            # 没异常,说明要查看其他人的数据
            result = utils.get_qq_from_at_msg(target_pc)
            if result == None:
                target_type = "NICKNAME"
            else:
                target_type = "QQ"
                target_pc = result

        except IndexError:
            # 没有指定参数,查看自己的数据
            target_pc = from_qq
            target_type = "QQ"
            show_self = True

        # 打一下log
        self.logger.info(
            f"[{self.command_name}] target_pc:{target_pc}, target_type: {target_type}"
        )

        # 开始查询数据
        with db:
            try:
                if target_type == "QQ":
                    pc_result: PlayerInfoModel = PlayerInfoModel.get(
                        PlayerInfoModel.qq == target_pc)
                else:
                    pc_result: PlayerInfoModel = PlayerInfoModel.get(
                        PlayerInfoModel.nickname == target_pc)
            except DoesNotExist:
                # 查无此人
                self.send_msg(
                    utils.build_at_msg(from_qq) + "\n无此人数据!"
                    "\n请确认目标是否正确,或请先执行%game register nickname进行注册!")
                return

        # 格式化数据
        data_msg = "Nickname: " + pc_result.nickname + "\n"
        if show_self:
            data_msg += f"Rest PT: {pc_result.rest_pt}\n"
        data_msg += f"Level: {pc_result.level}\n" \
                    f"Exp: {pc_result.exp}\n" \
                    f"==========\n" \
                    f"STR: {pc_result.base_str}\n" \
                    f"VIT: {pc_result.base_vit}\n" \
                    f"AGI: {pc_result.base_agi}\n" \
                    f"LUK: {pc_result.base_luck}\n" \
                    f"==========\n" \
                    f"HP: {pc_result.hp_current} / {pc_result.hp_max}\n" \
                    f"SP: {pc_result.sp_current} / {pc_result.sp_max}\n" \
                    f"ATK: {pc_result.atk}\n" \
                    f"DEF: {pc_result.defe}\n" \
                    f"CRI: {self.convert(pc_result.cri * 100, 2)}%\n" \
                    f"HIT: {self.convert(pc_result.hit * 100, 2)}%\n" \
                    f"EVA: {self.convert(pc_result.eva * 100, 2)}%\n" \
                    f"=========="
        self.send_msg(utils.build_at_msg(from_qq) + "\n" + data_msg)