From bb6ee74d3b66103342bbae9e073c047e1f81edbb Mon Sep 17 00:00:00 2001 From: Giftina Date: Thu, 14 Jul 2022 18:28:43 +0800 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20=E6=94=B9=E4=B8=80=E4=B8=8B=E6=95=B7?= =?UTF-8?q?=E8=A1=8D=E8=AF=AD=E6=96=99=E6=95=99=E5=AD=A6=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{balabalaTeach.js => perfunctoryTeach.js} | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) rename plugins/{balabalaTeach.js => perfunctoryTeach.js} (71%) diff --git a/plugins/balabalaTeach.js b/plugins/perfunctoryTeach.js similarity index 71% rename from plugins/balabalaTeach.js rename to plugins/perfunctoryTeach.js index 83c9e7d0..eb8bd3c5 100644 --- a/plugins/balabalaTeach.js +++ b/plugins/perfunctoryTeach.js @@ -1,17 +1,17 @@ module.exports = { 插件名: "敷衍语料教学插件", 指令: "^[/!]?说不出话 (.*)", - 版本: "2.1", + 版本: "2.2", 作者: "Giftina", - 描述: "balabala敷衍教学,教给小夜一些比较通用的回复。对于一些难以回复的对话,小夜的词库中没有搜索到回复的时候,小夜会随机回复这些回复作为敷衍,回复了,但完全没有回复的意义。", + 描述: "敷衍语料教学,教给小夜一些比较通用的回复。对于一些难以回复的对话,小夜的词库中没有搜索到回复的时候,小夜会随机回复这些回复作为敷衍,回复了,但完全没有回复的意义。", 使用示例: "说不出话 ?", - 预期返回: "哇!小夜学会啦!小夜可能在说不出话的时候说 ? 噢", + 预期返回: "哇!小夜学会啦!小夜可能在说不出话的时候回复 ? 噢", execute: async function (msg, userId, userName, groupId, groupName, options) { const teachMsg = new RegExp(module.exports.指令).exec(msg)[1]; const teachMsgChecked = teachMsg.replace(/'/g, ""); // 防爆 console.log( - `${userId}(${userName}) 想要教给小夜balabala: ${teachMsgChecked},现在开始检测合法性`.log, + `${userId}(${userName}) 想要教给小夜敷衍语料: ${teachMsgChecked},现在开始检测合法性`.log, ); for (let i in CHAT_BAN_WORDS) { if ( @@ -23,19 +23,19 @@ module.exports = { .indexOf(CHAT_BAN_WORDS[i].toLowerCase()) !== -1 ) { console.log( - `balabala教学: 检测到不允许的词: ${CHAT_BAN_WORDS[i]},退出教学`.error, + `敷衍语料教学: 检测到不允许的词: ${CHAT_BAN_WORDS[i]},退出教学`.error, ); return { type: "text", content: "你教的内容里有主人不允许小夜学习的词qwq" }; } } - console.log("balabala教学: 没有检测到问题,可以学习".log); + console.log("敷衍语料教学: 没有检测到问题,可以学习".log); await PerfunctoryModel.create({ content: teachMsgChecked }) .then(() => { - console.log("balabala教学: 学习成功".log); + console.log("敷衍语料教学: 学习成功".log); }); - return { type: "text", content: `哇!小夜学会啦!小夜可能在说不出话的时候说 ${teachMsgChecked} 噢` }; + return { type: "text", content: `哇!小夜学会啦!小夜可能在说不出话的时候回复 ${teachMsgChecked} 噢` }; }, }; From 16a1526358716b5fc1cc78ddb96b73cb3170544e Mon Sep 17 00:00:00 2001 From: Giftina Date: Fri, 15 Jul 2022 09:31:07 +0800 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20=E5=9B=A0=E8=88=9E=E7=AB=8B=E6=96=B9?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E6=8E=A5=E5=8F=A3=E6=9B=B4=E6=94=B9=EF=BC=8C?= =?UTF-8?q?`=E6=9C=BA=E5=8F=B0=E7=8A=B6=E6=80=81`=20`=E5=85=B3=E6=B3=A8?= =?UTF-8?q?=E6=9C=BA=E5=8F=B0`=20=E5=8A=9F=E8=83=BD=E5=A4=B1=E6=95=88?= =?UTF-8?q?=EF=BC=8C=E5=81=9A=E4=B8=AA=E5=AD=98=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/danceCube.js | 50 +++++++++++++++++++++++---- plugins/danceCube/authorization.token | 2 +- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/plugins/danceCube.js b/plugins/danceCube.js index 6fbac1a9..24e0503e 100644 --- a/plugins/danceCube.js +++ b/plugins/danceCube.js @@ -5,7 +5,7 @@ module.exports = { 插件名: "公测·舞立方信息查询插件", 指令: "^[/!]?(绑定|个人信息|战绩|机台状态|关注机台|我要出勤)(.*)", - 版本: "1.1", + 版本: "1.2", 作者: "Giftina", 描述: "舞立方信息查询,可以查询玩家信息以及机台状态。数据来源以及素材版权归属 胜骅科技 https://www.arccer.com/ ,如有侵权请联系作者删除。", 使用示例: "个人信息", @@ -55,7 +55,12 @@ module.exports = { } const musicIndex = args[2] || defaultMusicIndex; - reply = await GetPlayerRank(playerId, musicIndex); + const playerRank = await GetPlayerRank(playerId, musicIndex); + if (playerRank.error) { + reply = `查询战绩失败:${playerRank.error}`; + } else { + reply = playerRank; + } } // 机台状态 else if (getMachineStateCommand.test(msg)) { @@ -69,7 +74,7 @@ module.exports = { return { type: "text", content: errorNoData }; } else { const location = await AnalysisLocation(playerData.location); - console.log(`将绑定信息地址 ${playerData.location} 解析为 ${location.province + location.city}`.log); + console.log(`将绑定信息地址 ${playerData.location} 解析为 ${location.province + " " + location.city}`.log); if (!location) { return { type: "text", content: "解析你的地区失败了,对不起呀,你还可以手动查询,指令如:机台状态 浙江省 杭州市" }; } else { @@ -83,7 +88,12 @@ module.exports = { return { type: "text", content: "没有正确指定省份或城市噢,正确指令如:机台状态 浙江省 杭州市,市辖区示例:机台状态 上海市" }; } - reply = await GetMachineListByPlace(province, city); + const machineListByPlace = await GetMachineListByPlace(province, city); + if (machineListByPlace.error) { + reply = `查询机台状态失败:${machineListByPlace.error}`; + } else { + reply = machineListByPlace; + } } // 关注机台 else if (focusMachineCommand.test(msg)) { @@ -98,7 +108,12 @@ module.exports = { } const machineId = args[1]; - reply = await FocusMachine(userId, machineId); + const machineFocused = await FocusMachine(userId, machineId); + if (machineFocused.error) { + reply = `关注机台失败:${machineFocused.error}`; + } else { + reply = machineFocused; + } } // 我要出勤 else if (goGoGOCommand.test(msg)) { @@ -110,7 +125,12 @@ module.exports = { return { type: "text", content: "你还没有关注机台呢,禁止出勤,请发送 机台状态 来查询你附近的机台的ID吧" }; } - reply = await GoGoGo(userId); + const couldGoGoGo = await GoGoGo(userId); + if (couldGoGoGo.error) { + reply = `出勤失败:${couldGoGoGo.error}`; + } else { + reply = couldGoGoGo; + } } return { type: "text", content: reply }; @@ -319,8 +339,12 @@ async function GetPlayerRank(playerId, musicIndex) { musicIndex: musicIndex, userId: playerId, }, + validateStatus: (status) => status < 500, }) .then(async function (response) { + if (response.status !== 200) { + return { error: response.data.Message }; + } const results = response.data; const reply = results.map((result) => { const musicName = result.Name; @@ -443,8 +467,12 @@ async function GetMachineListByPlace(province, city) { province: province, city: city, }, + validateStatus: (status) => status < 500, }) .then(async function (response) { + if (response.status !== 200) { + return { error: response.data.Message }; + } const machineList = response.data; const reply = machineList.map((machine) => { const machineName = machine.PlaceName.replace(/\n/g, ""); @@ -497,8 +525,12 @@ async function FocusMachine(userId, machineTerminalID) { onlyPassed: true, getUserInfo: false, // 舞立方点灯计划的点灯玩家 }, + validateStatus: (status) => status < 500, }) .then(async function (response) { + if (response.status !== 200) { + return { error: response.data.Message }; + } const machine = response.data.find((machine) => { return machine.MachineTerminalID === machineTerminalID; }); @@ -553,8 +585,12 @@ async function GoGoGo(userId) { province: focusMachine.province, city: focusMachine.city, }, + validateStatus: (status) => status < 500, }) .then(async function (response) { + if (response.status !== 200) { + return { error: response.data.Message }; + } const machineList = response.data; const machine = machineList.find((machine) => { return machine.MachineTerminalID === focusMachine.machineTerminalID; @@ -580,4 +616,4 @@ ${provinceAndCity} ${address} [CQ:image,file=${machinePicture1Link}][CQ:image,file=${machinePicture2Link}]`; } -const DanceCubeModel = require(path.join(process.cwd(), "plugins", "system", "model", "danceCubeModel.js")); \ No newline at end of file +const DanceCubeModel = require(path.join(process.cwd(), "plugins", "system", "model", "danceCubeModel.js")); diff --git a/plugins/danceCube/authorization.token b/plugins/danceCube/authorization.token index 782c6a52..8d9f652f 100644 --- a/plugins/danceCube/authorization.token +++ b/plugins/danceCube/authorization.token @@ -1 +1 @@ -bearer pSiCl4tEZErNct1IVA-w1pViMWASW6GRTVVW-KbLbw1BKbdwoMiMUDUxv-vclIUiUjfhcf8QcZeH5bjUaHG3hAk0S4gFPbrIw-EPshC8EMJgsOhh02A8b4tFXDJcA2GV23RTKc5oSXAPoFRLHQCxtVYBSv29gnxE5hW8TGZUNNNAFSdCYdx37xS_XByEAgevNuslcBQ7CWa6pN1lzg0fm5T5Si3Rvl8JTXu-GcQy05h8LTgKwzcgtAYrrgaVJInLl4K2P93MnuXyJ-wV4OeCdWWiSrnAkIuQU4w7uL3AgNrpoCF66ICC_oiVB4CMzNcW1Mqscvj5wvptx5NtGiLhW95CS0wZubaODq_tQ8AZs2u0hFw2AeNiRPJAYxjBetL9MBzy6oMt78Sg7bAlBxlKHvM7QyA8R2p_iJXSNwJ8oGGINiD2P2OxTf5zog7nU9puibhNUSK6WtkUwR6havcfmncWfPEOVSKfTOagCcbZohRvbN6YxUwUEKY21qC6fqNPVxnorJGfhQpWABf0s0i2ReAw6DyysaUvfHaHfbSZL4wJs4Cs66qvJqgNMIVWQIBUx-7FfxZ0a98M_MppmJFsY9Qq_x2lyjZb263gxUsoBiu0fMa4xQx1HtRX3EkhnDQ4BXOuUw1LVLV3mKRdcz9m1BqZrSm6hICQ3pLoBr7CXHYIkjiXVDPTzJ_cpzwNEblPjxHB9UbKhQcJEQAwM2Dy-V0ppVxH73INJ5J3-FCplXs3I5N7ORIcn_F4LaVcFlr1TeNYqLq53paGmCstmkWjyKOvnFfUOjxjHOgxtcIoX3VH3pW59zzwyFBqC5ib6s3SaPTA0sUXkvg3OjXHf83AsQCcYykq8LixMNaC_rSC2FhTDejcMsqX648sV1ByIKNgvJCY_Sd7YNO-F9f7Xb443OkI_e72Ym-Q9Gf8YThVC9IPa5dYS30UlV32U6PxbJs5 \ No newline at end of file +bearer KexZ0pfDx6GnIxUx2QBxoeBVVtPcktcUB086NooJGXQTzmbusxfQ7--wOkQVKDqvSOHxTetNHLwPTqeH-ZlJrIekFLw6dO63_Up500OxThO_vhFFA6P_Aa9gGpi9jArLEhZoD7sATPJpnr9pa4AgWGdiNBr4cJgWfbCgBrvbRpskmjpDyqNqw0hHjw9p6aDJemRvMjmpDlMC8_ub7NjPN33gAr6LQMja9BmuKXzf_1LD1ddwHmdkq9ryqx82wqpLOVk1XH6gH30DK3RDaJ8xSFzNctA8ES7lP5gOmJWasAiYZpgR79FF_8fLM6LHrxeAbS7AU2PsruPvz34eC6wuH0VDcQKEemPNSvvcr4otTmZpKWiPlnn7JRK4s051xTT1n45AW1iR5t1TNpiZal-E8lBEQm-ROFWOoUGRL5CgKza3pUWQLOcPnxYVD-qlJTyNmU-24fIN1EcRxPK2GFUyiiJb7gt1AOO2ZhdyLwIuFA9APT5i2hcWP3IXVT_VsqBb7WEEA9xLE6fuvGryD3JbjodeTpcIIxGJlLbwnC-XLhuh6mogGN8fQtFzwXsa5Y59zpTsSAzpzf4nrd7KRGKc53gT2rOUb-vksigmbjTLezBd2GquelivoFmbTWyWsCCz5ci4sk5D1cPk51iaR1Jn-ioMB7xbo5o-kelcNubMC9qz9zcZidOt7-msModY0yBPb7HEK3ukJROa6CRig4RXczjo0wz3MENxzc11RZjwsDteu0O1mhs-B-PxW-UNixXC1qtyskrifjFBZZxhgtVIFmwRb-dqs5kKzz4al1JHfA3afVvKCTbDZ6j9hQjL5R9cz-zNVvbTZia5lwOVqMitZGdV7RV6062niQTXqcWGxsHvR0U--Bxy-hjtDLXPhavnRQYFam2ljwOCGDoolRXsrxNUy-iVuv50uBtAvBlPqd4EmvHKnojfmAygoZJfDf0K \ No newline at end of file From e6d2eec8af94b06b6aa81e1e591655ec891c8335 Mon Sep 17 00:00:00 2001 From: Giftina Date: Fri, 15 Jul 2022 09:37:15 +0800 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=E7=BE=A4=E6=9C=8D=E5=8A=A1=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E8=87=AA=E5=8A=A8=E9=87=8D=E8=AF=95=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=BF=87=E7=9F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/system/utils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/system/utils.js b/plugins/system/utils.js index 211561bc..35acc6bf 100644 --- a/plugins/system/utils.js +++ b/plugins/system/utils.js @@ -1,7 +1,6 @@ /** * @name 系统工具类 * @description 各种公用函数和系统底层函数 - * @version 2.3 */ module.exports = { /** @@ -244,7 +243,7 @@ module.exports = { }); if (!groupList) { - setTimeout(() => this.InitGroupList(), 5000); + setTimeout(() => this.InitGroupList(), 10000); return; } else { const groupIdList = groupList.map((group) => group.group_id); From 80cc8d42666fbef2660c25dec0431eeae473eadd Mon Sep 17 00:00:00 2001 From: Giftina Date: Fri, 15 Jul 2022 11:38:06 +0800 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E9=80=82=E9=85=8D=E6=96=B0=E7=89=88?= =?UTF-8?q?=E8=88=9E=E7=AB=8B=E6=96=B9=E6=9C=BA=E5=8F=B0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/db.db | Bin 745472 -> 745472 bytes plugins/danceCube.js | 226 ++++++------------------- plugins/system/model/danceCubeModel.js | 7 +- 3 files changed, 55 insertions(+), 178 deletions(-) diff --git a/config/db.db b/config/db.db index b1a99e8384a10e6a6e67bbfffd53ad70f1ebc6e4..1ee206e9a13e2f77f04876536aa56ec0056af008 100644 GIT binary patch delta 148 zcmZoTpxbajcY?IwVg?3=Z9ohKj6D-|j1?C%==s<1^8aAq=G?}>_mBT9-x@wX-gKTz zJO*3`xc_r*+t?t@IaxtKnyWE{i(On^p0TNX@>0$vlb`ZxZtmqOS6$4aAkfU>(9Yt( i2*gZ4%nZaVK+FonY(UHo#2i4(3B+96Ssb|k$O8a#_a?Rg delta 187 zcmZoTpxbajcY?Iw3(8#V#%{&)BRx`2gnrflKi4dA9hA&QO?}VywoO#HV4Kw i2c|X$<~9eGHV4)=2evi`_BIEOHV4i&2d-rf+zJ2!_B7Z4 diff --git a/plugins/danceCube.js b/plugins/danceCube.js index 24e0503e..e3beae71 100644 --- a/plugins/danceCube.js +++ b/plugins/danceCube.js @@ -3,9 +3,9 @@ */ module.exports = { - 插件名: "公测·舞立方信息查询插件", - 指令: "^[/!]?(绑定|个人信息|战绩|机台状态|关注机台|我要出勤)(.*)", - 版本: "1.2", + 插件名: "舞立方信息查询插件", + 指令: "^[/!]?(绑定|个人信息|战绩|插眼|我要出勤)(.*)", + 版本: "2.0", 作者: "Giftina", 描述: "舞立方信息查询,可以查询玩家信息以及机台状态。数据来源以及素材版权归属 胜骅科技 https://www.arccer.com/ ,如有侵权请联系作者删除。", 使用示例: "个人信息", @@ -62,75 +62,32 @@ module.exports = { reply = playerRank; } } - // 机台状态 - else if (getMachineStateCommand.test(msg)) { - let province = args[1]; - let city = province?.includes("市") ? "市辖区" : args[2]; - - // 如果没有携带参数,则从绑定信息中获取,没有则提示绑定 - const playerData = await DanceCubeModel.findOne({ where: { userId } }); - if (!args[1]) { - if (!playerData) { - return { type: "text", content: errorNoData }; - } else { - const location = await AnalysisLocation(playerData.location); - console.log(`将绑定信息地址 ${playerData.location} 解析为 ${location.province + " " + location.city}`.log); - if (!location) { - return { type: "text", content: "解析你的地区失败了,对不起呀,你还可以手动查询,指令如:机台状态 浙江省 杭州市" }; - } else { - province = location.province; - city = location.city; - } - } - } - - if (!province || !city) { - return { type: "text", content: "没有正确指定省份或城市噢,正确指令如:机台状态 浙江省 杭州市,市辖区示例:机台状态 上海市" }; - } - - const machineListByPlace = await GetMachineListByPlace(province, city); - if (machineListByPlace.error) { - reply = `查询机台状态失败:${machineListByPlace.error}`; - } else { - reply = machineListByPlace; - } - } - // 关注机台 - else if (focusMachineCommand.test(msg)) { - // 如果没有携带 playerId 参数,则查询用户有没有绑定玩家,没有则提示绑定 + // 插眼 + else if (setLocationCommand.test(msg)) { + // 查询用户有没有绑定玩家,没有则提示绑定 const playerData = await DanceCubeModel.findOne({ where: { userId } }); if (!playerData) { return { type: "text", content: errorNoData }; } - // 如果没有指定机台ID,需要引导用户输入机台ID + // 如果没有指定地名,需要引导用户输入地名 else if (!args[1]) { - return { type: "text", content: "好像没有指定机台ID噢,请发送 机台状态 指令来查询你附近的机台的ID吧" }; + return { type: "text", content: "好像没有指定地名噢,请发送 插眼 地名 在指定位置插眼吧" }; } - const machineId = args[1]; - const machineFocused = await FocusMachine(userId, machineId); - if (machineFocused.error) { - reply = `关注机台失败:${machineFocused.error}`; - } else { - reply = machineFocused; - } + const location = args[1]; + reply = await Geocoding(userId, location); } // 我要出勤 else if (goGoGOCommand.test(msg)) { - // 查询用户关注的机台状态,如果没有关注机台,则提示用户关注机台 + // 查询用户设定的坐标附近的机台状态,如果没有插眼,则提示用户插眼 const playerData = await DanceCubeModel.findOne({ where: { userId } }); if (!playerData) { return { type: "text", content: errorNoData }; - } else if (!playerData.focusMachine) { - return { type: "text", content: "你还没有关注机台呢,禁止出勤,请发送 机台状态 来查询你附近的机台的ID吧" }; + } else if (!playerData.location) { + return { type: "text", content: "你还没有插眼呢,禁止出勤,请发送 插眼 地名 在指定位置插眼吧" }; } - const couldGoGoGo = await GoGoGo(userId); - if (couldGoGoGo.error) { - reply = `出勤失败:${couldGoGoGo.error}`; - } else { - reply = couldGoGoGo; - } + reply = await GoGoGo(userId); } return { type: "text", content: reply }; @@ -140,8 +97,7 @@ module.exports = { const bindCommand = new RegExp(/^[/!]?绑定(.*)/); const getPlayerInfoCommand = new RegExp(/^[/!]?个人信息(.*)/); const getRankCommand = new RegExp(/^[/!]?战绩(.*)/); -const getMachineStateCommand = new RegExp(/^[/!]?机台状态(.*)/); -const focusMachineCommand = new RegExp(/^[/!]?关注机台(.*)/); +const setLocationCommand = new RegExp(/^[/!]?插眼(.*)/); const goGoGOCommand = new RegExp(/^[/!]?我要出勤/); const defaultMusicIndex = 6; // 音乐类型,1 最新,2 国语,3 粤语,4 韩文,5 欧美,6 其他 @@ -170,8 +126,8 @@ const headers = { const api = { playerInfo: baseURL + "Dance/api/User/GetInfo", playerRank: baseURL + "Dance/api/User/GetMyRank", - machineList: baseURL + "Dance/OAuth/GetMachineList", - machineListByPlace: baseURL + "Dance/OAuth/GetMachineListByPlace", + geocoding: "https://api.map.baidu.com/geocoding/v3", + machineListByLocation: baseURL + "Dance/OAuth/GetMachineListByLocation", }; //加载字体 const titleFontName = "优设标题圆"; @@ -289,7 +245,7 @@ async function AnalysisPlayerInfo(playerId) { ctx.font = `160px '${eventFontName}'`; ctx.fillStyle = "rgba(99, 99, 99, 0.2)"; ctx.textAlign = "center"; - ctx.fillText("公 测", canvas.width / 2, canvas.height / 2 + 80); + ctx.fillText("测 试", canvas.width / 2, canvas.height / 2 + 80); // 保存图片 const fileName = `${playerId}.png`; @@ -444,7 +400,7 @@ async function GetPlayerRank(playerId, musicIndex) { ctx.font = `170px '${eventFontName}'`; ctx.fillStyle = "rgba(33, 33, 33, 0.4)"; ctx.textAlign = "center"; - ctx.fillText("公 测", canvas.width / 2, canvas.height / 2 + 80); + ctx.fillText("测 试", canvas.width / 2, canvas.height / 2 + 80); // 保存图片 const fileName = `${playerId}.png`; @@ -456,151 +412,74 @@ async function GetPlayerRank(playerId, musicIndex) { } /** - * 根据省市查询机台状态 - * @param {string} province 省 - * @param {string} city 市 - */ -async function GetMachineListByPlace(province, city) { - const machineList = await axios.get(api.machineListByPlace, { - headers: headers, - params: { - province: province, - city: city, - }, - validateStatus: (status) => status < 500, - }) - .then(async function (response) { - if (response.status !== 200) { - return { error: response.data.Message }; - } - const machineList = response.data; - const reply = machineList.map((machine) => { - const machineName = machine.PlaceName.replace(/\n/g, ""); - const address = machine.Address.replace(/\n/g, ""); - const status = machine.Online ? "🟢" : "🔴"; - const machineGeneration = machine.Img1.includes("9700") ? "Ⅰ代" : "Ⅱ代"; // 按机台图片名判断其实不是很准确,但是大致看了下八九不离十 - const machineTerminalID = machine.MachineTerminalID; - return `${status}${machineName} ${machineGeneration}\nID: ${machineTerminalID}\n${address}\n`; - }); - return `${province}${city}机台状态: - -${reply.join("\n")} -发送 关注机台 机台ID 可以关注机台 -(机台在线状态和世代仅供参考,以实际状态为准) -`; - }) - .catch(function (error) { - console.log(`获取机台状态失败: ${error}`.error); - return "获取机台状态失败: ", error; - }); - return machineList; -} - -/** - * 根据 location 解析省市 - * @param {string} location 省市 - */ -async function AnalysisLocation(location) { - // 简陋的省份解析 - let province = location.split("省")[0]; - const city = location.split("省")[1]; - - if (!province || !city) { - return; - } - - province += "省"; - return { province, city }; -} - -/** - * 关注机台,后续出勤时直接查询该机台号 - * @param {string} machineTerminalID 机台号 + * 插眼,根据玩家提供的地名查询经纬度并存入玩家数据库 + * @param {string} location 位置 */ -async function FocusMachine(userId, machineTerminalID) { - // 先验证机台是否存在 - const machineInfo = await axios.get(api.machineList, { - headers: headers, +async function Geocoding(userId, location) { + // 百度地理编码 + const { lng, lat } = await axios.get(api.geocoding, { params: { - onlyPassed: true, - getUserInfo: false, // 舞立方点灯计划的点灯玩家 + address: location, + ak: "u9vKc81UQZLPvVkNnX0XklXI58WqiKF6", + output: "json", }, - validateStatus: (status) => status < 500, }) .then(async function (response) { - if (response.status !== 200) { - return { error: response.data.Message }; + if (response.data.status !== 0) { + return "地理编码失败"; } - const machine = response.data.find((machine) => { - return machine.MachineTerminalID === machineTerminalID; - }); - return machine; + return response.data.result.location; }) .catch(function (error) { - console.log(`获取玩家资料失败: ${error}`.error); - return "获取玩家资料失败: ", error; + console.log(`地理编码失败: ${error}`.error); + return "地理编码失败: ", error; }); - if (!machineInfo) { - return "这个机台不存在呢,是不是输错了呢,请发送 机台状态 指令来查询机台ID吧"; - } - - // 再获取机台位置 - const province = machineInfo.ProvinceAndCity.split(" ")[0]; - const city = machineInfo.ProvinceAndCity.split(" ")[1]; - await DanceCubeModel.update({ - focusMachine: { - machineTerminalID: machineTerminalID, - province: province, - city: city, - }, + location: { lng, lat }, }, { where: { userId: userId, } }); - return `关注成功,现在你关注的机台是 ${machineInfo.PlaceName},发送 我要出勤 查询你关注的机台情况`; + return "插眼成功,发送 我要出勤 查询你附近的机台状态"; } /** - * 查询出勤状态 + * 查询眼位附近机台状态 * @param {*} userId 用户id */ async function GoGoGo(userId) { /** - * focusMachine: { machineTerminalID, province, city } + * location: { lng, lat } */ - const { focusMachine } = await DanceCubeModel.findOne({ + const { location } = await DanceCubeModel.findOne({ where: { userId: userId, }, - attributes: ["focusMachine"], + attributes: ["location"], }); - const machine = await axios.get(api.machineListByPlace, { + const machineList = await axios.get(api.machineListByLocation, { headers: headers, - params: { - province: focusMachine.province, - city: focusMachine.city, - }, - validateStatus: (status) => status < 500, + params: { ...location }, }) .then(async function (response) { - if (response.status !== 200) { - return { error: response.data.Message }; - } - const machineList = response.data; - const machine = machineList.find((machine) => { - return machine.MachineTerminalID === focusMachine.machineTerminalID; - }); - return machine; + console.log(`查询眼位附近机台状态:${response.data}`); + return response.data; }) .catch(function (error) { - console.log(`获取机台状态失败: ${error}`.error); - return "获取机台状态失败: ", error; + console.log(`获取机台状态失败:${error}`.error); + return "获取机台状态失败:", error; }); + + if (machineList.length === 0) { + return "获取机台状态失败:附近没有找到任何机台"; + } + + const machineCount = machineList.length; + const machine = machineList[0]; // 选择最近的一台舞立方 const machineName = machine.PlaceName.replace(/\n/g, ""); const provinceAndCity = machine.ProvinceAndCity.replace(/\n/g, ""); const address = machine.Address.replace(/\n/g, ""); @@ -609,7 +488,8 @@ async function GoGoGo(userId) { const machineGeneration = machine.Img1.includes("9700") ? "Ⅰ代机" : "Ⅱ代机"; const machinePicture1Link = `https://dancedemo.shenghuayule.com/Dance/${machine.Img1}`; const machinePicture2Link = `https://dancedemo.shenghuayule.com/Dance/${machine.Img2}`; - return `${status} + return `眼位附近有${machineCount}台舞立方,下面播报距离眼位最近的舞立方状态: +${status} ${machineName} ${machineGeneration} ${provinceAndCity} ${address} 坐标:${longitudeAndLatitude} diff --git a/plugins/system/model/danceCubeModel.js b/plugins/system/model/danceCubeModel.js index f6d9c25a..074c4063 100644 --- a/plugins/system/model/danceCubeModel.js +++ b/plugins/system/model/danceCubeModel.js @@ -23,15 +23,12 @@ const DanceCubeModel = sequelize.define("danceCube", { type: DataTypes.CHAR(20), }, location: { - type: DataTypes.CHAR(10), - }, - focusMachine: { type: DataTypes.CHAR, set: function (value) { - return this.setDataValue("focusMachine", JSON.stringify(value)); + return this.setDataValue("location", JSON.stringify(value)); }, get: function () { - return JSON.parse(this.getDataValue("focusMachine")); + return JSON.parse(this.getDataValue("location")); }, }, }, { From 966926f5a6e83de631162d70b1c9675eb7dbbcc9 Mon Sep 17 00:00:00 2001 From: Giftina Date: Fri, 15 Jul 2022 12:08:56 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=E6=8F=92=E7=9C=BC=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/danceCube.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/danceCube.js b/plugins/danceCube.js index e3beae71..0a5fffbb 100644 --- a/plugins/danceCube.js +++ b/plugins/danceCube.js @@ -1,6 +1,5 @@ -/** - * authorization.token 文件内容为玩家账户密钥,向服务器请求数据时会携带该参数鉴权,具有修改账户的最高权限,需要自行抓包获取,请勿透露给不信任的他人,否则最糟糕的情况可能会导致游戏账户被恶意注销 - */ +// 用于插眼所需要的百度地理编码密钥,需要自己去申请:https://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding +const baiduAk = ""; module.exports = { 插件名: "舞立方信息查询插件", @@ -107,6 +106,9 @@ const { createCanvas, loadImage, registerFont } = require("canvas"); // 用于 const path = require("path"); const fs = require("fs"); const axios = require("axios").default; +/** + * authorization.token 文件内容为玩家账户密钥,向服务器请求数据时会携带该参数鉴权,具有修改账户的最高权限,需要自行抓包获取,请勿透露给不信任的他人,否则最糟糕的情况可能会导致游戏账户被恶意注销 + */ const authorization = fs.readFileSync( path.join(__dirname, "danceCube", "authorization.token"), "utf-8", @@ -417,24 +419,29 @@ async function GetPlayerRank(playerId, musicIndex) { */ async function Geocoding(userId, location) { // 百度地理编码 - const { lng, lat } = await axios.get(api.geocoding, { + const { lng, lat, error } = await axios.get(api.geocoding, { params: { address: location, - ak: "u9vKc81UQZLPvVkNnX0XklXI58WqiKF6", + ak: baiduAk, output: "json", }, }) .then(async function (response) { if (response.data.status !== 0) { - return "地理编码失败"; + console.log(`地理编码失败:${response.data.message} `.log); + return { error: response.data.message }; } return response.data.result.location; }) .catch(function (error) { - console.log(`地理编码失败: ${error}`.error); - return "地理编码失败: ", error; + console.log(`地理编码失败: ${error} `.log); + return { error }; }); + if (!lng || !lat) { + return `插眼失败:${error},可能是这个地名不太好找,请换个地名再试试`; + } + await DanceCubeModel.update({ location: { lng, lat }, }, { @@ -466,11 +473,11 @@ async function GoGoGo(userId) { params: { ...location }, }) .then(async function (response) { - console.log(`查询眼位附近机台状态:${response.data}`); + console.log(`查询眼位附近机台状态:${response.data} `); return response.data; }) .catch(function (error) { - console.log(`获取机台状态失败:${error}`.error); + console.log(`获取机台状态失败:${error} `.error); return "获取机台状态失败:", error; }); @@ -483,7 +490,7 @@ async function GoGoGo(userId) { const machineName = machine.PlaceName.replace(/\n/g, ""); const provinceAndCity = machine.ProvinceAndCity.replace(/\n/g, ""); const address = machine.Address.replace(/\n/g, ""); - const longitudeAndLatitude = `${machine.Longitude}, ${machine.Latitude}`; // 经纬度 + const longitudeAndLatitude = `${machine.Longitude}, ${machine.Latitude} `; // 经纬度 const status = machine.Online ? "🟢机台在线,立即出勤" : "🔴机台离线,散了吧"; const machineGeneration = machine.Img1.includes("9700") ? "Ⅰ代机" : "Ⅱ代机"; const machinePicture1Link = `https://dancedemo.shenghuayule.com/Dance/${machine.Img1}`;