00-Adventure.zip

  • 带头大哥c
    了解作者
  • MQL
    开发工具
  • 42KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 0
    下载次数
  • 2020-01-08 15:48
    上传日期
bot抢答机器人 非常好玩非常好玩 基于呱聊 bot sdk
00-Adventure.zip
  • src
  • main.js
    2.4KB
  • script.yaml
    183.6KB
  • script_bak.yaml
    183.3KB
  • callback.js
    7.5KB
  • save.js
    560B
  • loader.js
    625B
  • .gitignore
    18B
  • package.json
    501B
  • pack.ps1
    436B
内容介绍
// 群聊@消息示例 // { // "message": "test", // "type": 1, // "timestamp": 1562128536, // "extra": {}, // "app": "rtx", // "groupid": "wrkSFfCgAAlH7cMsR2wXRK6KGqocFtEw", // "senderid": "pixelcao", // "sendername": "曹一聪" // } async function defaultCallback(msgObj, services) { // return "默认回复" // await services.push.replyToGamerchatMD("主动回复消息", "test") // return "\n```\n" + JSON.stringify(msgObj, null, 2) + "\n```"; return "> 打扎好,我是`00后入学考试`,检验一下你是合格的二次元er吗?💯\n@我,就能开始玩啦~" } async function groupatCallback(msgObj, services) { // await services.push.replyToBotplatformMD("[主动定向推送]群聊@消息") // return defaultCallback(msgObj, services); // return "\n```\n" + JSON.stringify(msgObj, null, 2) + "\n```"; console.log("\n======G-START=======\n") // 过滤消息 if (msgObj.message == undefined) { return "用户消息未定义" } // 设置群聊锁 var saveKey = msgObj.groupid + "_" + msgObj.channelid if (saveKey == undefined || saveKey == "") { return "群聊ID获取失败" } console.log("saveKey:", saveKey) var lockKey = saveKey + "_lock" // var lockValue = await services.storage.doOne("get", lockKey, []) // if (lockValue == "1" || lockValue == 1) { // return "撞车啦,有人正在答题,请等待Bot回复^_^" // } // await services.storage.doOne("set", lockKey, ["1"]) // 使用 Seq 批量操作,不要像上面这样分两步 var reqList = [{ cmd: "get", key: lockKey, args: [] }, { cmd: "set", key: lockKey, args: ["1"] }] var lockValueSeq = await services.storage.commitSeq("kv", reqList) console.log("lockValueSeq:", JSON.stringify(lockValueSeq)) if (lockValueSeq != undefined && lockValueSeq.length == 2) { var lockValue = lockValueSeq[0]['value'] if (lockValue == "1" || lockValue == 1) { return "撞车啦,有人正在答题,请等待Bot回复^_^" } } else { await services.storage.doOne("set", lockKey, ["0"]) return "群聊锁获取失败:" + JSON.stringify(lockValueSeq) } msgObj.message = String(msgObj.message).replace("哔哩哔哩入学考试Debug", "") msgObj.message = String(msgObj.message).replace("哔哩哔哩入学考试", "") msgObj.message = String(msgObj.message).replace("哔哩哔哩", "") msgObj.message = String(msgObj.message).replace("入学考试", "") msgObj.message = String(msgObj.message).replace("@", "") msgObj.message = String(msgObj.message).trim() var play = require('@tencent/mdgame') var loader = require('./loader') var save = require('./save') var objpath = new Object() var script = loader('script.yaml', objpath) if (script == undefined) { await services.storage.doOne("set", lockKey, ["0"]) return "剧本加载失败: " + objpath["path"] } var profile = await save.loadFromCloud(services.storage, saveKey) if (profile == undefined) { console.log("creating profile from scratch") profile = { player: saveKey, chapter: "1.1", variables: {}, inputs: [] } } console.log("curr player:", msgObj.sendername, "input:", msgObj.message) console.log("curr profile:", JSON.stringify(profile)) profile.inputs.push(msgObj.message) profile.player = String(msgObj.sendername) // [DR] 清空上报队列 profile.variables["reportaction"] = ""; // [DR] 记录玩家参与次数 profile.variables["usertrigger"] = profile.variables["usertrigger"] ? profile.variables["usertrigger"] : {} profile.variables["usertrigger"][msgObj.senderid] = profile.variables["usertrigger"][msgObj.senderid] ? profile.variables["usertrigger"][msgObj.senderid] + 1 : 1 var scene = play(msgObj.message, profile, script) if (scene == undefined) { await services.storage.doOne("set", lockKey, ["0"]) return "关卡渲染失败" } profile.chapter = scene.chapter profile.variables = scene.variables var saveRet = await save.saveToCloud(services.storage, saveKey, profile) if (String(saveRet).trim() != "OK") { await services.storage.doOne("set", lockKey, ["0"]) return "存档失败" } await services.storage.doOne("set", lockKey, ["0"]) // [Debug] 存档上报到企业微信 // var debugMsg = services.push.packMessage(String(JSON.stringify(scene.variables, null, 2)), true, "rtx") // debugMsg.setBotID("44d3070d-bb8a-47cd-a741-356b431638d4") // await services.push.pushBaseMessage(debugMsg) // [DR] 数据上报 console.log("ReportAction: ", profile.variables["reportaction"]) if (profile.variables["reportaction"] != "") { var datareports = [] var reportaction = profile.variables["reportaction"] // 根据 reportaction 生成上报队列 if (reportaction == "start") { datareports.push({ keys: ["action", "userid"], vals: ["start", msgObj.senderid] }); } // 上报游戏结果 var reportFinish = (finishResult) => { // 上报每个玩家游玩次数 if (profile.variables["usertrigger"] != undefined) { Object.keys(profile.variables["usertrigger"]).forEach((uid) => { datareports.push({ keys: ["action", "userid", "rounds"], vals: ["trigger", uid, profile.variables["usertrigger"][uid]] }) }) } // 上报游戏完成数/总回合数 var timeElapsed = (Date.now() / 1000 | 0) - profile.variables["starttime"] datareports.push({ keys: ["action", "userid", "timeelapsed", "rounds", "result"], vals: ["finish", msgObj.senderid, timeElapsed, profile.variables["rounds"], finishResult] }); } if (reportaction == "succ" || reportaction == "fail") { reportFinish(reportaction) } // 上报所生成的队列 for (var x = 0; x < datareports.length; x++) { var reportFunc = services.report.generateReportFunction.apply(services.report, datareports[x]["keys"]) var reportRet = await reportFunc.apply(services.report, datareports[x]["vals"]) console.log("[DR] ret:", reportRet, "content:", datareports[x]); } } console.log("\n======G-END=======\n") return scene.output } async function botlinkCallback(msgObj, services) { // await services.push.replyToBotplatformMD("[主动定向推送]链接消息") return defaultCallback(msgObj, services); } async function privatechatCallback(msgObj, services) { // await services.push.replyToBotplatformMD("[主动定向推送]私聊消息") // return defaultCallback(msgObj, services); return "暂不支持私聊游玩" } async function timerCallback(msgObj, services) { // await services.push.replyToBotplatformMD("[主动定向推送]定时器消息") return defaultCallback(msgObj, services); } async function eventCallback(msgObj, services) { // await services.push.replyToBotplatformMD("[主动定向推送]事件消息") return defaultCallback(msgObj, services); } module.exports = { default: defaultCallback, groupat: groupatCallback, botlink: botlinkCallback, privatechat: privatechatCallback, timer: timerCallback, event: eventCallback };
评论
    相关推荐
    • javascript
      javascript入门基础教程,帮助javascript初学者了解和学习javascript基础
    • javascript
      Javascript资料,欢迎新手,下载一下知识点去学习~
    • JavaScript
      JavaScript的基础知识,适合刚开始学Javascript的学者
    • javascript
      这是JAVASCRIPT方面的开发资料大家看看
    • JavaScript
      集合了JavaScript的特效,教材,教程和手册,供学习JavaScript的人学习参考
    • JavaScript
      10张图片,javascript知识点归纳
    • javascript
      Javascript的文档 系列书籍影音
    • JavaScript
      JavaScript文档JavaScript文档JavaScript文档JavaScript文档JavaScript文档
    • javascript
      javascript基础教程,适合初学者用
    • JavaScript
      JavaScript中文帮助文档,javascript DOM,微软scrpit技术:包括JavaScript中文帮助文档(.chm), javascript DOM(.chm),微软scrpit技术(.exe)