-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
72 changed files
with
829 additions
and
678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
{ | ||
"corei18n.template.args_error": "参数 “{0}” 的类型错误,期望类型:{1} 实际类型:{2}", | ||
"corei18n.template.args_few": "输入参数过少请增加参数,期望数量:{0} 实际数量:{1}", | ||
"corei18n.template.args_many": "输入参数过多请减少参数,期望数量:{0} 实际数量:{1}", | ||
"corei18n.template.option_error": "选项 “{0}” 的类型错误,期望类型:{1} 实际类型:{2}", | ||
"corei18n.template.syntax": "指令语法错误,意外地在 {0} 处字符 “{1}”", | ||
"corei18n.template.unknown": "未知的指令 “{0}” ,请检查指令是否输入正确", | ||
"corei18n.template.error": "意外的错误!\n捕获信息:{0}", | ||
"corei18n.template.res_error": "响应数据格式错误!\n错误信息:{0}", | ||
"corei18n.template.num_error": "序号错误,请重新发送", | ||
"corei18n.template.exists": "目标参数“{0}”已存在,请勿重复执行", | ||
"corei18n.template.no_exists": "目标参数“{0}”不存在,请确认后,重新发送", | ||
"corei18n.template.data_error.args": "参数 “{0}” 传入数据错误", | ||
"corei18n.template.data_error.options": "选项 “{0}” 传入数据错误", | ||
"corei18n.template.scope": "该指令仅群聊或私聊下可使用!", | ||
"corei18n.template.no_access_manger": "该指令仅群管理员与群BOT管理员可使用!", | ||
"corei18n.template.no_access_admin": "该指令仅BOT最高管理员可使用!", | ||
"corei18n.template.empty": "无", | ||
"corei18n.template.unsupported": "当前平台不支持该消息元素", | ||
"corei18n.template.": "当前平台不支持该消息元素", | ||
"corei18n.template.prompt": "请输入一个值:", | ||
"corei18n.template.confirm": "是否确认?(是/否)", | ||
"corei18n.template.confirm.sure": "是", | ||
"core.descr.core": "查看实例统计信息", | ||
"core.descr.bot": "查看当前 bot 信息与运行状态", | ||
"core.descr.bots": "查看所有 bot 信息与运行状态", | ||
"core.descr.about": "查看关于信息", | ||
"core.descr.locale": "设置显示语言", | ||
"core.descr.module": "查看模块", | ||
"core.msg.bot": "ID:%identity%\n语言:%lang%\n平台:%platform%\nid:%self_id%\n连接时间:%create_time%\n接收消息数量:%received_msg%\n发送消息数量:%sent_msg%\n实例下线次数:%offline_times%\n最后消息时间:%last_msg_time%", | ||
"core.msg.core": "全局语言:%lang%\n实例目录:%root%\n运行模式:%mode%\n模块数量:%modules%\n服务数量:%services%\nbot 实例数量:%bots%\n中间件数量:%midwares%\n指令数量:%commands%\n正则数量:%regexps%", | ||
"core.msg.bots": "实例列表:%list%", | ||
"core.msg.bots.list": "\n----------\nID:%identity%\n语言:%lang%\n平台:%platform%\n状态:%status%", | ||
"core.msg.about": "Kotori 版本:%version%\n协议:%license%\nNodeJS 版本:%node_version%" | ||
} | ||
"core.msg.about": "Kotori 版本:%version%\n协议:%license%\nNodeJS 版本:%node_version%", | ||
"core.msg.locale": "成功将当前实例显示语言设置为:%lang%", | ||
"core.msg.locale.global": "成功将全局显示语言设置为:%lang%", | ||
"core.msg.locale.invalid": "参数无效,必须是以下中的一个值:en_US、ja_JP、zh_CN、zh_TW", | ||
"core.msg.module": "模块列表:%list%", | ||
"core.msg.module.list": "\n----------\n名称:%name%\n描述:%description%\n版本:%version%" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
{ | ||
"corei18n.template.args_error": "參數 “{0}” 的類型錯誤,期望類型:{1} 實際類型:{2}", | ||
"corei18n.template.args_few": "輸入參數過少請增加參數,期望數量:{0} 實際數量:{1}", | ||
"corei18n.template.args_many": "輸入參數過多請減少參數,期望數量:{0} 實際數量:{1}", | ||
"corei18n.template.option_error": "選項 “{0}” 的類型錯誤,期望類型:{1} 實際類型:{2}", | ||
"corei18n.template.syntax": "指令語法錯誤,意外地在 {0} 處字符 “{1}”", | ||
"corei18n.template.unknown": "未知的指令 “{0}” ,請檢查指令是否輸入正確", | ||
"corei18n.template.error": "意外的錯誤!\n捕獲信息:{0}", | ||
"corei18n.template.res_error": "響應數據格式錯誤!\n錯誤信息:{0}", | ||
"corei18n.template.num_error": "序號錯誤,請重新發送", | ||
"corei18n.template.exists": "目標參數“{0}”已存在,請勿重複執行", | ||
"corei18n.template.no_exists": "目標參數“{0}”不存在,請確認後,重新發送", | ||
"corei18n.template.data_error.args": "參數 “{0}” 傳入數據錯誤", | ||
"corei18n.template.data_error.options": "選項 “{0}” 傳入數據錯誤", | ||
"corei18n.template.scope": "該指令僅群聊或私聊下可使用!", | ||
"corei18n.template.no_access_manger": "該指令僅群管理員與群BOT管理員可使用!", | ||
"corei18n.template.no_access_admin": "該指令僅BOT最高管理員可使用!", | ||
"corei18n.template.empty": "無", | ||
"corei18n.template.unsupported": "當前平台不支持該消息元素", | ||
"corei18n.template.": "當前平台不支持該消息元素", | ||
"corei18n.template.prompt": "請輸入壹個值:", | ||
"corei18n.template.confirm": "是否確認?(是/否)", | ||
"corei18n.template.confirm.sure": "是", | ||
"core.descr.core": "查看實例統計信息", | ||
"core.descr.bot": "查看當前 bot 信息與運行狀態", | ||
"core.descr.bots": "查看所有 bot 信息與運行狀態", | ||
"core.descr.about": "查看關于信息", | ||
"core.descr.locale": "設置顯示語言", | ||
"core.descr.module": "查看模塊", | ||
"core.msg.bot": "ID:%identity%\n語言:%lang%\n平台:%platform%\nid:%self_id%\n連接時間:%create_time%\n接收消息數量:%received_msg%\n發送消息數量:%sent_msg%\n實例下線次數:%offline_times%\n最後消息時間:%last_msg_time%", | ||
"core.msg.core": "全局語言:%lang%\n實例目錄:%root%\n運行模式:%mode%\n模塊數量:%modules%\n服務數量:%services%\nbot 實例數量:%bots%\n中間件數量:%midwares%\n指令數量:%commands%\n正則數量:%regexps%", | ||
"core.msg.bots": "實例列表:%list%", | ||
"core.msg.bots.list": "\n----------\nID:%identity%\n語言:%lang%\n平台:%platform%\n狀態:%status%", | ||
"core.msg.about": "Kotori 版本:%version%\n協議:%license%\nNodeJS 版本:%node_version%" | ||
} | ||
"core.msg.about": "Kotori 版本:%version%\n協議:%license%\nNodeJS 版本:%node_version%", | ||
"core.msg.locale": "成功將當前實例顯示語言設置爲:%lang%", | ||
"core.msg.locale.global": "成功將全局顯示語言設置爲:%lang%", | ||
"core.msg.locale.invalid": "參數無效,必須是以下中的壹個值:en_US、ja_JP、zh_CN、zh_TW", | ||
"core.msg.module": "模塊列表:%list%", | ||
"core.msg.module.list": "\n----------\n名稱:%name%\n描述:%description%\n版本:%version%" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# kotori-plugin-filter | ||
# @kotori-bot/kotori-plugin-filter | ||
|
||
filter plugin for kotori-bot loader | ||
|
||
## Reference | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,40 @@ | ||
import { Tsu, Context, plugins, Symbols } from 'kotori-bot'; | ||
import { Tsu, Context, plugins, Symbols, CORE_MODULES, KotoriPlugin } from 'kotori-bot'; | ||
import pm from 'picomatch'; | ||
|
||
type ModuleMap = [{ pkg: string }, object]; | ||
|
||
const plugin = plugins([__dirname, '../']); | ||
|
||
@plugin.import | ||
export default class Plugin { | ||
private ctx: Context; | ||
|
||
private config: Tsu.infer<typeof Plugin.schema>; | ||
|
||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */ | ||
class FilterPlugin extends KotoriPlugin<Tsu.infer<typeof FilterPlugin.schema>> { | ||
@plugin.schema | ||
public static schema = Tsu.Object({ | ||
mode: Tsu.Union([Tsu.Literal('include'), Tsu.Literal('exclude')]).default('exclude'), | ||
list: Tsu.Array(Tsu.String()).default([]) | ||
}); | ||
|
||
public constructor(ctx: Context, config: Tsu.infer<typeof Plugin.schema>) { | ||
this.ctx = ctx; | ||
this.config = config; | ||
public constructor(ctx: Context, config: Tsu.infer<typeof FilterPlugin.schema>) { | ||
super(ctx, config); | ||
this.loaderFilter(); | ||
} | ||
|
||
private loaderFilter() { | ||
const { mode, list } = this.config; | ||
const runner = this.ctx.get<{ [Symbols.modules]: Map<string, ModuleMap> }>('runner'); | ||
const runner = this.ctx.get<{ [Symbols.modules]: Map<string, [{ main?: string }, object]> }>('runner'); | ||
if (!runner) { | ||
this.ctx.logger.error('it is not loader environment nowadays'); | ||
return; | ||
} | ||
this.ctx.logger.record(`get loader successfully, filter mode: ${mode}`); | ||
runner[Symbols.modules].forEach((val, key) => { | ||
const value = [runner[Symbols.modules].get(key)]; | ||
if (CORE_MODULES.includes(key)) return; | ||
const [ModuleMeta] = val; | ||
const result = list.filter((pattern) => pm(pattern)(key).valueOf()).length > 0; | ||
if (result && (mode === 'exclude' || mode === undefined)) { | ||
delete value[0]; | ||
console.log(value[0], value[0] === val); | ||
} else if (!result && mode === 'include') { | ||
delete value[0]; | ||
if ((result && mode === 'exclude') || (!result && mode === 'include')) { | ||
runner[Symbols.modules].delete(key); | ||
delete ModuleMeta.main; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
// plugin.import(Plugin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.