Example #1
0
    def textsetsex(self, update: Update, plid: int) -> bool:
        if plid == 0:  # 私聊情形
            plid = getchatid(update)

        if getmsgfromid(update) != plid:
            return True

        self.popOP(getchatid(update))
        text = update.message.text

        cardi = self.findcard(plid)
        if not cardi:
            return self.errorInfo("找不到卡。")
        return self.cardsetsex(update, cardi, text)
Example #2
0
    def setsex(self, update: Update, context: CallbackContext) -> bool:
        """设置性别。比较明显的性别词汇会被自动分类为男性或女性,其他的性别也可以设置。
        `/setsex 性别`:直接设置。
        `/setsex`:使用交互式的方法设置性别。"""

        pl = self.forcegetplayer(update)
        if pl.controlling is None:
            return self.errorInfo("找不到卡。", True)
        if len(context.args) == 0:
            if isgroup(update):
                gpid = getchatid(update)
                self.addOP(gpid, "setsex " + str(pl.id))
                self.reply("请输入性别:")
                return True

            rtbuttons = [[
                InlineKeyboardButton("男性", callback_data="setsex male"),
                InlineKeyboardButton("女性", callback_data="setsex female"),
                InlineKeyboardButton("其他", callback_data="setsex other")
            ]]
            rp_markup = InlineKeyboardMarkup(rtbuttons)
            self.reply("请选择性别:", reply_markup=rp_markup)
            self.workingMethod[self.lastchat] = BUTTON_SETSEX
            return True

        card = pl.controlling
        self.cardsetsex(update, card, context.args[0])
        return True
Example #3
0
    def textHandler(self, update: Update,
                    context: CallbackContext) -> handleStatus:
        """信息处理函数,用于无指令的消息处理。
        具体指令处理正常完成时再删除掉当前操作状态`OPERATION[chatid]`,处理出错时不删除。"""

        if update.message is None:
            return handleBlocked(False)

        if isgroup(update):
            gp = self.forcegetgroup(update)
            if gp.game is not None and gp.game.memfile != "":
                self.textmem(update)

        if update.message.text in ["cancel", "取消"]:
            self.reply("操作取消")
            self.popOP(getchatid(update))
            return handleBlocked()

        oper = self.getOP(getchatid(update))
        opers = oper.split(" ")
        if oper == "":
            self.botchat(update)
            return handleBlocked()
        if opers[0] == "newcard":
            return handleBlocked(
                self.textnewcard(update, int(opers[2]))
                if len(opers) > 2 else self.textnewcard(update))
        if oper == "setage":
            return handleBlocked(self.textsetage(update))
        if oper == "setname":  # 私聊情形
            return handleBlocked(self.textsetname(update, 0))
        if opers[0] == "setname":  # 群消息情形
            return handleBlocked(self.textsetname(update, int(opers[1])))
        if oper == "setsex":  # 私聊情形
            return handleBlocked(self.textsetsex(update, 0))
        if opers[0] == "setsex":  # 群消息情形
            return handleBlocked(self.textsetsex(update, int(opers[1])))
        if opers[0] == "delcard":
            return handleBlocked(self.textdelcard(update, int(opers[1])))
        if opers[0] == "passjob":
            return handleBlocked(self.textpassjob(update))
        if opers[0] == "passskill":
            return handleBlocked(self.textpassskill(update))
        if oper == "startgame":
            return handleBlocked(self.textstartgame(update))
        return handleBlocked(False)
Example #4
0
    def textsetname(self, update: Update, plid: int) -> bool:
        if plid == 0:  # 私聊情形
            plid = getchatid(update)

        if getmsgfromid(update) != plid:
            return True  # 不处理

        self.popOP(getchatid(update))

        text = ' '.join(update.message.text.split())

        cardi = self.findcard(plid)
        if not cardi:
            return self.errorInfo("找不到卡。")

        self.nameset(cardi, text)
        self.reply("姓名设置完成:" + text)
        return True
Example #5
0
    def textsetage(self, update: Update) -> bool:
        text = update.message.text
        plid = getchatid(update)
        if not isint(text):
            return self.errorInfo("输入无效,请重新输入")
        cardi = self.findcard(plid)
        if not cardi:
            self.popOP(plid)
            return self.errorInfo("找不到卡")

        return (bool(self.popOP(plid)) or True) if self.cardsetage(
            update, cardi, int(text)) else False
Example #6
0
    def setname(self, update: Update, context: CallbackContext) -> bool:
        """设置角色卡姓名。

        `/setname --name`:直接设定姓名。
        `/setname`:bot将等待输入姓名。
        设置的姓名可以带有空格等字符。"""

        card1 = self.forcegetplayer(update).controlling
        if card1 is None:
            return self.errorInfo("找不到卡。")

        if len(context.args) == 0:
            if isprivate(update):
                self.addOP(getchatid(update), "setname")
            else:
                self.addOP(getchatid(update), "setname " + str(card1.playerid))
            self.reply("请输入姓名:")
            return True

        self.nameset(card1, ' '.join(context.args))
        self.reply("角色的名字已经设置为" + card1.info.name + "。")
        return True
    def deletemsg(self, update: Update, context: CallbackContext) -> bool:
        """用于删除消息,清空当前对话框中没有用的消息。
        bot可以删除任意私聊消息,无论是来自用户还是bot。
        如果是群内使用该指令,需要管理员或KP权限,
        以及bot是管理员,此时可以删除群内的任意消息。

        当因为各种操作产生了过多冗杂消息的时候,使用
        `/delmsg --msgnumber`将会删除:delmsg指令的消息
        以及该指令上面的msgnumber条消息。例如:
        `/delmsg 2`将删除包含delmsg指令在内的3条消息。
        没有参数的时候,`/delmsg`默认删除指令和指令的上一条消息。

        因为要进行连续的删除请求,删除的时间会稍微有些滞后,
        请不要重复发送该指令,否则可能造成有用的消息丢失。
        如果感觉删除没有完成,请先随意发送一条消息来拉取删除情况,
        而不是继续用`/delmsg`删除。"""

        delnum = 1
        chatid = getchatid(update)

        if isgroup(update) and not self.isadmin(self.lastchat, BOT_ID):
            return self.errorInfo("Bot没有管理权限")

        if isgroup(update) and self.checkaccess(self.forcegetplayer(update), self.forcegetgroup(update)) & (GROUPKP | GROUPADMIN) == 0:
            return self.errorInfo("没有权限", True)

        if len(context.args) >= 1:
            if not isint(context.args[0]) or int(context.args[0]) <= 0:
                return self.errorInfo("参数错误", True)
            delnum = int(context.args[0])
            if delnum > 10:
                return self.errorInfo("一次最多删除10条消息")

        lastmsgid = self.lastmsgid
        while delnum >= 0:  # 这是因为要连同delmsg指令的消息也要删掉
            if lastmsgid < -100:
                break
            try:
                context.bot.delete_message(
                    chat_id=chatid, message_id=lastmsgid)
            except Exception as e:
                if str(e).find("can't be deleted for everyone") != -1:
                    self.errorInfo("消息删除失败,发送时间较久的消息无法删除")
                    break
                lastmsgid -= 1
            else:
                delnum -= 1
                lastmsgid -= 1

        update.effective_chat.send_message("删除完成").delete()
        return True
Example #8
0
    def textHandler(self, update: Update, context: CallbackContext) -> bool:
        if update.message.migrate_to_chat_id is not None:
            self.chatmigrate(
                getchatid(update), update.message.migrate_to_chat_id)
            return True

        if Filters.status_update(update):
            return True

        self.renewStatus(update)
        if any(x in self.blacklist for x in (self.lastuser, self.lastchat)):
            return self.errorInfo("你在黑名单中,无法使用任何功能")

        for cls in self.__class__.__bases__:
            status: handleStatus = cls.textHandler(self, update, context)
            if status.blocked():
                return status.normal

        return False
Example #9
0
    def setage(self, update: Update, context: CallbackContext):
        if isgroup(update):
            return self.errorInfo("发送私聊消息设置年龄。", True)

        pl = self.forcegetplayer(update)
        card = pl.controlling
        if card is None:
            return self.errorInfo("找不到卡。")

        if card.info.age >= 17 and card.info.age <= 99:
            return self.errorInfo("已经设置过年龄了。")

        if len(context.args) == 0:
            self.reply("请输入年龄:")
            self.addOP(getchatid(update), "setage")
            return True

        age = context.args[0]
        if not isint(age):
            return self.errorInfo("输入无效")

        age = int(age)
        return self.cardsetage(update, card, age)