koishi-plugin-teach
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -10,6 +10,6 @@ "use strict"; | ||
return []; | ||
const p = {}; | ||
for (const field of fields) | ||
p[field] = 1; | ||
const dialogues = await this.db.collection('dialogue').find({ _id: { $in: ids } }).project(p).toArray(); | ||
let cursor = this.db.collection('dialogue').find({ _id: { $in: ids } }); | ||
if (fields) | ||
cursor = cursor.project(Object.fromEntries(fields.map(k => [k, 1]))); | ||
const dialogues = await cursor.toArray(); | ||
dialogues.forEach(d => { | ||
@@ -16,0 +16,0 @@ d._id = d.id; |
@@ -23,2 +23,2 @@ import { Context } from 'koishi-core'; | ||
export declare const name = "teach"; | ||
export declare function apply(ctx: Context, config?: Dialogue.Config): void; | ||
export declare function apply(ctx: Context, config?: Config): void; |
@@ -58,3 +58,3 @@ "use strict"; | ||
__exportStar(require("./plugins/writer"), exports); | ||
const cheatSheet = (p, authority) => `\ | ||
const cheatSheet = (p, authority, config) => `\ | ||
教学系统基本用法: | ||
@@ -72,7 +72,7 @@ 添加问答:${p} 问题 回答 | ||
结果页码: / page | ||
禁用递归查询: -R${authority >= 3 ? ` | ||
正则+合并结果:${p}${p}${p}` : ''} | ||
禁用递归查询: -R${authority >= config.authority.regExp ? ` | ||
正则+合并结果:${p}${p}${p}` : ''}${config.useContext ? ` | ||
上下文选项: | ||
允许本群: -e | ||
禁止本群: -d${authority >= 3 ? ` | ||
禁止本群: -d` : ''}${config.useContext && authority >= config.authority.context ? ` | ||
全局允许: -E | ||
@@ -82,17 +82,15 @@ 全局禁止: -D | ||
无视上下文搜索:-G` : ''} | ||
问答选项:${authority >= 3 ? ` | ||
问答选项:${config.useWriter && authority >= config.authority.frozen ? ` | ||
锁定问答: -f/-F | ||
教学者代行: -s/-S` : ''} | ||
教学者代行: -s/-S` : ''}${config.useWriter && authority >= config.authority.writer ? ` | ||
设置问题作者: -w uid | ||
设置为匿名: -W | ||
设置为匿名: -W` : ''} | ||
忽略智能提示: -i | ||
重定向: => | ||
匹配规则:${authority >= 3 ? ` | ||
匹配规则:${authority >= config.authority.regExp ? ` | ||
正则表达式: -x/-X` : ''} | ||
严格匹配权重: -p prob | ||
称呼匹配权重: -P prob | ||
设置最小好感度:-a aff | ||
设置最大好感度:-A aff | ||
称呼匹配权重: -P prob${config.useTime ? ` | ||
设置起始时间: -t time | ||
设置结束时间: -T time | ||
设置结束时间: -T time` : ''} | ||
前置与后继: | ||
@@ -153,9 +151,24 @@ 设置前置问题: < id | ||
prefix: '#', | ||
authority: { | ||
base: 2, | ||
admin: 3, | ||
context: 3, | ||
frozen: 4, | ||
regExp: 3, | ||
writer: 2, | ||
}, | ||
}; | ||
function apply(ctx, config = {}) { | ||
config = { ...defaultConfig, ...config }; | ||
config = { | ||
...defaultConfig, | ||
...config, | ||
authority: { | ||
...defaultConfig.authority, | ||
...config.authority, | ||
}, | ||
}; | ||
registerPrefix(ctx, config.prefix); | ||
ctx.command('teach', '添加教学对话', { authority: 2, checkUnknown: true, hideOptions: true }) | ||
ctx.command('teach', '添加教学对话', { authority: config.authority.base, checkUnknown: true, hideOptions: true }) | ||
.userFields(['authority', 'id']) | ||
.usage(({ $user }) => cheatSheet(config.prefix, $user.authority)) | ||
.usage(({ $user }) => cheatSheet(config.prefix, $user.authority, config)) | ||
.action(async ({ options, session, args }) => { | ||
@@ -162,0 +175,0 @@ const argv = { app: ctx.app, session, args, config, options }; |
@@ -25,4 +25,4 @@ "use strict"; | ||
.option('ignoreHint', '-i 忽略智能提示') | ||
.option('regexp', '-x 使用正则表达式匹配', { authority: 3 }) | ||
.option('regexp', '-X 取消使用正则表达式匹配', { authority: 3, value: false }) | ||
.option('regexp', '-x 使用正则表达式匹配', { authority: config.authority.regExp }) | ||
.option('regexp', '-X 取消使用正则表达式匹配', { authority: config.authority.regExp, value: false }) | ||
.option('redirect', '=> <answer> 重定向到其他问答'); | ||
@@ -29,0 +29,0 @@ ctx.on('dialogue/validate', (argv) => { |
@@ -8,8 +8,9 @@ "use strict"; | ||
return; | ||
const authority = config.authority.context; | ||
ctx.command('teach') | ||
.option('disable', '-d 在当前环境下禁用问答') | ||
.option('disableGlobal', '-D 在所有环境下禁用问答', { authority: 3 }) | ||
.option('disableGlobal', '-D 在所有环境下禁用问答', { authority }) | ||
.option('enable', '-e 在当前环境下启用问答') | ||
.option('enableGlobal', '-E 在所有环境下启用问答', { authority: 3 }) | ||
.option('groups', '-g <gids> 设置具体的生效环境', { authority: 3, type: 'string', validate: utils_1.RE_GROUPS }) | ||
.option('enableGlobal', '-E 在所有环境下启用问答', { authority }) | ||
.option('groups', '-g <gids> 设置具体的生效环境', { authority, type: 'string', validate: utils_1.RE_GROUPS }) | ||
.option('global', '-G 无视上下文搜索'); | ||
@@ -16,0 +17,0 @@ ctx.on('dialogue/validate', (argv) => { |
@@ -9,7 +9,8 @@ "use strict"; | ||
return; | ||
const { authority } = config; | ||
ctx.command('teach') | ||
.option('frozen', '-f 锁定这个问答', { authority: 4 }) | ||
.option('frozen', '-F, --no-frozen 解锁这个问答', { authority: 4, value: false }) | ||
.option('frozen', '-f 锁定这个问答', { authority: authority.frozen }) | ||
.option('frozen', '-F, --no-frozen 解锁这个问答', { authority: authority.frozen, value: false }) | ||
.option('writer', '-w <uid> 添加或设置问题的作者') | ||
.option('writer', '-W, --anonymous 添加或设置匿名问题', { value: 0 }) | ||
.option('writer', '-W, --anonymous 添加或设置匿名问题', { authority: authority.writer, value: 0 }) | ||
.option('substitute', '-s 由教学者完成回答的执行') | ||
@@ -75,6 +76,6 @@ .option('substitute', '-S, --no-substitute 由触发者完成回答的执行', { value: false }); | ||
}); | ||
// 当修改问答时,如果问答的作者不是本人,需要 3 级权限 | ||
// 当修改问答时,如果问答的作者不是本人,需要 admin 级权限 | ||
// 当添加和修改问答时,如果问答本身是代行模式或要将问答设置成代行模式,则需要权限高于问答原作者 | ||
// 当使用 -w 时需要原作者权限高于目标用户 | ||
// 锁定的问答需要 4 级权限才能修改 | ||
// 锁定的问答需要 frozen 级权限才能修改 | ||
ctx.on('dialogue/permit', ({ session, target, options, authMap }, { writer, flag }) => { | ||
@@ -84,5 +85,5 @@ const { substitute, writer: newWriter } = options; | ||
return ((newWriter && authority <= authMap[newWriter] && newWriter !== id) || | ||
((flag & utils_1.Dialogue.Flag.frozen) && authority < 4) || | ||
(writer !== id && ((target && authority < 3) || ((substitute || (flag & utils_1.Dialogue.Flag.substitute)) && | ||
(authority <= (authMap[writer] || 2)))))); | ||
((flag & utils_1.Dialogue.Flag.frozen) && authority < config.authority.frozen) || | ||
(writer !== id && ((target && authority < config.authority.admin) || ((substitute || (flag & utils_1.Dialogue.Flag.substitute)) && | ||
(authority <= (authMap[writer] || config.authority.base)))))); | ||
}); | ||
@@ -89,0 +90,0 @@ ctx.on('dialogue/detail-short', ({ flag }, output) => { |
@@ -59,4 +59,13 @@ import { Session, ParsedLine, App } from 'koishi-core'; | ||
type Field = keyof Dialogue; | ||
interface AuthorityConfig { | ||
base?: number; | ||
admin?: number; | ||
context?: number; | ||
frozen?: number; | ||
regExp?: number; | ||
writer?: number; | ||
} | ||
interface Config { | ||
prefix?: string; | ||
authority?: AuthorityConfig; | ||
historyAge?: number; | ||
@@ -63,0 +72,0 @@ validateRegExp?: RegExpValidator.Options; |
{ | ||
"name": "koishi-plugin-teach", | ||
"description": "Teach plugin for Koishi", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"main": "dist/index.js", | ||
@@ -41,7 +41,7 @@ "typings": "dist/index.d.ts", | ||
"peerDependencies": { | ||
"koishi-core": "^2.3.2", | ||
"koishi-core": "^2.4.0", | ||
"koishi-utils": "^3.1.5" | ||
}, | ||
"devDependencies": { | ||
"koishi-plugin-mongo": "^1.1.0", | ||
"koishi-plugin-mongo": "^1.1.1", | ||
"koishi-plugin-mysql": "^2.0.2", | ||
@@ -48,0 +48,0 @@ "koishi-test-utils": "^5.0.2" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
226513
2965