-
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
58 changed files
with
1,034 additions
and
903 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
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,33 +1,19 @@ | ||
{ | ||
"name": "@kotori-bot/kotori-plugin-alias", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "alias plugin", | ||
"main": "lib/index.js", | ||
"keywords": [ | ||
"kotori", | ||
"chatbot", | ||
"kotori-plugin" | ||
], | ||
"keywords": ["kotori", "chatbot", "kotori-plugin"], | ||
"license": "GPL-3.0", | ||
"files": [ | ||
"lib", | ||
"locales", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"files": ["lib", "locales", "LICENSE", "README.md"], | ||
"author": "Himeno <[email protected]>", | ||
"peerDependencies": { | ||
"kotori-bot": "workspace:^" | ||
}, | ||
"kotori": { | ||
"enforce": "pre", | ||
"meta": { | ||
"language": [ | ||
"en_US", | ||
"ja_JP", | ||
"zh_TW", | ||
"zh_CN" | ||
] | ||
"language": ["en_US", "ja_JP", "zh_TW", "zh_CN"] | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,53 +3,52 @@ | |
* @Blog: https://hotaru.icu | ||
* @Date: 2023-07-11 14:18:27 | ||
* @LastEditors: Hotaru [email protected] | ||
* @LastEditTime: 2024-06-07 21:19:44 | ||
* @LastEditTime: 2024-07-29 18:03:20 | ||
*/ | ||
import { Context, Symbols } from 'kotori-bot'; | ||
import { type Context, Symbols } from 'kotori-bot' | ||
|
||
export const lang = [__dirname, '../locales']; | ||
export const lang = [__dirname, '../locales'] | ||
|
||
export const inject = ['file']; | ||
export const inject = ['file'] | ||
|
||
type Data = Record<string, string>; | ||
type Data = Record<string, string> | ||
|
||
export function main(ctx: Context) { | ||
const load = (bot: string) => ctx.file.load<Data>(`${bot}.json`, 'json', {}); | ||
const save = (bot: string, data: Data) => ctx.file.save(`${bot}.json`, data); | ||
const load = (bot: string) => ctx.file.load<Data>(`${bot}.json`, 'json', {}) | ||
const save = (bot: string, data: Data) => ctx.file.save(`${bot}.json`, data) | ||
|
||
ctx.midware((next, session) => { | ||
const s = session; | ||
const list = load(s.api.adapter.identity); | ||
if (list[s.message] || s.message.trim() in list) s.message = list[s.message]; | ||
next(); | ||
}, 90); | ||
const list = load(session.api.adapter.identity) | ||
const msg = session.message.toString() | ||
if (list[msg] || session.message.trim() in list) session.message = list[msg] | ||
next() | ||
}, 90) | ||
|
||
ctx.command('alias query - alias.descr.alias.query').action((_, session) => { | ||
const list = Object.entries(load(session.api.adapter.identity) ?? {}) | ||
.map((el) => session.format('alias.msg.alias.list', [...el])) | ||
.join(''); | ||
return ['alias.msg.alias.query', [list]]; | ||
}); | ||
.join('') | ||
return session.format('alias.msg.alias.query', [list]) | ||
}) | ||
|
||
ctx.command('alias add <alias> <...command> - alias.descr.alias.add').action((data, session) => { | ||
const list = load(session.api.adapter.identity); | ||
if ((data.args[0] as string) in list) return 'alias.msg.alias.fail'; | ||
let useful = false; | ||
ctx[Symbols.command].forEach((command) => { | ||
if (useful) return; | ||
if (command.meta.root === data.args[1] || command.meta.alias.includes(data.args[1] as string)) useful = true; | ||
}); | ||
if (!useful) return 'alias.msg.alias.fail.2'; | ||
list[data.args[0] as string] = data.args.slice(1).join(' '); | ||
save(session.api.adapter.identity, list); | ||
return ['alias.msg.alias.add', [data.args[0]]]; | ||
}); | ||
const list = load(session.api.adapter.identity) | ||
if ((data.args[0] as string) in list) return 'alias.msg.alias.fail' | ||
|
||
const useful = Array.from(ctx[Symbols.command].values()).some( | ||
(command) => command.meta.root === data.args[1] || command.meta.alias.includes(data.args[1] as string) | ||
) | ||
if (!useful) return 'alias.msg.alias.fail.2' | ||
list[data.args[0] as string] = data.args.slice(1).join(' ') | ||
save(session.api.adapter.identity, list) | ||
return session.format('alias.msg.alias.add', [data.args[0]]) | ||
}) | ||
|
||
ctx.command('alias del <alias> - alias.descr.alias.del').action((data, session) => { | ||
const list = load(session.api.adapter.identity); | ||
if (!((data.args[0] as string) in list)) return session.error('no_exists', { target: data.args[0] as string }); | ||
delete list[data.args[0] as string]; | ||
save(session.api.adapter.identity, list); | ||
return ['alias.msg.alias.del', [data.args[0]]]; | ||
}); | ||
const list = load(session.api.adapter.identity) | ||
if (!((data.args[0] as string) in list)) throw session.error('no_exists', { target: data.args[0] as string }) | ||
delete list[data.args[0] as string] | ||
save(session.api.adapter.identity, list) | ||
return session.format('alias.msg.alias.del', [data.args[0]]) | ||
}) | ||
} |
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,10 +1,10 @@ | ||
{ | ||
"bangumi.descr.bgm": "Search anime/games schedules", | ||
"bangumi.descr.bgmc": "Get today's schedules", | ||
"bangumi.msg.bgm": "Original name: {0}\nChinese name: {1}\nIntroduction: {2}\nTags: {3}\nDetails: {4}\n{5}", | ||
"bangumi.msg.bgm.list": "{0}.{1}{2}\n", | ||
"bangumi.msg.bgm.fail": "No relevant items found: {0}", | ||
"bangumi.option.bangumi.order": "Order number", | ||
"bangumi.msg.bgmc": "Date: {0}~{1}", | ||
"bangumi.msg.bgmc.list": "\nOriginal name: {0}\nChinese name: {1}\nBroadcast time: {2}\n{3}" | ||
} | ||
"bangumi.descr.bgm": "Search anime/games schedules", | ||
"bangumi.descr.bgmc": "Get today's schedules", | ||
"bangumi.msg.bgm": "Original name: {0}\nChinese name: {1}\nIntroduction: {2}\nTags: {3}\nDetails: {4}", | ||
"bangumi.msg.bgm.list": "{0}.{1}{2}\n", | ||
"bangumi.msg.bgm.fail": "No relevant items found: {0}", | ||
"bangumi.option.bangumi.order": "Order number", | ||
"bangumi.msg.bgmc": "Date: {0}~{1}", | ||
"bangumi.msg.bgmc.list": "\nOriginal name: {0}\nChinese name: {1}\nBroadcast time: {2}\n{3}" | ||
} |
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,10 +1,10 @@ | ||
{ | ||
"bangumi.descr.bgm": "アニメ/ゲームの番組検索", | ||
"bangumi.descr.bgmc": "今日放送の番組を取得", | ||
"bangumi.msg.bgm": "原題:{0}\n中国語名:{1}\n紹介:{2}\nタグ:{3}\n詳細:{4}\n{5}", | ||
"bangumi.msg.bgm.list": "{0}.{1}{2}\n", | ||
"bangumi.option.bangumi.order": "番号", | ||
"bangumi.msg.bgm.fail": "関連項目が見つかりませんでした:{0}", | ||
"bangumi.msg.bgmc": "日付:{0}~{1}", | ||
"bangumi.msg.bgmc.list": "\n原題:{0}\n中国語名:{1}\n放送開始時間:{2}\n{3}" | ||
} | ||
"bangumi.descr.bgm": "アニメ/ゲームの番組検索", | ||
"bangumi.descr.bgmc": "今日放送の番組を取得", | ||
"bangumi.msg.bgm": "原題:{0}\n中国語名:{1}\n紹介:{2}\nタグ:{3}\n詳細:{4}", | ||
"bangumi.msg.bgm.list": "{0}.{1}{2}\n", | ||
"bangumi.option.bangumi.order": "番号", | ||
"bangumi.msg.bgm.fail": "関連項目が見つかりませんでした:{0}", | ||
"bangumi.msg.bgmc": "日付:{0}~{1}", | ||
"bangumi.msg.bgmc.list": "\n原題:{0}\n中国語名:{1}\n放送開始時間:{2}\n{3}" | ||
} |
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,10 +1,10 @@ | ||
{ | ||
"bangumi.descr.bgm": "番组计划搜索游戏/动漫", | ||
"bangumi.descr.bgmc": "获取番组计划今日放送", | ||
"bangumi.msg.bgm": "原名:{0}\n中文名:{1}\n介绍:{2}\n标签:{3}\n详情:{4}\n{5}", | ||
"bangumi.msg.bgm": "原名:{0}\n中文名:{1}\n介绍:{2}\n标签:{3}\n详情:{4}", | ||
"bangumi.msg.bgm.list": "{0}.{1}{2}\n", | ||
"bangumi.option.bangumi.order": "序号", | ||
"bangumi.msg.bgm.fail": "未找到相关条目:{0}", | ||
"bangumi.msg.bgmc": "日期:{0}~{1}", | ||
"bangumi.msg.bgmc.list": "\n原名:{0}\n中文名:{1}\n开播时间:{2}\n{3}" | ||
} | ||
} |
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,10 +1,10 @@ | ||
{ | ||
"bangumi.descr.bgm": "番組計劃搜索遊戲/動漫", | ||
"bangumi.descr.bgmc": "獲取番組計劃今日放送", | ||
"bangumi.msg.bgm": "原名:{0}\n中文名:{1}\n介紹:{2}\n標簽:{3}\n詳情:{4}\n{5}", | ||
"bangumi.msg.bgm": "原名:{0}\n中文名:{1}\n介紹:{2}\n標簽:{3}\n詳情:{4}", | ||
"bangumi.msg.bgm.list": "{0}.{1}{2}\n", | ||
"bangumi.msg.bgm.fail": "未找到相關條目:{0}", | ||
"bangumi.option.bangumi.order": "番号", | ||
"bangumi.msg.bgmc": "日期:{0}~{1}", | ||
"bangumi.msg.bgmc.list": "\n原名:{0}\n中文名:{1}\n開播時間:{2}\n{3}" | ||
} | ||
} |
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.