From 72cc205096f4b3254ec089780de3d7debc701e92 Mon Sep 17 00:00:00 2001 From: yeyang <746659424@qq.com> Date: Thu, 17 Nov 2022 22:33:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E6=AC=A1=E6=8F=90=E4=BA=A4=E5=A4=B4?= =?UTF-8?q?=E8=A1=94=E5=B1=8F=E8=94=BD=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/gp_admin.js | 12 +++- apps/set.js | 65 +++++++++++++++++++++- components/Config.js | 13 ++++- config/config/Shielding_words.yaml | 8 +++ config/default_config/Shielding_words.yaml | 5 ++ 5 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 config/config/Shielding_words.yaml create mode 100644 config/default_config/Shielding_words.yaml diff --git a/apps/gp_admin.js b/apps/gp_admin.js index d95f9bb..36e7c5b 100644 --- a/apps/gp_admin.js +++ b/apps/gp_admin.js @@ -2,6 +2,7 @@ import plugin from '../../../lib/plugins/plugin.js' import fetch from 'node-fetch' import { segment } from 'oicq' import lodash from 'lodash' +import { Config } from '../components/index.js' import { Cfg, Gpadmin, common } from '../model/index.js' const ROLE_MAP = { admin: '群管理', @@ -481,7 +482,16 @@ export class Basics extends plugin { if (!e.group.is_owner) return e.reply("做不到,怎么想我都做不到吧ヽ(≧Д≦)ノ", true) let Title = e.msg.replace(/#|申请头衔/g, "") - + //屏蔽词处理 + if (!e.isMaster) { + let data = Config.NoTitle + if (data.Match_pattern) { + let reg = new RegExp(lodash.compact(data.Shielding_words).join("|")) + if (reg.test(Title)) return e.reply("这里面有不好的词汇哦~", true) + } else { + if (data.Shielding_words.includes(Title)) return e.reply("这是有不好的词汇哦~", true) + } + } let res = await e.group.setTitle(e.user_id, Title) if (res) { if (!Title) { diff --git a/apps/set.js b/apps/set.js index 9c97b81..680f92c 100644 --- a/apps/set.js +++ b/apps/set.js @@ -2,7 +2,7 @@ import plugin from '../../../lib/plugins/plugin.js' import fs from "fs"; import lodash from "lodash"; import { Config, render } from '../components/index.js' - +import { YamlReader } from '../model/index.js'; const configs = { "好友消息": "privateMessage", "群消息": "groupMessage", @@ -61,9 +61,18 @@ export class NewConfig extends plugin { { reg: '^#(开启|关闭)陌生人点赞$', fnc: 'Stranger_zan' + }, + { + reg: '^#(增加|减少|查看)头衔屏蔽词.*$', + fnc: 'NoTitle' + }, + { + reg: '^#切换头衔屏蔽词匹配(模式)?$', + fnc: 'NoTitlepattern' } ] }) + this.NoTitlepath = './plugins/yenai-plugin/config/config/Shielding_words.yaml' } //初始化 @@ -214,6 +223,60 @@ export class NewConfig extends plugin { e.reply("✅ 已关闭陌生人点赞") } } + //增删查头衔屏蔽词 + async NoTitle(e) { + let getdata = new YamlReader(this.NoTitlepath) + let data = getdata.jsonData.Shielding_words + if (/查看/.test(e.msg)) { + return e.reply(`现有的头衔屏蔽词如下:${data.join("\n")}`) + } + let msg = e.msg.replace(/#|(增加|减少)头衔屏蔽词/g, "").trim().split(",") + let type = /增加/.test(e.msg) ? true : false + let no = [], yes = [] + for (let i of msg) { + if (data.includes(i)) { + no.push(i) + } else { + yes.push(i) + } + } + no = lodash.compact(lodash.uniq(no)) + yes = lodash.compact(lodash.uniq(yes)) + if (type) { + if (!lodash.isEmpty(yes)) { + for (let i of yes) { + getdata.addIn("Shielding_words", i) + } + e.reply(`✅ 成功添加:${yes.join(",")}`) + } + if (!lodash.isEmpty(no)) { + e.reply(`❎ 以下词已存在:${no.join(",")}`) + } + } else { + if (!lodash.isEmpty(no)) { + for (let i of no) { + let index = data.indexOf(i) + getdata.delete("Shielding_words." + index) + } + e.reply(`✅ 成功删除:${no.join(",")}`) + } + if (!lodash.isEmpty(yes)) { + e.reply(`❎ 以下词未在屏蔽词中:${yes.join(",")}`) + } + } + } + //修改匹配模式 + async NoTitlepattern(e) { + let getdata = new YamlReader(this.NoTitlepath) + let data = getdata.jsonData.Match_pattern + if (data) { + getdata.set("Match_pattern", 0) + e.reply("✅ 已修改匹配模式为精确匹配") + } else { + getdata.set("Match_pattern", 1) + e.reply("✅ 已修改匹配模式为模糊匹配") + } + } } //随机底图 diff --git a/components/Config.js b/components/Config.js index cf9a9c4..d183311 100644 --- a/components/Config.js +++ b/components/Config.js @@ -47,8 +47,17 @@ class Config { get verifycfg() { return this.getverifycfg(); } - - + //头衔屏蔽词 + get NoTitle() { + return this.getNoTitle(); + } + //头衔屏蔽词 + getNoTitle() { + let config = this.getConfig("Shielding_words") + let def = this.getdefSet("Shielding_words") + return { ...def, ...config } + } + //进群验证 getverifycfg() { let config = this.getConfig("groupverify") let def = this.getdefSet("groupverify") diff --git a/config/config/Shielding_words.yaml b/config/config/Shielding_words.yaml new file mode 100644 index 0000000..8b77abc --- /dev/null +++ b/config/config/Shielding_words.yaml @@ -0,0 +1,8 @@ +#匹配模式 1为模糊 0为精确 +Match_pattern: 0 +#屏蔽词 +Shielding_words: + - + - 不要啊 + - 你干嘛 + - 椰羊 diff --git a/config/default_config/Shielding_words.yaml b/config/default_config/Shielding_words.yaml new file mode 100644 index 0000000..621b7d0 --- /dev/null +++ b/config/default_config/Shielding_words.yaml @@ -0,0 +1,5 @@ +#匹配模式 1为模糊 0为精确 +Match_pattern: 1 +#屏蔽词 +Shielding_words: + - \ No newline at end of file