首次提交头衔屏蔽词

This commit is contained in:
yeyang
2022-11-17 22:33:02 +08:00
parent 21cb7e4a39
commit 72cc205096
5 changed files with 99 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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("✅ 已修改匹配模式为模糊匹配")
}
}
}
//随机底图

View File

@@ -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")

View File

@@ -0,0 +1,8 @@
#匹配模式 1为模糊 0为精确
Match_pattern: 0
#屏蔽词
Shielding_words:
-
- 不要啊
- 你干嘛
- 椰羊

View File

@@ -0,0 +1,5 @@
#匹配模式 1为模糊 0为精确
Match_pattern: 1
#屏蔽词
Shielding_words:
-