From bbad0c7622c859e65df74fc3ddba528db2283ae3 Mon Sep 17 00:00:00 2001 From: yeyang <746659424@qq.com> Date: Fri, 7 Apr 2023 14:52:08 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=97=EF=B8=8F=20add?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/groupBannedWords.js | 41 +++++++++++++++++++++++++++++++++++++++ config/group/.gitignore | 1 + lib/common/common.js | 4 +++- model/GroupBannedWords.JS | 17 ++++++++++++++++ model/index.js | 2 ++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 apps/groupBannedWords.js create mode 100644 config/group/.gitignore create mode 100644 model/GroupBannedWords.JS diff --git a/apps/groupBannedWords.js b/apps/groupBannedWords.js new file mode 100644 index 0000000..a80011a --- /dev/null +++ b/apps/groupBannedWords.js @@ -0,0 +1,41 @@ +import { common, GroupBannedWords } from '../model/index.js' + +export class NewGroupBannedWords extends plugin { + constructor () { + super({ + name: '椰奶群屏蔽词', + event: 'message.group', + priority: 500, + rule: [ + { + reg: '^#?新增屏蔽词.*$', + fnc: 'add' + }, + { + reg: '^#?删除屏蔽词.*$', + fnc: 'del' + }, + { + reg: '^#?查看屏蔽词.*$', + fnc: 'query' + } + ] + + }) + } + + async add (e) { + if (!common.Authentication(e, 'admin', 'admin')) return false + let words = e.msg.replace(/#?新增屏蔽词/, '')?.split(',') + if (!words) return e.reply('需要添加的屏蔽词为空') + GroupBannedWords.addBannedWords(e.group_id, words) + } + + async del (e) { + + } + + async query (e) { + + } +} diff --git a/config/group/.gitignore b/config/group/.gitignore new file mode 100644 index 0000000..94a2dd1 --- /dev/null +++ b/config/group/.gitignore @@ -0,0 +1 @@ +*.json \ No newline at end of file diff --git a/lib/common/common.js b/lib/common/common.js index 8f32ce9..fbf712c 100644 --- a/lib/common/common.js +++ b/lib/common/common.js @@ -84,7 +84,9 @@ export default new class newCommon { * @param {Array} message - 发送的消息数组,数组每一项为转发消息的一条消息 * @param {Object} [options] - 发送消息的配置项 * @param {Number} [options.recallMsg=0] - 撤回时间,单位秒,默认为0表示不撤回 - * @param {{nickname:string,user_id:number}} [options.info] - 转发发送人信息 + * @param {object} [options.info] - 转发发送人信息 + * @param {string} options.info.nickname - 转发人昵称 + * @param {number} options.info.user_id - 转发人QQ * @param {string|array} [options.fkmsg] - 风控消息,不传则默认消息 * @param {Boolean} [options.isxml] - 是否处理卡片,若为true则处理卡片 * @param {Boolean} [options.isxmlMsg] - 处理卡片显示的消息 diff --git a/model/GroupBannedWords.JS b/model/GroupBannedWords.JS new file mode 100644 index 0000000..3b3a58b --- /dev/null +++ b/model/GroupBannedWords.JS @@ -0,0 +1,17 @@ +import { Data, Plugin_Path } from '../components/index.js' +import _ from 'lodash' +export default new class { + constructor () { + this.root = `${Plugin_Path}/config/group` + } + + addBannedWords (groupId, words) { + let data = Data.readJSON(`${groupId}.json`, this.root) + if (!data.bannedWords)data.bannedWords = [] + if (Array.isArray(words)) words = [words] + let uniqWords = _.uniq(words) + data.bannedWords.push(...words) + Data.writeJSON(`${groupId}.json`, data, this.root) + return uniqWords + } +}() diff --git a/model/index.js b/model/index.js index 6e49a8c..445dfab 100644 --- a/model/index.js +++ b/model/index.js @@ -12,6 +12,7 @@ import Ascii2D from './PicSearch/ascii2d.js' import SauceNAO from './PicSearch/saucenao.js' import WhatAnime from './PicSearch/whatanime.js' import listener from './listener/loader.js' +import GroupBannedWords from './GroupBannedWords.js' // 加载监听事件 listener.load() // 导出模块 @@ -29,6 +30,7 @@ export { Bika, uploadRecord, GroupAdmin, + GroupBannedWords, QQApi, funApi }