예제 #1
0
def addReserve(event: ReceiveEvent[MsgEvent], step: str):
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        notdigitMsg = "请输入 1-6 之间的阿拉伯数字\nP.S.: 6 代表 5 王狂暴"
        if not step.isdigit():
            pcrPlugin.api.reply(event, TextMsg(notdigitMsg))
            return
        pcr = _getPCRObj(event)
        try:
            pcr.getMappingInfo(member=event.payload.msgInfo.UserId)
        except NotFoundPlayerMapping:
            pcrPlugin.api.reply(event, TextMsg("尚未绑定账户,暂时无法使用此功能"))
            return
        try:
            status, row = pcr.addReserve(event.payload.msgInfo.UserId,
                                         int(step))
        except ValueError:
            pcrPlugin.api.reply(event, TextMsg(notdigitMsg))
            return
        if status:
            pcrPlugin.api.reply(
                event,
                TextMsg("已预约{}周目{}".format(row.stage,
                                           _ReserveBossID2Name(row.step,
                                                               pcr))))
        else:
            pcrPlugin.api.reply(
                event,
                TextMsg("你已经预约了{}周目{}".format(
                    row.stage, _ReserveBossID2Name(row.step, pcr))))
예제 #2
0
def urge(event: ReceiveEvent[MsgEvent]):
    """催刀"""
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        pcr = _getPCRObj(event)
        u = _queryK(pcr, False)
        if u != None:
            pcrPlugin.api.reply(event, [TextMsg("当前还剩下{}刀".format(u[0][0]))])
            if (u[0][0] == 0):
                pcrPlugin.api.reply(event, [TextMsg("恭喜出刀完成!")])
            for left, lis in u.items():
                if len(lis) == 0:
                    continue
                if left == 0:
                    continue
                notBind = []
                atlist = []
                for playerID in lis:
                    mapping = pcr.getMappingInfo(playerID=playerID)
                    if mapping.mamber == None:
                        notBind.append(mapping.playerName)
                    else:
                        atlist.append(mapping.mamber)
                pcrPlugin.api.reply(event, TextMsg("剩余{}刀".format(left)))
                if len(notBind) != 0:
                    pcrPlugin.api.reply(
                        event, TextMsg("未绑定的玩家:{}".format('、'.join(notBind))))
                if len(atlist) != 0:
                    pcrPlugin.api.reply(event, AtMsg(atlist))
예제 #3
0
def queryDamage(event: ReceiveEvent[MsgEvent]):
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        user, isAtUser = _getAtList(event, event.payload.msgInfo.UserId)
        if isAtUser:
            if not pcrPlugin.api.isGroupAdmin(event.source,
                                              event.payload.msgInfo.GroupId,
                                              event.payload.msgInfo.UserId):
                pcrPlugin.api.reply(event, TextMsg("需要是管理员才可以查询其他人的出刀记录哦"))
                return
        if len(user) != 1:
            pcrPlugin.api.reply(event, TextMsg("只能@一个人哦,而你@了%s个" % len(user)))
            return
        pcr = _getPCRObj(event)
        try:
            mapping = pcr.getMappingInfo(member=user[0])
        except NotFoundPlayerMapping:
            pcrPlugin.api.reply(
                event,
                TextMsg("{}还没有绑定游戏账户哦".format("你" if user[0] == event.payload.
                                              msgInfo.UserId else "该玩家")))
            return
        playerid = mapping['playerID']
        logs = pcr.queryDamageASMember(playerid)
        try:
            logMsg = ["今日已出{}刀(完整刀{}刀)".format(*pcr.getK(logs)[playerid])]
        except KeyError:
            pcrPlugin.api.reply(
                event, TextMsg("玩家:{} 今日还没有出刀记录哦".format(mapping.playerName)))
            return
        logMsg.extend([
            log.logText(name=mapping['playerName'],
                        bossname=pcr.bossList[log.step - 1]['boss_name'])
            for log in logs[playerid]
        ])
        pcrPlugin.api.reply(event, TextMsg('\n'.join(logMsg)))
예제 #4
0
def queryReserve(event: ReceiveEvent[MsgEvent]):
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        pcr = _getPCRObj(event)
        user, isAtUser = _getAtList(event, event.payload.msgInfo.UserId)
        if isAtUser:
            if not pcrPlugin.api.isGroupAdmin(event.source,
                                              event.payload.msgInfo.GroupId,
                                              event.payload.msgInfo.UserId):
                pcrPlugin.api.reply(event, TextMsg("需要是管理员才可以查询其他人的出刀记录哦"))
                return
        if len(user) != 1:
            pcrPlugin.api.reply(event, TextMsg("只能@一个人哦,而你@了%s个" % len(user)))
            return
        else:
            user = user[0]
        reserveList: List[str] = []
        for row in pcr.queryAllReserve(member=int(user)):
            reserveList.append(" - {}周目{}".format(
                row.stage, _ReserveBossID2Name(row.step, pcr)))

        if len(reserveList) != 0:
            pcrPlugin.api.reply(
                event, TextMsg("预约列表\n{}".format("\n".join(reserveList))))
        else:
            pcrPlugin.api.reply(event, TextMsg("无预约"))
예제 #5
0
def delBindPlayer(event: ReceiveEvent[MsgEvent], playerID: int):
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        user, isAtUser = _getAtList(event, event.payload.msgInfo.UserId)
        if isAtUser:
            if not pcrPlugin.api.isGroupAdmin(event.source,
                                              event.payload.msgInfo.GroupId,
                                              event.payload.msgInfo.UserId):
                pcrPlugin.api.reply(event, TextMsg("需要是管理员才可以解除其他人的绑定哦"))
                return
        if len(user) != 1:
            pcrPlugin.api.reply(event, TextMsg("只能@一个人哦,而你@了%s个" % len(user)))
            return
        pcr = _getPCRObj(event)
        status, name = pcr.delBind(
            user[0],
            playerID,
            force=pcrPlugin.api.eventUserIsGroupAdmin(event) and isAtUser)
        if status == "ok":
            pcrPlugin.api.reply(event,
                                TextMsg('成功与游戏名为:{} 的账户解绑'.format(name)))
        elif status == "Not Bind You":
            pcrPlugin.api.reply(event,
                                TextMsg('游戏名为:{} 的账户绑定的不是你'.format(name)))
        else:
            pcrPlugin.api.reply(event, TextMsg('在公会内找不到此用户'))
예제 #6
0
def _getPCRObj(event: ReceiveEvent[MsgEvent]) -> PCR:
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        try:
            return pcrPlugin.context['Groups'][int(
                event.source.name)][event.payload.msgInfo.GroupId]
        except KeyError as e:
            pcrPlugin.api.reply(event, TextMsg("本群还未注册,不支持此功能"))
            raise e
    else:
        pcrPlugin.api.reply(event, TextMsg("此功能只支持群聊哦"))
        raise KeyError
예제 #7
0
def syncNow(event: ReceiveEvent[MsgEvent]):
    '''立即更新,需要群管理员'''
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        pcr = _getPCRObj(event)
        if pcrPlugin.api.isGroupAdmin(event.source,
                                      event.payload.msgInfo.GroupId,
                                      event.payload.msgInfo.UserId):
            autoReport(event.source.name, event.payload.msgInfo.GroupId, pcr)
            pcrPlugin.api.reply(event, TextMsg("已完成同步"))
        else:
            pcrPlugin.api.reply(event, TextMsg("需要是群管理员才可以调用此功能哦"))
예제 #8
0
def bindPlayer(event: ReceiveEvent[MsgEvent], playerID: int):
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        pcr = _getPCRObj(event)
        status, name = pcr.bind(event.payload.msgInfo.UserId, playerID)
        if status == "ok":
            pcrPlugin.api.reply(event,
                                TextMsg('成功与游戏名为:{} 的账户绑定'.format(name)))
        elif status == "Binded":
            pcrPlugin.api.reply(event, TextMsg('游戏名为:{} 的账户已被绑定'.format(name)))
        else:
            pcrPlugin.api.reply(event, TextMsg('在公会内找不到此用户'))
예제 #9
0
def left(event: ReceiveEvent[MsgEvent]):
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        pcr = _getPCRObj(event)
        u = _queryK(pcr, True)
        if u != None:
            pcrPlugin.api.reply(event, [TextMsg("当前还剩下{}刀".format(u[0][0]))])
            if (u[0][0] == 0):
                pcrPlugin.api.reply(event, [TextMsg("恭喜出刀完成!")])
            for left, lis in u.items():
                if len(lis) == 0:
                    continue
                if left == 0:
                    continue
                pcrPlugin.api.reply(event, TextMsg("剩余{}刀".format(left)))
                pcrPlugin.api.reply(event, TextMsg('、'.join(lis)))
예제 #10
0
 def setUp(self):
     self.callreturn = ""
     self.subComA = Command(command="a",
                            doc="DOC A",
                            msgtypes=GroupMsgInfo,
                            func=self.funcA)
     self.subComBA = Command(command="ba",
                             doc="DOC ba",
                             msgtypes=GroupMsgInfo,
                             func=self.funcB)
     self.subComB = Command(command="b",
                            doc="DOC B",
                            msgtypes=GroupMsgInfo,
                            sub=self.subComBA)
     self.subComC = Command(command="c",
                            doc="DOC C",
                            msgtypes=PrivateMsgInfo,
                            sub=self.subComBA)
     self.root = Command(command="root",
                         doc="DOC ROOT",
                         msgtypes=None,
                         sub=[self.subComA, self.subComB, self.subComC])
     self.receiveEvent = ReceiveEvent(
         Eventer("test", ServiceType.Core),
         MsgEvent(msgInfo=GroupMsgInfo(1), msgContent=TextMsg("test")))
예제 #11
0
def autoReport(botuid, gid, pcr: PCR):
    '''自动从 Bigfun 拉取出刀数据'''
    pcr.syncMappingInfo()  # 同步公会名称数据
    isNewData = False
    lastBossInfo = pcr.currentBossInfo()
    for newlog in pcr.autoReport():  # 同步出刀数据并返回新记录
        isNewData = True
        playerMapping = pcr.getMappingInfo(name=newlog.name)
        msg: List[MsgContent] = []
        member: Optional[str] = playerMapping.mamber
        if member != None:
            msg.append(AtMsg(int(member)))
        else:
            msg.append(TextMsg('*此玩家还未绑定*'))
        msg.append(
            TextMsg("\n" + DamageLogReturn.bfAPIDamage2Self(
                newlog,
                period=pcr.battleID,
                group=pcr.gid,
                playerid=playerMapping.playerID).logText(
                    name=playerMapping.playerName,
                    bossname=pcr.bossList[newlog._step - 1].name)))

        pcrPlugin.api.sendMsg(Eventer(botuid, ServiceType.Bridge),
                              MsgEvent(GroupMsgInfo(gid), msg))
    if isNewData:
        newBossInfo = pcr.currentBossInfo()
        pcrPlugin.api.sendMsg(
            Eventer(botuid, ServiceType.Bridge),
            MsgEvent(GroupMsgInfo(gid), TextMsg(str(newBossInfo))))
        step = newBossInfo.step
        if lastBossInfo.step != newBossInfo.step:
            query = pcr.queryReserve(newBossInfo.stage, newBossInfo.step)
        elif newBossInfo.step == 5 and newBossInfo.hp >= 10000000 and lastBossInfo.hp < 10000000:
            step = 6
            query = pcr.queryReserve(newBossInfo.stage, step)
        else:
            return
        nofiyId = []
        for row in query:
            nofiyId.append(row.member)
        pcrPlugin.api.sendMsg(
            Eventer(botuid, ServiceType.Bridge),
            MsgEvent(GroupMsgInfo(gid), [
                TextMsg('你预约的{}到了'.format(_ReserveBossID2Name(step, pcr))),
                AtMsg(nofiyId)
            ]))
예제 #12
0
def checklogin(data: List[Any]):
    event: ReceiveEvent[MsgEvent] = data[1]
    lastStatus: BigFunAPILoginStatus = data[2]
    if data[3] >= 60:
        pcrPlugin.api.reply(event, TextMsg("由于登录超时,系统已取消当前登录操作"))
    pcr: PCR = data[0]
    data[3] += 1
    status = pcr.checkLogin()
    if lastStatus != status:
        if status == BigFunAPILoginStatus.SCANED:
            msg = "已扫码,等待确认"
            pcrPlugin.api.reply(data[1], TextMsg(msg))
        elif status == BigFunAPILoginStatus.SUCCCESS:
            info = pcr.userInfo()
            msg = "登陆成功!\n当前用户:{}\n所在公会:{}\n即将开始同步战斗数据".format(
                info.playerName, info.clanName)
            pcrPlugin.api.reply(data[1], TextMsg(msg))
            addPCR(event.source.name, pcr.gid, pcr)
            pcr.syncMappingInfo()
            log = pcr.autoReport()
            msg = "公会:{}同步完成,已同步{}条数据\n{}".format(info.clanName, len(log),
                                                  str(pcr.currentBossInfo()))
            pcrPlugin.api.reply(event, TextMsg(msg))
            pcrPlugin.api.sendMsg(
                event.source, MsgEvent(GroupMsgInfo(pcr.gid), TextMsg(msg)))
            raise RemoveCron
        elif status == BigFunAPILoginStatus.NOT_CALL_LOGIN:
            msg = "二维码已失效,请重新扫码"
            pcrPlugin.api.reply(data[1], TextMsg(msg))
            raise RemoveCron
        elif status == BigFunAPILoginStatus.FAILER:
            msg = "登陆失败"
            pcrPlugin.api.reply(data[1], TextMsg(msg))
            raise RemoveCron
    data[2] = status
예제 #13
0
def rank(event: ReceiveEvent[MsgEvent]):
    pcr: PCR = _getPCRObj(event)
    rankInfo = pcr.rank()
    if isinstance(rankInfo, TeamInfo):
        pcrPlugin.api.reply(
            event,
            TextMsg("公会:{}\n当前排名:{} 总分:{}".format(rankInfo.clanName,
                                                  rankInfo.rank,
                                                  format(rankInfo.damage,
                                                         ","))))
예제 #14
0
def delReserve(event: ReceiveEvent[MsgEvent], stage: str, step: str):
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        notdigitMsg = "请输入 1-6 之间的阿拉伯数字\nP.S.: 6 代表 5 王狂暴"
        if not stage.isdigit():
            pcrPlugin.api.reply(event, TextMsg("第一个参数需要输入阿拉伯数字哦"))
            return
        if not step.isdigit():
            pcrPlugin.api.reply(event, TextMsg(notdigitMsg))
            return
        pcr = _getPCRObj(event)
        status = pcr.delReserve(stage,
                                step,
                                member=event.payload.msgInfo.UserId)
        if status:
            pcrPlugin.api.reply(
                event,
                TextMsg("已取消预约{}周目{}".format(stage,
                                             _ReserveBossID2Name(step, pcr))))
        else:
            pcrPlugin.api.reply(event, TextMsg("在预约列表找不到此预约"))
예제 #15
0
def login(event: ReceiveEvent[MsgEvent], gid):
    if isinstance(event.payload.msgInfo, PrivateMsgInfo):
        try:
            if not pcrPlugin.api.getGroupsList(
                    event.source).get(gid).member.get(
                        event.payload.msgInfo.UserId).isAdmin:
                pcrPlugin.api.reply(event, TextMsg("你需要是该群的管理员才可以执行这个操作哦"))
                return
        except NotFoundGroup:
            pcrPlugin.api.reply(event, TextMsg("我还没有加入这个群哦"))
            return
        pcr = PCR(int(event.source.name), gid)
        try:
            pcrPlugin.api.reply(
                event,
                [PicMsg(pcr.loginQrcode()),
                 TextMsg("请使用 bilibili 扫码登录")])
        except BigFunAPIisLogin:
            pcrPlugin.api.reply(event, TextMsg("该群已登录 BigFun"))
            return
        cronManager.append(
            Cron(1, checklogin,
                 [pcr, event, BigFunAPILoginStatus.WAITSCAN, 0]))
예제 #16
0
def cronRank(data):
    if len(data) == 0:
        data.append(0)
        return
    for botuid in pcrPlugin.context['Groups'].keys():
        for gid in pcrPlugin.context['Groups'][botuid].keys():
            pcr: PCR = pcrPlugin.context['Groups'][botuid][gid]
            rankInfo = pcr.rank()
            if isinstance(rankInfo, TeamInfo):
                pcrPlugin.api.sendMsg(
                    Eventer(botuid, ServiceType.Bridge),
                    MsgEvent(
                        GroupMsgInfo(gid),
                        TextMsg("公会:{}\n当前排名:{} 总分:{}".format(
                            rankInfo.clanName, rankInfo.rank,
                            format(rankInfo.damage, ",")))))
예제 #17
0
def OnFriendMsgs(payload):
    try:
        if not 'Data' in payload['CurrentPacket'].keys():  # TODO:暂时所有非聊天信息
            return
        if payload['CurrentPacket']['Data']['FromUin'] == payload['CurrentQQ']:  # 若是自己发送的消息直接忽略
            return
        if payload['CurrentPacket']['Data']['MsgType'] == "TextMsg":
            tmp = MsgEvent(**{"msgInfo": PrivateMsgInfo(**{
                "UserId": payload['CurrentPacket']['Data']['FromUin'],
                "UserName": service.api.FriendsList.get(payload['CurrentPacket']['Data']['FromUin']),
            }),
                "msgContent": TextMsg(payload['CurrentPacket']['Data']['Content']),
                "otherData": {
                "MsgSeq": payload['CurrentPacket']['Data']['MsgSeq'],
            }
            })
        else:
            service.logger.info(json.dumps(payload))
            return
        service.api.sendMsg(Eventer('*', ServiceType.Plugin), tmp)
    except Exception as e:
        service.logger.exception(e)  # 遇到问题咋们就逃避就行了
        return
예제 #18
0
def OnGroupMsgs(payload):
    try:
        if not 'Data' in payload['CurrentPacket'].keys():  # TODO:暂时所有非聊天信息
            return
        if payload['CurrentPacket']['Data']['FromUserId'] == payload['CurrentQQ']:  # 若是自己发送的消息直接忽略
            return
        if payload['CurrentPacket']['Data']['MsgType'] == "TextMsg":
            tmp = MsgEvent(**{"msgInfo": GroupMsgInfo(**{
                "GroupId": payload['CurrentPacket']['Data']['FromGroupId'],
                "GroupName": payload['CurrentPacket']['Data']['FromGroupName'],
                "UserId": payload['CurrentPacket']['Data']['FromUserId'],
                "UserName": payload['CurrentPacket']['Data']['FromNickName'],
            }),
                "msgContent": TextMsg(payload['CurrentPacket']['Data']['Content']),
                "otherData": {
                "MsgSeq": payload['CurrentPacket']['Data']['MsgSeq'],
                "MsgRandom": payload['CurrentPacket']['Data']['MsgRandom'],
            }
            })
        elif payload['CurrentPacket']['Data']['MsgType'] == "AtMsg":
            atContent = json.loads(
                payload['CurrentPacket']['Data']['Content'])
            Content: List[MsgContent] = [TextMsg(atContent['Content'])]
            for aUser in atContent.get('UserID', []):
                Content.append(AtMsg(aUser))
            tmp = MsgEvent(**{"msgInfo": GroupMsgInfo(**{
                "GroupId": payload['CurrentPacket']['Data']['FromGroupId'],
                "GroupName": payload['CurrentPacket']['Data']['FromGroupName'],
                "UserId": payload['CurrentPacket']['Data']['FromUserId'],
                "UserName": payload['CurrentPacket']['Data']['FromNickName'],
            }),
                "msgContent": Content,
                "otherData": {
                "MsgSeq": payload['CurrentPacket']['Data']['MsgSeq'],
                "MsgRandom": payload['CurrentPacket']['Data']['MsgRandom'],
            }
            })
        # TODO: 需要了解图片和文字是同一条消息的情况
        elif payload['CurrentPacket']['Data']['MsgType'] == "PicMsg":
            msgLink = []
            picContent = json.loads(
                payload['CurrentPacket']['Data']['Content'])
            for pic in picContent['GroupPic']:
                msgLink.append(PicMsg.webImg(
                    pic['Url'], {}, PicMsgForword(service.config['qq'], pic['FileMd5'])))
            if 'Content' in picContent:
                msgLink.append(TextMsg(picContent['Content']))
            tmp = MsgEvent(**{"msgInfo": GroupMsgInfo(**{
                "GroupId": payload['CurrentPacket']['Data']['FromGroupId'],
                "GroupName": payload['CurrentPacket']['Data']['FromGroupName'],
                "UserId": payload['CurrentPacket']['Data']['FromUserId'],
                "UserName": payload['CurrentPacket']['Data']['FromNickName'],
            }),
                "msgContent": msgLink,
                "otherData": {
                "MsgSeq": payload['CurrentPacket']['Data']['MsgSeq'],
                "MsgRandom": payload['CurrentPacket']['Data']['MsgRandom'],
            }
            })
        else:
            # self.logger.info(json.dumps(payload))
            return
        service.api.sendMsg(Eventer("*", ServiceType.Plugin), tmp)
    except Exception as e:
        service.logger.exception(e)  # 遇到问题咋们就逃避就行了
        return
예제 #19
0
def cTest(event: ReceiveEvent[MsgEvent], echotext):
    example.api.reply(event, TextMsg("echo: " + echotext))
예제 #20
0
def onPrivateMsgInfo(event: ReceiveEvent[MsgEvent]):
    payload = event.payload
    f = payload.msgContent[0]
    if isinstance(f, TextMsg):
        if f.content == "test":
            example.api.reply(event, TextMsg("i'm Here"))
예제 #21
0
def bossinfo(event: ReceiveEvent[MsgEvent]):
    if isinstance(event.payload.msgInfo, GroupMsgInfo):
        pcr = _getPCRObj(event)
        pcrPlugin.api.reply(event, TextMsg(str(pcr.currentBossInfo())))