Skip to content

Commit

Permalink
添加随机复读工功能
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirius0v0 committed Sep 14, 2021
1 parent c4e96df commit bfc1cb2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
18 changes: 18 additions & 0 deletions config-template/permission-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,24 @@
"admin",
"owner"
]
},
"_repeater": {
"activation": true,
"help": null,
"isadmin": [
"member",
"admin",
"owner"
]
},
"_noAbbreviated": {
"activation": true,
"help": null,
"isadmin": [
"member",
"admin",
"owner"
]
}
}
}
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ 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 { repeater } = require("./plugins/plugin-repeater"); // 复读
const { noAbbreviated } = require("./plugins/plugin-yyds"); // 好好说话
// 通知类插件
const { increase } = require("./plugins/plugin-increase"); // 入群欢迎
const { decrease } = require("./plugins/plugin-decrease"); // 退群
Expand Down Expand Up @@ -113,8 +115,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;
}
})
Expand Down
10 changes: 9 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"account": 123456789,
"botNickname": "灵喵",
"owner": 123456789,
"version": "2.1.0",
"version": "2.1.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
37 changes: 37 additions & 0 deletions plugins/plugin-repeater.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit bfc1cb2

Please sign in to comment.