✨ 群头衔匹配词分开群单独,需要重新配置
This commit is contained in:
@@ -20,6 +20,6 @@ module.exports = {
|
||||
'prefer-const': ['off'],
|
||||
'arrow-body-style': 'off',
|
||||
'camelcase': 'off',
|
||||
'quote-props': ['error', 'consistent-as-needed']
|
||||
'quote-props': ['error', 'consistent']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,16 +91,6 @@ export class Admin extends plugin {
|
||||
reg: '^#椰奶(启用|禁用)全部通知$',
|
||||
fnc: 'SetAllNotice',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#(增加|减少|查看)头衔屏蔽词.*$',
|
||||
fnc: 'ProhibitedTitle',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#切换头衔屏蔽词匹配(模式)?$',
|
||||
fnc: 'ProhibitedTitlePattern',
|
||||
permission: 'master'
|
||||
}
|
||||
]
|
||||
})
|
||||
@@ -218,71 +208,6 @@ export class Admin extends plugin {
|
||||
scale: 1.4
|
||||
})
|
||||
}
|
||||
|
||||
// 增删查头衔屏蔽词
|
||||
async ProhibitedTitle (e) {
|
||||
// 获取现有的头衔屏蔽词
|
||||
let shieldingWords = Config.groupTitle.Shielding_words
|
||||
// 判断是否需要查看头衔屏蔽词
|
||||
if (/查看/.test(e.msg)) {
|
||||
// 返回已有的头衔屏蔽词列表
|
||||
return e.reply(`现有的头衔屏蔽词如下:${shieldingWords.join('\n')}`)
|
||||
}
|
||||
|
||||
// 获取用户输入的要增加或删除的屏蔽词
|
||||
let message = e.msg.replace(/#|(增加|减少)头衔屏蔽词/g, '').trim().split(',')
|
||||
// 判断用户是要增加还是删除屏蔽词
|
||||
let isAddition = /增加/.test(e.msg)
|
||||
let existingWords = []
|
||||
let newWords = []
|
||||
|
||||
// 遍历用户输入的屏蔽词,区分已有和新的屏蔽词
|
||||
for (let word of message) {
|
||||
if (shieldingWords.includes(word)) {
|
||||
existingWords.push(word)
|
||||
} else {
|
||||
newWords.push(word)
|
||||
}
|
||||
}
|
||||
|
||||
// 去重
|
||||
existingWords = _.compact(_.uniq(existingWords))
|
||||
newWords = _.compact(_.uniq(newWords))
|
||||
|
||||
// 判断是要增加还是删除屏蔽词
|
||||
if (isAddition) {
|
||||
// 添加新的屏蔽词
|
||||
if (!_.isEmpty(newWords)) {
|
||||
for (let word of newWords) {
|
||||
Config.modifyarr('groupTitle', 'Shielding_words', word, 'add')
|
||||
}
|
||||
e.reply(`✅ 成功添加:${newWords.join(',')}`)
|
||||
}
|
||||
// 提示已有的屏蔽词
|
||||
if (!_.isEmpty(existingWords)) {
|
||||
e.reply(`❎ 以下词已存在:${existingWords.join(',')}`)
|
||||
}
|
||||
} else {
|
||||
// 删除已有的屏蔽词
|
||||
if (!_.isEmpty(existingWords)) {
|
||||
for (let word of existingWords) {
|
||||
Config.modifyarr('groupTitle', 'Shielding_words', word, 'del')
|
||||
}
|
||||
e.reply(`✅ 成功删除:${existingWords.join(',')}`)
|
||||
}
|
||||
// 提示不在屏蔽词中的词
|
||||
if (!_.isEmpty(newWords)) {
|
||||
e.reply(`❎ 以下词未在屏蔽词中:${newWords.join(',')}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 修改头衔匹配模式
|
||||
async ProhibitedTitlePattern (e) {
|
||||
let data = Config.groupTitle.Match_pattern ? 0 : 1
|
||||
Config.modify('groupTitle', 'Match_pattern', data)
|
||||
e.reply(`✅ 已修改匹配模式为${data ? '精确' : '模糊'}匹配`)
|
||||
}
|
||||
}
|
||||
|
||||
// 随机底图
|
||||
|
||||
@@ -2,7 +2,7 @@ import _ from 'lodash'
|
||||
import moment from 'moment'
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { Config } from '../components/index.js'
|
||||
import { common, GroupAdmin as Ga, puppeteer, QQApi } from '../model/index.js'
|
||||
import { common, GroupAdmin as Ga, puppeteer, QQApi, GroupBannedWords } from '../model/index.js'
|
||||
import cronValidate from '../tools/cronValidate.js'
|
||||
import { groupTitleMsg } from '../constants/msg.js'
|
||||
import { Time_unit } from '../constants/other.js'
|
||||
@@ -306,15 +306,15 @@ export class GroupAdmin extends plugin {
|
||||
|
||||
let Title = e.msg.replace(/#|申请头衔/g, '')
|
||||
// 屏蔽词处理
|
||||
let { Match_pattern, Shielding_words } = Config.groupTitle
|
||||
|
||||
Shielding_words = _.compact(Shielding_words)
|
||||
if (!e.isMaster && !_.isEmpty(Shielding_words)) {
|
||||
if (Match_pattern) {
|
||||
let reg = new RegExp(Shielding_words.join('|'))
|
||||
let TitleFilterModeChange = GroupBannedWords.getTitleFilterModeChange(e.group_id)
|
||||
let TitleBannedWords = GroupBannedWords.getTitleBannedWords(e.group_id)
|
||||
TitleBannedWords = _.compact(TitleBannedWords)
|
||||
if (!e.isMaster && !_.isEmpty(TitleBannedWords)) {
|
||||
if (TitleFilterModeChange) {
|
||||
let reg = new RegExp(TitleBannedWords.join('|'))
|
||||
if (reg.test(Title)) return e.reply('这里面有不好的词汇哦~', true)
|
||||
} else {
|
||||
if (Shielding_words.includes(Title)) return e.reply('这是有不好的词汇哦~', true)
|
||||
if (TitleBannedWords.includes(Title)) return e.reply('这是有不好的词汇哦~', true)
|
||||
}
|
||||
}
|
||||
let res = await e.group.setTitle(e.user_id, Title)
|
||||
|
||||
@@ -32,6 +32,14 @@ export class NewGroupBannedWords extends plugin {
|
||||
{
|
||||
reg: '^#?设置违禁词禁言时间(\\d+)$',
|
||||
fnc: 'muteTime'
|
||||
},
|
||||
{
|
||||
reg: '^#(增加|减少|查看)头衔屏蔽词.*$',
|
||||
fnc: 'ProhibitedTitle'
|
||||
},
|
||||
{
|
||||
reg: '^#切换头衔屏蔽词匹配(模式)?$',
|
||||
fnc: 'ProhibitedTitlePattern'
|
||||
}
|
||||
]
|
||||
|
||||
@@ -46,36 +54,40 @@ export class NewGroupBannedWords extends plugin {
|
||||
if (_.isEmpty(groupBannedWords)) {
|
||||
return false
|
||||
}
|
||||
let keyWord = e.toString()
|
||||
const KeyWord = e.toString()
|
||||
.replace(/#|#/g, '')
|
||||
.replace(`{at:${Bot.uin}}`, '')
|
||||
.trim()
|
||||
keyWord = this.trimAlias(keyWord)
|
||||
const word = _.find(Object.keys(groupBannedWords), wrd => _.includes(keyWord, wrd))
|
||||
if (!word) return false
|
||||
const trimmedKeyWord = this.trimAlias(KeyWord)
|
||||
const matchingWord = Object.keys(groupBannedWords).find((word) =>
|
||||
_.includes(trimmedKeyWord, word)
|
||||
)
|
||||
if (!matchingWord) return false
|
||||
|
||||
const type = groupBannedWords[word]
|
||||
const isAccurateModeOK = type.matchType == 1 && keyWord === word
|
||||
const isVagueModeOK = type.matchType == 2 && _.includes(keyWord, word)
|
||||
const type = groupBannedWords[matchingWord]
|
||||
const isAccurateModeOK = type.matchType == 1 && trimmedKeyWord === matchingWord
|
||||
const isVagueModeOK = type.matchType == 2 && _.includes(trimmedKeyWord, matchingWord)
|
||||
const isOK = isAccurateModeOK || isVagueModeOK
|
||||
const punishments = {
|
||||
1: async () => await e.member.kick(),
|
||||
2: async () => await e.member.mute(GroupBannedWords.getMuteTime(e.group_id)),
|
||||
3: async () => await e.recall(),
|
||||
4: async () => {
|
||||
'1': async () => await e.member.kick(),
|
||||
'2': async () => await e.member.mute(GroupBannedWords.getMuteTime(e.group_id)),
|
||||
'3': async () => await e.recall(),
|
||||
'4': async () => {
|
||||
await e.member.kick()
|
||||
await e.recall()
|
||||
},
|
||||
5: async () => {
|
||||
'5': async () => {
|
||||
await e.member.mute(GroupBannedWords.getMuteTime(e.group_id))
|
||||
await e.recall()
|
||||
}
|
||||
}
|
||||
if (isOK && punishments[type.penaltyType]) {
|
||||
await punishments[type.penaltyType]()
|
||||
const keyWordTran = await GroupBannedWords.keyWordTran(matchingWord)
|
||||
const senderCard = e.sender.card || e.sender.nickname
|
||||
e.reply([
|
||||
`触发违禁词:${await GroupBannedWords.keyWordTran(word)}\n`,
|
||||
`触发者:${e.sender.card || e.sender.nickname}(${e.user_id})\n`,
|
||||
`触发违禁词:${keyWordTran}\n`,
|
||||
`触发者:${senderCard}(${e.user_id})\n`,
|
||||
`执行:${GroupBannedWords.penaltyTypeMap[type.penaltyType]}`
|
||||
])
|
||||
}
|
||||
@@ -169,4 +181,65 @@ export class NewGroupBannedWords extends plugin {
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
// 增删查头衔屏蔽词
|
||||
async ProhibitedTitle (e) {
|
||||
// 获取现有的头衔屏蔽词
|
||||
let shieldingWords = GroupBannedWords.getTitleBannedWords(e.group_id)
|
||||
// 判断是否需要查看头衔屏蔽词
|
||||
if (/查看/.test(e.msg)) {
|
||||
// 返回已有的头衔屏蔽词列表
|
||||
return e.reply(`现有的头衔屏蔽词如下:${shieldingWords.join('\n')}`)
|
||||
}
|
||||
|
||||
// 获取用户输入的要增加或删除的屏蔽词
|
||||
let message = e.msg.replace(/#|(增加|减少)头衔屏蔽词/g, '').trim().split(',')
|
||||
// 判断用户是要增加还是删除屏蔽词
|
||||
let isAddition = /增加/.test(e.msg)
|
||||
let existingWords = []
|
||||
let newWords = []
|
||||
|
||||
// 遍历用户输入的屏蔽词,区分已有和新的屏蔽词
|
||||
for (let word of message) {
|
||||
if (shieldingWords.includes(word)) {
|
||||
existingWords.push(word)
|
||||
} else {
|
||||
newWords.push(word)
|
||||
}
|
||||
}
|
||||
|
||||
// 去重
|
||||
existingWords = _.compact(_.uniq(existingWords))
|
||||
newWords = _.compact(_.uniq(newWords))
|
||||
|
||||
// 判断是要增加还是删除屏蔽词
|
||||
if (isAddition) {
|
||||
// 添加新的屏蔽词
|
||||
if (!_.isEmpty(newWords)) {
|
||||
GroupBannedWords.addTitleBannedWords(e.group_id, newWords)
|
||||
e.reply(`✅ 成功添加:${newWords.join(',')}`)
|
||||
}
|
||||
// 提示已有的屏蔽词
|
||||
if (!_.isEmpty(existingWords)) {
|
||||
e.reply(`❎ 以下词已存在:${existingWords.join(',')}`)
|
||||
}
|
||||
} else {
|
||||
// 删除已有的屏蔽词
|
||||
if (!_.isEmpty(existingWords)) {
|
||||
GroupBannedWords.delTitleBannedWords(e.group_id, existingWords)
|
||||
e.reply(`✅ 成功删除:${existingWords.join(',')}`)
|
||||
}
|
||||
// 提示不在屏蔽词中的词
|
||||
if (!_.isEmpty(newWords)) {
|
||||
e.reply(`❎ 以下词未在屏蔽词中:${newWords.join(',')}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 修改头衔匹配模式
|
||||
async ProhibitedTitlePattern (e) {
|
||||
if (!common.Authentication(e, 'admin', 'admin')) return false
|
||||
let res = GroupBannedWords.setTitleFilterModeChange(e.group_id)
|
||||
e.reply(`✅ 已修改匹配模式为${res ? '精确' : '模糊'}匹配`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
#匹配模式 1为模糊 0为精确
|
||||
Match_pattern: 1
|
||||
#屏蔽词
|
||||
Shielding_words:
|
||||
-
|
||||
@@ -245,8 +245,8 @@ export const helpList = [{
|
||||
group: '违禁词',
|
||||
list: [
|
||||
{
|
||||
title: '#新增(模糊|精确)?(踢|禁|撤|踢撤|禁撤)?违禁词.*',
|
||||
desc: '前面为匹配模式后面为惩罚',
|
||||
title: '#新增(模糊|精确)?<惩罚>?违禁词.*',
|
||||
desc: '惩罚包括踢、禁、撤、踢撤、禁撤',
|
||||
icon: 7
|
||||
},
|
||||
{
|
||||
|
||||
@@ -17,6 +17,7 @@ export default new class {
|
||||
}
|
||||
this.dataCach = {}
|
||||
this.muteTimeCach = {}
|
||||
this.groupTitleCach = {}
|
||||
}
|
||||
|
||||
addBannedWords (
|
||||
@@ -124,4 +125,38 @@ export default new class {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
setTitleFilterModeChange (groupId) {
|
||||
let data = Data.readJSON(`${groupId}.json`, this.root)
|
||||
data.TitleFilterModeChange = data.TitleFilterModeChange ? 0 : 1
|
||||
Data.writeJSON(`${groupId}.json`, data, this.root)
|
||||
return data.TitleFilterModeChange
|
||||
}
|
||||
|
||||
getTitleFilterModeChange (groupId) {
|
||||
let data = Data.readJSON(`${groupId}.json`, this.root)
|
||||
return data.TitleFilterModeChange ?? 0
|
||||
}
|
||||
|
||||
addTitleBannedWords (groupId, arr) {
|
||||
let data = Data.readJSON(`${groupId}.json`, this.root)
|
||||
if (!data.TitleBannedWords)data.TitleBannedWords = []
|
||||
data.TitleBannedWords.push(...arr)
|
||||
Data.writeJSON(`${groupId}.json`, data, this.root)
|
||||
delete this.groupTitleCach[groupId]
|
||||
}
|
||||
|
||||
getTitleBannedWords (groupId) {
|
||||
if (this.groupTitleCach[groupId]) return this.groupTitleCach[groupId]
|
||||
let data = Data.readJSON(`${groupId}.json`, this.root).TitleBannedWords ?? []
|
||||
this.groupTitleCach[groupId] = data
|
||||
return data
|
||||
}
|
||||
|
||||
delTitleBannedWords (groupId, arr) {
|
||||
let data = Data.readJSON(`${groupId}.json`, this.root)
|
||||
data.TitleBannedWords = _.differenceBy(data.TitleBannedWords, arr)
|
||||
Data.writeJSON(`${groupId}.json`, data, this.root)
|
||||
delete this.groupTitleCach[groupId]
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user