-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: requester,manger,alias modules
- Loading branch information
Showing
60 changed files
with
923 additions
and
4,872 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,4 @@ kotori.dev.yml | |
!modules/i18n-command | ||
!modules/menu | ||
|
||
index.html | ||
data |
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
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,23 +1,64 @@ | ||
import path from 'path'; | ||
import { Context } from 'kotori-bot'; | ||
import { CommandAccess, Context, MessageScope } from 'kotori-bot'; | ||
|
||
export const lang = [__dirname, '../locales']; | ||
|
||
export const inject = ['database']; | ||
export const inject = ['file']; | ||
|
||
type Data = Record<string, string[]>; | ||
|
||
export function main(ctx: Context) { | ||
ctx.on('ready', async () => { | ||
await ctx.db | ||
.createTable('access', (table) => { | ||
table.increments(); | ||
table.string('platform'); | ||
table.string('groupId'); | ||
table.string('userId'); | ||
}) | ||
.catch(() => {}); | ||
const load = (platform: string) => ctx.file.load(`${platform}.json`, 'json', {}) as Data; | ||
const save = (platform: string, data: Data) => ctx.file.save(`${platform}.json`, data); | ||
|
||
ctx.on('before_parse', (data) => { | ||
const d = data; | ||
if (d.session.type !== MessageScope.GROUP || !d.session.groupId) return; | ||
const list = load(d.session.api.adapter.platform); | ||
if (!(String(d.session.groupId) in list)) return; | ||
if (!list[String(d.session.groupId)].includes(String(d.session.userId))) return; | ||
d.session.sender.role = 'admin'; | ||
}); | ||
|
||
ctx.on('parse', (data) => {}); | ||
} | ||
ctx | ||
.command('access query - access.descr.access.query') | ||
.action((_, session) => { | ||
const list = (load(session.api.adapter.platform)[String(session.groupId)] ?? []) | ||
.map((el) => session.format('access.msg.access.list', [el])) | ||
.join(''); | ||
return ['access.msg.access.query', [list]]; | ||
}) | ||
.scope(MessageScope.GROUP) | ||
.access(CommandAccess.ADMIN); | ||
|
||
// const message = controlParams(`${data.group_id}\\accessList.json` | ||
ctx | ||
.command('access add <userId> - access.descr.access.add') | ||
.action((data, session) => { | ||
const list = load(session.api.adapter.platform); | ||
const index = String(session.groupId); | ||
list[index] = list[index] ?? []; | ||
if (list[index].includes(data.args[0] as string)) { | ||
return session.error('exists', { target: data.args[0] as string }); | ||
} | ||
list[index].push(data.args[0] as string); | ||
save(session.api.adapter.platform, list); | ||
return ['access.msg.access.add', [data.args[0]]]; | ||
}) | ||
.scope(MessageScope.GROUP) | ||
.access(CommandAccess.ADMIN); | ||
|
||
ctx | ||
.command('access del <userId> - access.descr.access.del') | ||
.action((data, session) => { | ||
const list = load(session.api.adapter.platform); | ||
const index = String(session.groupId); | ||
list[index] = list[index] ?? []; | ||
if (!list[index].includes(data.args[0] as string)) { | ||
return session.error('no_exists', { target: data.args[0] as string }); | ||
} | ||
list[index] = list[index].filter((el) => el !== data.args[0]); | ||
save(session.api.adapter.platform, list); | ||
return ['access.msg.access.del', [data.args[0]]]; | ||
}) | ||
.scope(MessageScope.GROUP) | ||
.access(CommandAccess.ADMIN); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"core.descr.alias.query": "Query all command aliases", | ||
"core.descr.alias.add": "Add command alias, supports parameters, no need for slash", | ||
"core.descr.alias.del": "Delete command alias", | ||
"core.msg.alias.query": "Alias list: {0}", | ||
"core.msg.alias.list": "\n{0} -> {1}", | ||
"core.msg.alias.add": "Succeeded in adding alias: {0}\nSend the alias to see the effect", | ||
"core.msg.alias.del": "Succeeded in deleting alias: {0}", | ||
"core.msg.alias.fail": "This command or alias is already registered", | ||
"core.msg.alias.fail.2": "Invalid command" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"core.descr.alias.query": "すべてのコマンドエイリアスを照会", | ||
"core.descr.alias.add": "コマンドエイリアスを追加、スラッシュ不要、パラメータ可能", | ||
"core.descr.alias.del": "コマンドエイリアスを削除", | ||
"core.msg.alias.query": "エイリアスリスト:{0}", | ||
"core.msg.alias.list": "\n{0} -> {1}", | ||
"core.msg.alias.add": "エイリアスが追加されました: {0}\nエイリアスを送信して効果を確認してください", | ||
"core.msg.alias.del": "エイリアスが削除されました: {0}", | ||
"core.msg.alias.fail": "そのコマンドまたはエイリアスは既に登録されています", | ||
"core.msg.alias.fail.2": "そのコマンドは無効です" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"core.descr.alias.query": "查询全部指令别名", | ||
"core.descr.alias.add": "添加指令别名", | ||
"core.descr.alias.del": "删除指令别名", | ||
"core.msg.alias.query": "别名列表:{0}", | ||
"core.msg.alias.list": "\n{0} -> {1}", | ||
"core.msg.alias.add": "成功添加别名:{0}\n发送别名以查看效果", | ||
"core.msg.alias.del": "成功删除别名:{0}", | ||
"core.msg.alias.fail": "该别名已被注册", | ||
"core.msg.alias.fail.2": "该指令无效" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"core.descr.alias.query": "查詢全部指令別名", | ||
"core.descr.alias.add": "添加指令別名", | ||
"core.descr.alias.del": "刪除指令別名", | ||
"core.msg.alias.query": "別名列表:{0}", | ||
"core.msg.alias.list": "\n{0} -> {1}", | ||
"core.msg.alias.add": "成功添加別名:{0}\n發送別名以查看效果", | ||
"core.msg.alias.del": "成功刪除別名:{0}", | ||
"core.msg.alias.fail": "該別名已被注冊", | ||
"core.msg.alias.fail.2": "該指令無效" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@kotori-bot/kotori-plugin-alias", | ||
"version": "1.0.0", | ||
"description": "alias plugin", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"build": "tsc --build" | ||
}, | ||
"keywords": [ | ||
"kotori", | ||
"chatbot", | ||
"kotori-plugin" | ||
], | ||
"license": "GPL-3.0", | ||
"files": [ | ||
"lib", | ||
"locales", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"author": "Himeno <biyuehuya@gmail.com>", | ||
"peerDependencies": { | ||
"kotori-bot": "workspace:^" | ||
}, | ||
"kotori": { | ||
"enforce": "pre", | ||
"meta": { | ||
"language": [ | ||
"en_US", | ||
"ja_JP", | ||
"zh_TW", | ||
"zh_CN" | ||
] | ||
} | ||
} | ||
} |
Oops, something went wrong.