Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirius0v0 committed Sep 14, 2021
2 parents 6410965 + bfc1cb2 commit 382e29e
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 8 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"
]
}
}
}
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"); // 退群
Expand Down Expand Up @@ -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;
}
})
Expand Down
12 changes: 10 additions & 2 deletions 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
5 changes: 3 additions & 2 deletions plugins/mcbot/mcHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
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;
}
37 changes: 37 additions & 0 deletions plugins/plugin-yyds.js
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit 382e29e

Please sign in to comment.