diff --git a/config-template/permission-template.json b/config-template/permission-template.json index 97eee0f..bb71ac5 100644 --- a/config-template/permission-template.json +++ b/config-template/permission-template.json @@ -184,6 +184,24 @@ "admin", "owner" ] + }, + "_repeater": { + "activation": true, + "help": null, + "isadmin": [ + "member", + "admin", + "owner" + ] + }, + "_noAbbreviated": { + "activation": true, + "help": null, + "isadmin": [ + "member", + "admin", + "owner" + ] } } } \ No newline at end of file diff --git a/index.js b/index.js index 790ff4c..c22b9a9 100644 --- a/index.js +++ b/index.js @@ -41,7 +41,9 @@ const { baiduForU } = require("./plugins/plugin-baidu-for-u"); // 为你百 const { send } = require("./plugins/plugin-send"); // 反馈 const { biliLive, getEveryLiveStatus } = require("./plugins/bilibili/plugin-bili-live"); // bili直播间 const { ping } = require("./plugins/mcbot/plugin-mcbot"); // mcbot -const { setRegReply, deleteRegReply, customRegReply, getRegReplyList } = require("./plugins/plugin-custom-regular-reply"); // 自定义正则回复 +const { customRegReply } = require("./plugins/plugin-custom-regular-reply"); // 自定义正则回复 +const { repeater } = require("./plugins/plugin-repeater"); // 复读 +const { noAbbreviated } = require("./plugins/plugin-yyds"); // 好好说话 // 通知类插件 const { increase } = require("./plugins/plugin-increase"); // 入群欢迎 const { decrease } = require("./plugins/plugin-decrease"); // 退群 @@ -114,8 +116,10 @@ bot.on("message.group.normal", function (e) { case "-mc": // mcbot ping(this, e, args); break; - default: // 触发自定义回复 - customReply(this, e, cmd); + default: + noAbbreviated(this, e); // 好好说话 + repeater(this, e); // 复读 + customReply(this, e, cmd); // 触发自定义回复 break; } }) diff --git a/package-lock.json b/package-lock.json index 5a80b25..4831748 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "lingcat-bot", - "version": "2.0.0", + "version": "2.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -438,6 +438,14 @@ "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.3.tgz", "integrity": "sha1-2sh4dxPJlmhJ/IGAd36+nB3fO4Y=" }, + "axios": { + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", + "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", + "requires": { + "follow-redirects": "^1.14.0" + } + }, "base64-js": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", @@ -1427,4 +1435,4 @@ } } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 7da3577..d3cbc42 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "account": 123456789, "botNickname": "灵喵", "owner": 123456789, - "version": "2.1.0", + "version": "2.1.3", "description": "", "main": "index.js", "scripts": { diff --git a/plugins/mcbot/mcHandle.js b/plugins/mcbot/mcHandle.js index dcf77ac..ecd4c7a 100644 --- a/plugins/mcbot/mcHandle.js +++ b/plugins/mcbot/mcHandle.js @@ -18,8 +18,9 @@ const getPlayerInfo = async (host, port = 25565) => { let playerInfo = serverInfo?.players; let playerList = serverInfo?.players?.sample; let players = []; - if (typeof playerList === "undefined" || playerList?.length === 0) players = "暂无信息"; - playerList.forEach(player => { + if (playerList?.length === 0) players = "暂无信息"; + else if (typeof playerList === "undefined") players = "该服务器空荡荡~"; + else playerList.forEach(player => { players.push(player?.name); }); playerInfo["sample"] = players; diff --git a/plugins/plugin-repeater.js b/plugins/plugin-repeater.js new file mode 100644 index 0000000..fb6834c --- /dev/null +++ b/plugins/plugin-repeater.js @@ -0,0 +1,37 @@ +"use strict" +const { getPermission } = require("../lib/permission"); +const msgList = {}; + +async function repeater(_bot, data, args = null) { + if (!await getPermission(data, "repeater")) return; + const startRepeat = 3; // 从第三条开始复读 + const repeatProbability = 0.35; // 复读概率 + const cd = 3; // 若复读冷却条数 + const gid = String(data.group_id); + if (typeof msgList?.[gid] === "undefined") msgList[gid] = []; + if (msgList[gid].length === 25) msgList[gid] = []; // 清理消息 + msgList[gid].push(data.raw_message); + if (!isEqual(msgList[gid], startRepeat, cd, "✈")) return; + let isSendMsg = Math.random() < repeatProbability; + if (isSendMsg) { + data.reply(data.raw_message); + msgList[gid].push("✈"); // 标志已复读 + } + console.log(msgList) +} +exports.repeater = repeater; + +// 比较后n个元素是否相等 +function isEqual(array, num, cd, symbol) { + let symIndex = array.indexOf(symbol); + if (symIndex !== -1 && symIndex + (cd + 1) < array.length) array = array.slice(symIndex + cd + 1); + if (array.length < num) return false; + let equal = true; + for (let index = array.length - 1; index > array.length - num; index--) { + if (array[index] !== array[index - 1]) { + equal = false; + break; + } + } + return equal; +} \ No newline at end of file diff --git a/plugins/plugin-yyds.js b/plugins/plugin-yyds.js new file mode 100644 index 0000000..a5b3c08 --- /dev/null +++ b/plugins/plugin-yyds.js @@ -0,0 +1,37 @@ +"use strict" +const { getPermission } = require("../lib/permission"); +const axios = require("axios"); + +async function noAbbreviated(_bot, data, args = null) { + if (!await getPermission(data, "noAbbreviated")) return; + let texts = data.message.filter(msg => msg.type === 'text'); + let textList = []; + const reg = /[a-zA-Z]+/ig; + texts.forEach(text => { + let temp = Array(text?.data?.text.match(reg)); + if (temp[0] !== null) { + temp[0].forEach(e => { + textList.push(e); + }); + } + }); + if (textList.length === 0) return; + let fullText = await getFullText(textList.join(" ")); + fullText = fullText.filter(e => typeof e?.trans !== "undefined"); + let msg = []; + fullText.forEach(tran => { + msg.push(tran?.trans[0]); + }) + data.reply(msg.join("\n")); + +} +exports.noAbbreviated = noAbbreviated; + +const getFullText = async (text) => { + try { + let res = await axios.post('https://lab.magiconch.com/api/nbnhhsh/guess', { text: text }); + return res?.data; + } catch (error) { + console.error(error) + } +} \ No newline at end of file