From d1914bee4d1b2adec136195004442706a8a97b85 Mon Sep 17 00:00:00 2001 From: Hotaru Date: Sat, 10 Feb 2024 21:03:53 +0800 Subject: [PATCH] fix: loader catch error --- kotori.db | Bin 16384 -> 16384 bytes modules/bangumi/src/index.ts | 64 +++++------ modules/github/locales/en_US.json | 8 +- modules/github/locales/ja_JP.json | 8 +- modules/github/locales/zh_CN.json | 8 +- modules/github/locales/zh_TW.json | 8 +- modules/github/src/index.ts | 6 +- modules/goodnight/src/index.ts | 15 +-- modules/i18n-command/src/index.ts | 1 + modules/newnew/locales/en_US.json | 4 +- modules/newnew/locales/ja_JP.json | 4 +- modules/newnew/locales/zh_CN.json | 6 +- modules/newnew/locales/zh_TW.json | 6 +- modules/newnew/src/index.ts | 20 ++-- modules/random-img/src/index.ts | 4 - modules/sed/locales/en_US.json | 18 ++-- modules/sed/locales/ja_JP.json | 18 ++-- modules/sed/locales/zh_CN.json | 18 ++-- modules/sed/locales/zh_TW.json | 18 ++-- modules/sed/{package1.json => package.json} | 0 modules/sed/src/index.ts | 64 +++-------- modules/sed/src/utils.ts | 113 +++++++++++++++----- packages/core/src/service/adapter.ts | 2 +- packages/loader/src/loader.ts | 9 +- packages/loader/src/runner.ts | 2 +- packages/logger/src/index.ts | 2 +- 26 files changed, 226 insertions(+), 200 deletions(-) rename modules/sed/{package1.json => package.json} (100%) diff --git a/kotori.db b/kotori.db index 099fa58ea02c7838f818664549a9235f55f293d7..6abf5864d237e12a497af4b897e14a216b1fe56b 100644 GIT binary patch delta 134 zcmZo@U~Fh$oFL7pF;T{uQDbAm5`Jbiz6+Dt1+0bm1^7Am8Tfwiec*e+_kiyP--XSA x0yTUdY-+3w{0t05`Jb`eu>HK0@j-a6|V7ZmXLogz$m-OKmY*yKMQvN diff --git a/modules/bangumi/src/index.ts b/modules/bangumi/src/index.ts index 93a400cd..84500b7c 100644 --- a/modules/bangumi/src/index.ts +++ b/modules/bangumi/src/index.ts @@ -58,39 +58,43 @@ export const lang = [__dirname, '../locales']; export const inject = ['cache']; export function main(ctx: Context) { - ctx.command('bgm [order:number=1] - bangumi.descr.bgm').action(async (data, session) => { - const prop = `bgm_${data.args[0]}`; - const res = - ctx.cache.get>(prop) ?? - bgm1Schema.parse(await http(`search/subject/${data.args[0]}`)); - if (!res || !Array.isArray(res.list)) return ['bangumi.msg.bgm.fail', [data.args[0]]]; - ctx.cache.set(prop, res); + ctx + .command('bgm <...content> - bangumi.descr.bgm') + .option('o', 'order:number bangumi.option.bangumi.order') + .action(async (data, session) => { + const name = data.args.join(''); + const order = data.options.order ?? 1; + const prop = `bgm_${name}`; + const res = + ctx.cache.get>(prop) ?? bgm1Schema.parse(await http(`search/subject/${name}`)); + if (!res || !Array.isArray(res.list)) return ['bangumi.msg.bgm.fail', [name]]; + ctx.cache.set(prop, res); - if (data.args[1] === 0) { - let list = ''; - for (let init = 0; init < (res.list.length > MAX_LIST ? MAX_LIST : res.list.length); init += 1) { - const result = res.list[init]; - list += session.format('bangumi.msg.bgm.list', [init + 1, result.name, result.name_cn]); + if (order === 0) { + let list = ''; + for (let init = 0; init < (res.list.length > MAX_LIST ? MAX_LIST : res.list.length); init += 1) { + const result = res.list[init]; + list += session.format('bangumi.msg.bgm.list', [init + 1, result.name, result.name_cn]); + } + return list; } - return list; - } - const result = res.list[(data.args[1] as number) - 1]; - if (!result) return session.error('num_error'); - const res2 = bgm2Schema.parse(await http(`v0/subjects/${result.id}`)); - if ('title' in res2) return ['bangumi.msg.bgm.fail', [data.args[0]]]; - return [ - 'bangumi.msg.bgm', - [ - res2.name, - res2.name_cn, - res2.summary, - res2.tags.map((el) => el.name).join(' '), - `https://bgm.tv/subject/${result.id}`, - session.el.image(res2.images.large) - ] - ]; - }); + const result = res.list[(order as number) - 1]; + if (!result) return session.error('num_error'); + const res2 = bgm2Schema.parse(await http(`v0/subjects/${result.id}`)); + if ('title' in res2) return ['bangumi.msg.bgm.fail', [name]]; + return [ + 'bangumi.msg.bgm', + [ + res2.name, + res2.name_cn, + res2.summary, + res2.tags.map((el) => el.name).join(' '), + `https://bgm.tv/subject/${result.id}`, + session.el.image(res2.images.large) + ] + ]; + }); ctx.command('bgmc - bangumi.descr.bgmc').action(async (_, session) => { const res = bgmcSchema.parse(await http(`calendar`)); diff --git a/modules/github/locales/en_US.json b/modules/github/locales/en_US.json index da20f488..ec4897cb 100644 --- a/modules/github/locales/en_US.json +++ b/modules/github/locales/en_US.json @@ -1,6 +1,6 @@ { - "querytool.descr.github": "Query Github repository info", - "querytool.msg.github": "URL: %name%\nDescription: %description%\nLanguage: %language%\nOwner: %author%\nCreated: %create%\nLast updated: %update%\nLast push: %push%\nOpen source license: %license%", - "querytool.msg.github.image": "%image%", - "querytool.msg.github.fail": "Repository not found: %input%" + "github.descr.github": "Query Github repository info", + "github.msg.github": "URL: %name%\nDescription: %description%\nLanguage: %language%\nOwner: %author%\nCreated: %create%\nLast updated: %update%\nLast push: %push%\nOpen source license: %license%", + "github.msg.github.image": "%image%", + "github.msg.github.fail": "Repository not found: %input%" } \ No newline at end of file diff --git a/modules/github/locales/ja_JP.json b/modules/github/locales/ja_JP.json index 1a780468..3adc785c 100644 --- a/modules/github/locales/ja_JP.json +++ b/modules/github/locales/ja_JP.json @@ -1,6 +1,6 @@ { - "querytool.descr.github": "Githubリポジトリ情報を検索", - "querytool.msg.github": "アドレス:%name%\n説明:%description%\n言語:%language%\n所有者:%author%\n作成日時:%create%\n最終更新日時:%update%\n最終プッシュ日時:%push%\nオープンソースライセンス:%license%", - "querytool.msg.github.image": "%image%", - "querytool.msg.github.fail": "リポジトリが見つかりません:%input%" + "github.descr.github": "Githubリポジトリ情報を検索", + "github.msg.github": "アドレス:%name%\n説明:%description%\n言語:%language%\n所有者:%author%\n作成日時:%create%\n最終更新日時:%update%\n最終プッシュ日時:%push%\nオープンソースライセンス:%license%", + "github.msg.github.image": "%image%", + "github.msg.github.fail": "リポジトリが見つかりません:%input%" } \ No newline at end of file diff --git a/modules/github/locales/zh_CN.json b/modules/github/locales/zh_CN.json index 678a17b8..1a8321b3 100644 --- a/modules/github/locales/zh_CN.json +++ b/modules/github/locales/zh_CN.json @@ -1,6 +1,6 @@ { - "querytool.descr.github": "查询Github仓库信息", - "querytool.msg.github": "地址:%name%\n描述:%description%\n语言:%language%\n所有者:%author%\n创建时间:\n %create%\n最后更新时间:%update%\n最后推送时间:%push%\n开源协议:%license%", - "querytool.msg.github.image": "%image%", - "querytool.msg.github.fail": "未找到仓库:%input%" + "github.descr.github": "查询Github仓库信息", + "github.msg.github": "地址:%name%\n描述:%description%\n语言:%language%\n所有者:%author%\n创建时间:\n %create%\n最后更新时间:%update%\n最后推送时间:%push%\n开源协议:%license%", + "github.msg.github.image": "%image%", + "github.msg.github.fail": "未找到仓库:%input%" } \ No newline at end of file diff --git a/modules/github/locales/zh_TW.json b/modules/github/locales/zh_TW.json index 502e3754..4ef16c92 100644 --- a/modules/github/locales/zh_TW.json +++ b/modules/github/locales/zh_TW.json @@ -1,6 +1,6 @@ { - "querytool.descr.github": "查詢Github倉庫信息", - "querytool.msg.github": "地址:%name%\n描述:%description%\n語言:%language%\n所有者:%author%\n創建時間:\n %create%\n最後更新時間:%update%\n最後推送時間:%push%\n開源協議:%license%", - "querytool.msg.github.image": "%image%", - "querytool.msg.github.fail": "未找到倉庫:%input%" + "github.descr.github": "查詢Github倉庫信息", + "github.msg.github": "地址:%name%\n描述:%description%\n語言:%language%\n所有者:%author%\n創建時間:\n %create%\n最後更新時間:%update%\n最後推送時間:%push%\n開源協議:%license%", + "github.msg.github.image": "%image%", + "github.msg.github.fail": "未找到倉庫:%input%" } \ No newline at end of file diff --git a/modules/github/src/index.ts b/modules/github/src/index.ts index b70c21a5..77800ea0 100644 --- a/modules/github/src/index.ts +++ b/modules/github/src/index.ts @@ -21,11 +21,11 @@ const githubSchema = Tsu.Union([ export const lang = [__dirname, '../locales']; export function main(ctx: Context) { - ctx.command('github - querytool.descr.github').action(async (data, session) => { + ctx.command('github - github.descr.github').action(async (data, session) => { const res = githubSchema.parse(await ctx.http.get(`https://api.github.com/repos/${data.args[0]}`)); - if (!('full_name' in res)) return ['querytool.msg.github.fail', { input: data.args[0] }]; + if (!('full_name' in res)) return ['github.msg.github.fail', { input: data.args[0] }]; session.quick([ - 'querytool.msg.github', + 'github.msg.github', { name: res.full_name || 'BOT_RESULT.EMPTY', description: res.description || 'BOT_RESULT.EMPTY', diff --git a/modules/goodnight/src/index.ts b/modules/goodnight/src/index.ts index 51affbcc..6e9bef40 100644 --- a/modules/goodnight/src/index.ts +++ b/modules/goodnight/src/index.ts @@ -42,12 +42,13 @@ export function main(ctx: Context, config: Config) { ctx.regexp(/^(早|早安|早上好)$/, (_, session) => { const record = loadTodayData(); const at = session.el.at(session.userId); - if (session.userId in record.morning) return ['goodnight.msg.morning.already', { at }]; + const prop = `${session.api.adapter.platform}${session.userId}`; + if (prop in record.morning) return ['goodnight.msg.morning.already', { at }]; const hours = new Date().getHours(); if (hours < config.getupTimeLess) return ['goodnight.msg.morning.early', { at, hour: config.getupTimeLess }]; - record.morning[session.userId] = new Date().getTime(); + record.morning[prop] = new Date().getTime(); saveTodayData(record); const count = Object.keys(record.morning).length; // if (count <= 10) addExp(data.group_id!, session.userId, 15); @@ -61,17 +62,17 @@ export function main(ctx: Context, config: Config) { ctx.regexp(/^(晚|晚安|晚上好)$/, (_, session) => { const record = loadTodayData(); const at = session.el.at(session.userId)!; - if (session.userId in record.night) return ['goodnight.msg.night.already', { at }]; + const prop = `${session.api.adapter.platform}${session.userId}`; + if (prop in record.night) return ['goodnight.msg.night.already', { at }]; const record2 = loadTodayData(true); - if (!(session.userId in record.morning) && !(session.userId in record2.morning)) - return ['goodnight.msg.night.not', { at }]; + if (!(prop in record.morning) && !(prop in record2.morning)) return ['goodnight.msg.night.not', { at }]; const nowTime = new Date().getTime(); - const timecal = nowTime - (record.morning[session.userId] || record2.morning[session.userId]); + const timecal = nowTime - (record.morning[prop] || record2.morning[prop]); if (timecal < config.sleepTimeLess * 60 * 60 * 1000) return ['goodnight.msg.night.less', { at }]; - record.night[session.userId] = nowTime; + record.night[prop] = nowTime; saveTodayData(record); const time = ctx.i18n.rtime(timecal, 'hours'); const hours = new Date().getHours(); diff --git a/modules/i18n-command/src/index.ts b/modules/i18n-command/src/index.ts index 9750e468..fb1c9e8b 100644 --- a/modules/i18n-command/src/index.ts +++ b/modules/i18n-command/src/index.ts @@ -22,6 +22,7 @@ export function main(ctx: Context) { } const { value } = data.result; data.cancel(); + ctx.logger.debug(data); switch (value.type) { case 'arg_error': quick(['corei18n.template.args_error', value]); diff --git a/modules/newnew/locales/en_US.json b/modules/newnew/locales/en_US.json index 1626d80f..53bc031e 100644 --- a/modules/newnew/locales/en_US.json +++ b/modules/newnew/locales/en_US.json @@ -7,11 +7,11 @@ "newnew.msg.my_length": "{0}Max length: {1} cm Min length: {2} cm\nUsed {3} times Total length: {4} cm\nAverage length: {5} cm", "newnew.msg.my_length.fail": "{0}Your bull is lost...Can't find your bull data 😭 Sorry", "newnew.descr.avg_ranking": "Get average bull ranking", - "newnew.msg.avg_ranking": "Average length ranking:", + "newnew.msg.avg_ranking": "Average length ranking:{0}", "newnew.msg.avg_ranking.list": "\n{0}.{1} {2} cm ({3} times, Total {4} cm)", "newnew.msg.avg_ranking.fail": "No data now (≧_ ≦)", "newnew.descr.today_ranking": "Get today's bull ranking", - "newnew.msg.today_ranking": "Today's length ranking:", + "newnew.msg.today_ranking": "Today's length ranking:{0}", "newnew.msg.today_ranking.list": "\n{0}.{1} {2} cm", "newnew.msg.today_ranking.fail": "No data now (≧_ ≦)" } \ No newline at end of file diff --git a/modules/newnew/locales/ja_JP.json b/modules/newnew/locales/ja_JP.json index 8278980c..99f33701 100644 --- a/modules/newnew/locales/ja_JP.json +++ b/modules/newnew/locales/ja_JP.json @@ -7,11 +7,11 @@ "newnew.msg.my_length": "{0}最大の長さ:{1} cm 最深の長さ:{2} cm\n使用回数:{3} 回 総長:{4} cm\n平均の長さ:{5} cm", "newnew.msg.my_length.fail": "{0}あなたの牛牛が見つかりませんでした...牛牛のデータが見つかりません😭 ごめんなさい", "newnew.descr.avg_ranking": "平均牛牛ランキングを取得", - "newnew.msg.avg_ranking": "平均の長さランキング:", + "newnew.msg.avg_ranking": "平均の長さランキング:{0}", "newnew.msg.avg_ranking.list": "\n{0}.{1} {2} cm ({3}回、総長{4} cm)", "newnew.msg.avg_ranking.fail": "現在データがありません(≧_ ≦)", "newnew.descr.today_ranking": "今日の牛牛ランキングを取得", - "newnew.msg.today_ranking": "今日の長さランキング:", + "newnew.msg.today_ranking": "今日の長さランキング:{0}", "newnew.msg.today_ranking.list": "\n{0}.{1} {2} cm", "newnew.msg.today_ranking.fail": "現在データがありません(≧_ ≦)" } \ No newline at end of file diff --git a/modules/newnew/locales/zh_CN.json b/modules/newnew/locales/zh_CN.json index f53feb90..fbaec761 100644 --- a/modules/newnew/locales/zh_CN.json +++ b/modules/newnew/locales/zh_CN.json @@ -4,14 +4,14 @@ "newnew.msg.today_length.info.1": "{0}今日的牛~牛长度是{1} cm", "newnew.msg.today_length.info.2": "{0}今日的牛~牛长度是...今天是可爱的女孩子噢( •̀ ω •́ )✧({1}cm)", "newnew.descr.my_length": "获取自己的牛牛信息", - "newnew.msg.my_length": "{0}\n最大长度:{1} cm 最深长度:{2} cm\n使用次数:{3}次 累计长度:{4} cm\n平均长度:{5} cm", + "newnew.msg.my_length": "{0}\n最大长度:{1} cm 最深长度:{2} cm\n使用次数:{3} 次 累计长度:{4} cm\n平均长度:{5} cm", "newnew.msg.my_length.fail": "{0}你的牛牛丢了...找不到你的牛牛数据呢/(ㄒoㄒ)/~~对不起", "newnew.descr.avg_ranking": "获取平均牛牛排行", - "newnew.msg.avg_ranking": "平均长度排行:", + "newnew.msg.avg_ranking": "平均长度排行:{0}", "newnew.msg.avg_ranking.list": "\n{0}.{1} {2} cm ({3} 次 总长{4} cm)", "newnew.msg.avg_ranking.fail": "当前还没有数据噢~(≧﹏ ≦)", "newnew.descr.today_ranking": "获取今日牛牛排行", - "newnew.msg.today_ranking": "今日长度排行:", + "newnew.msg.today_ranking": "今日长度排行:{0}", "newnew.msg.today_ranking.list": "\n{0}.{1} {2} cm", "newnew.msg.today_ranking.fail": "当前还没有数据噢~(≧﹏ ≦)" } \ No newline at end of file diff --git a/modules/newnew/locales/zh_TW.json b/modules/newnew/locales/zh_TW.json index de90d881..4d84975d 100644 --- a/modules/newnew/locales/zh_TW.json +++ b/modules/newnew/locales/zh_TW.json @@ -4,14 +4,14 @@ "newnew.msg.today_length.info.1": "{0}今日的牛~牛長度是{1} cm", "newnew.msg.today_length.info.2": "{0}今日的牛~牛長度是...今天是可愛的女孩子噢( •̀ ω •́ )✧({1}cm)", "newnew.descr.my_length": "獲取自己的牛牛信息", - "newnew.msg.my_length": "{0}\n最大長度:{1} cm 最深長度:{2} cm\n使用次數:{3}次 累計長度:{4} cm\n平均長度:{5} cm", + "newnew.msg.my_length": "{0}\n最大長度:{1} cm 最深長度:{2} cm\n使用次數:{3} 次 累計長度:{4} cm\n平均長度:{5} cm", "newnew.msg.my_length.fail": "{0}妳的牛牛丟了...找不到妳的牛牛數據呢/(ㄒoㄒ)/~~對不起", "newnew.descr.avg_ranking": "獲取平均牛牛排行", - "newnew.msg.avg_ranking": "平均長度排行:", + "newnew.msg.avg_ranking": "平均長度排行:{0}", "newnew.msg.avg_ranking.list": "\n{0}.{1} {2} cm ({3} 次 總長{4} cm)", "newnew.msg.avg_ranking.fail": "當前還沒有數據噢~(≧﹏ ≦)", "newnew.descr.today_ranking": "獲取今日牛牛排行", - "newnew.msg.today_ranking": "今日長度排行:", + "newnew.msg.today_ranking": "今日長度排行:{0}", "newnew.msg.today_ranking.list": "\n{0}.{1} {2} cm", "newnew.msg.today_ranking.fail": "當前還沒有數據噢~(≧﹏ ≦)" } \ No newline at end of file diff --git a/modules/newnew/src/index.ts b/modules/newnew/src/index.ts index 22a718c7..ebda6a57 100644 --- a/modules/newnew/src/index.ts +++ b/modules/newnew/src/index.ts @@ -3,7 +3,7 @@ * @Blog: https://hotaru.icu * @Date: 2023-07-30 11:33:15 * @LastEditors: Hotaru biyuehuya@gmail.com - * @LastEditTime: 2024-02-10 11:38:20 + * @LastEditTime: 2024-02-10 20:25:58 */ import { Context, Tsu } from 'kotori-bot'; @@ -74,7 +74,7 @@ export function main(ctx: Context, config: Config) { if (!person || person.length <= 0) return ['newnew.msg.my_length.fail', [session.el.at(session.userId)]]; return [ 'newnew.msg.my_length', - [session.el.at(session.userId), person[1], person[0], person[3], person[3] / person[2], person[2]] + [session.el.at(session.userId), person[1], person[0], person[2], person[3], person[3] / person[2]] ]; }); @@ -97,9 +97,9 @@ export function main(ctx: Context, config: Config) { if (nums < config.avgMinNum) return; list += session.format('newnew.msg.avg_ranking.list', [ num, - entry[0], - nums, + entry[0].slice(session.api.adapter.platform.length), entry[1][3], + nums, statOrigin[entry[0]][3] ]); num += 1; @@ -111,14 +111,18 @@ export function main(ctx: Context, config: Config) { const today = loadTodayData(); if (today.length <= 0) return 'newnew.msg.today_ranking.fail'; - const newEntries = Object.entries(today); - newEntries.sort((a, b) => b[1] - a[1]); + const entries = Object.entries(today).filter((val) => val[0].startsWith(session.api.adapter.platform)); + entries.sort((a, b) => b[1] - a[1]); let list = ''; let num = 1; - newEntries.forEach((entry) => { + entries.forEach((entry) => { if (num > 20) return; - list += session.format('newnew.msg.today_ranking.list', [num, entry[0], entry[1]]); + list += session.format('newnew.msg.today_ranking.list', [ + num, + entry[0].slice(session.api.adapter.platform.length), + entry[1] + ]); num += 1; }); return ['newnew.msg.today_ranking', [list]]; diff --git a/modules/random-img/src/index.ts b/modules/random-img/src/index.ts index 4f38f3e8..6492e1d3 100644 --- a/modules/random-img/src/index.ts +++ b/modules/random-img/src/index.ts @@ -24,10 +24,6 @@ const quick = (url: string, el: Elements) => el.image(url) || 'corei18n.template export const lang = [__dirname, '../locales']; export function main(ctx: Context) { - ctx.on('ready', () => { - ctx.logger.debug(ctx.db); - }); - ctx.command('sex [tags] - random_img.descr.sex').action(async (data, session) => { session.quick('random_img.msg.sex.tips'); const res = sexSchema.parse( diff --git a/modules/sed/locales/en_US.json b/modules/sed/locales/en_US.json index dc6ebab8..0ad8057d 100644 --- a/modules/sed/locales/en_US.json +++ b/modules/sed/locales/en_US.json @@ -1,11 +1,11 @@ { - "querytool.descr.sed": "Social engineering info query", - "querytool.msg.sed": "Query content: {0}\nTime consumed: {1} secs\nRecords found: {2}{3}", - "querytool.msg.sed.list": "\n{0}: {1}", - "querytool.msg.sed.key.qq": "QQ number", - "querytool.msg.sed.key.phone": "Phone number", - "querytool.msg.sed.key.location": "Carrier", - "querytool.msg.sed.key.id": "LOL ID", - "querytool.msg.sed.key.area": "LOL area", - "querytool.msg.sed.fail": "No relevant records found: {0}" + "sed.descr.sed": "Social engineering info query", + "sed.msg.sed": "Query content: {0}\nTime consumed: {1} secs\nRecords found: {2}{3}", + "sed.msg.sed.list": "\n{0}: {1}", + "sed.msg.sed.key.qq": "QQ number", + "sed.msg.sed.key.phone": "Phone number", + "sed.msg.sed.key.location": "Carrier", + "sed.msg.sed.key.id": "LOL ID", + "sed.msg.sed.key.area": "LOL area", + "sed.msg.sed.fail": "No relevant records found: {0}" } \ No newline at end of file diff --git a/modules/sed/locales/ja_JP.json b/modules/sed/locales/ja_JP.json index b0c73a7d..5f723215 100644 --- a/modules/sed/locales/ja_JP.json +++ b/modules/sed/locales/ja_JP.json @@ -1,11 +1,11 @@ { - "querytool.descr.sed": "ソーシャルエンジニアリング情報検索", - "querytool.msg.sed": "検索内容:{0}\n処理時間:{1} 秒\nレコード数:{2}{3}", - "querytool.msg.sed.list": "\n{0}:{1}", - "querytool.msg.sed.key.qq": "QQ番号", - "querytool.msg.sed.key.phone": "電話番号", - "querytool.msg.sed.key.location": "キャリア", - "querytool.msg.sed.key.id": "LOL ID", - "querytool.msg.sed.key.area": "LOLエリア", - "querytool.msg.sed.fail": "関連レコードが見つかりませんでした:{0}" + "sed.descr.sed": "ソーシャルエンジニアリング情報検索", + "sed.msg.sed": "検索内容:{0}\n処理時間:{1} 秒\nレコード数:{2}{3}", + "sed.msg.sed.list": "\n{0}:{1}", + "sed.msg.sed.key.qq": "QQ番号", + "sed.msg.sed.key.phone": "電話番号", + "sed.msg.sed.key.location": "キャリア", + "sed.msg.sed.key.id": "LOL ID", + "sed.msg.sed.key.area": "LOLエリア", + "sed.msg.sed.fail": "関連レコードが見つかりませんでした:{0}" } \ No newline at end of file diff --git a/modules/sed/locales/zh_CN.json b/modules/sed/locales/zh_CN.json index 3f11f1af..fafb75c4 100644 --- a/modules/sed/locales/zh_CN.json +++ b/modules/sed/locales/zh_CN.json @@ -1,11 +1,11 @@ { - "querytool.descr.sed": "社工信息查询", - "querytool.msg.sed": "查询内容:{0}\n消耗时间:{1} 秒\n记录数量:{2}{3}", - "querytool.msg.sed.list": "\n{0}:{1}", - "querytool.msg.sed.key.qq": "QQ", - "querytool.msg.sed.key.phone": "手机号", - "querytool.msg.sed.key.location": "运营商", - "querytool.msg.sed.key.id": "LOLID", - "querytool.msg.sed.key.area": "LOL区域", - "querytool.msg.sed.fail": "未查询到相关记录:{0}" + "sed.descr.sed": "社工信息查询", + "sed.msg.sed": "查询内容:{0}\n记录数量:{1}{2}", + "sed.msg.sed.list": "\n{0}:{1}", + "sed.msg.sed.key.qq": "QQ", + "sed.msg.sed.key.phone": "手机号", + "sed.msg.sed.key.location": "运营商", + "sed.msg.sed.key.id": "LOLID", + "sed.msg.sed.key.area": "LOL区域", + "sed.msg.sed.fail": "未查询到相关记录:{0}" } \ No newline at end of file diff --git a/modules/sed/locales/zh_TW.json b/modules/sed/locales/zh_TW.json index 61a6e2c5..54ae7858 100644 --- a/modules/sed/locales/zh_TW.json +++ b/modules/sed/locales/zh_TW.json @@ -1,11 +1,11 @@ { - "querytool.descr.sed": "社工信息查詢", - "querytool.msg.sed": "查詢內容:{0}\n消耗時間:{1} 秒\n記錄數量:{2}{3}", - "querytool.msg.sed.list": "\n{0}:{1}", - "querytool.msg.sed.key.qq": "QQ", - "querytool.msg.sed.key.phone": "手機號", - "querytool.msg.sed.key.location": "運營商", - "querytool.msg.sed.key.id": "LOLID", - "querytool.msg.sed.key.area": "LOL區域", - "querytool.msg.sed.fail": "未查詢到相關記錄:{0}" + "sed.descr.sed": "社工信息查詢", + "sed.msg.sed": "查詢內容:{0}\n消耗時間:{1} 秒\n記錄數量:{2}{3}", + "sed.msg.sed.list": "\n{0}:{1}", + "sed.msg.sed.key.qq": "QQ", + "sed.msg.sed.key.phone": "手機號", + "sed.msg.sed.key.location": "運營商", + "sed.msg.sed.key.id": "LOLID", + "sed.msg.sed.key.area": "LOL區域", + "sed.msg.sed.fail": "未查詢到相關記錄:{0}" } \ No newline at end of file diff --git a/modules/sed/package1.json b/modules/sed/package.json similarity index 100% rename from modules/sed/package1.json rename to modules/sed/package.json diff --git a/modules/sed/src/index.ts b/modules/sed/src/index.ts index 83c358d7..64802a06 100644 --- a/modules/sed/src/index.ts +++ b/modules/sed/src/index.ts @@ -1,57 +1,19 @@ import { Context } from 'kotori-bot'; +import Sed from './utils'; export const lang = [__dirname, '../locales']; export function main(ctx: Context) { - ctx - .command('sed ') - .action(async (data, session) => { - if (data.args[0] === session.api.adapter.selfId.toString()) - return ['querytool.msg.sed.fail', { input: data.args[0] }]; - - const res = await ctx.http.get('https://api.sed', { msg: data.args[0] }); - if (!isObj(res)) return ['BOT_RESULT.SERVER_ERROR', { res }]; - if (res.code === 501 || !isObj(res.data)) return ['querytool.msg.sed.fail', { input: data.args[0] }]; - let list = ''; - list += res.data.qq - ? stringTemp('querytool.msg.sed.list', { - key: message.locale('querytool.msg.sed.key.qq'), - content: res.data.qq - }) - : ''; - list += res.data.phone - ? stringTemp('querytool.msg.sed.list', { - key: message.locale('querytool.msg.sed.key.phone'), - content: res.data.phone - }) - : ''; - list += res.data.location - ? stringTemp('querytool.msg.sed.list', { - key: message.locale('querytool.msg.sed.key.location'), - content: res.data.location - }) - : ''; - list += res.data.id - ? stringTemp('querytool.msg.sed.list', { - key: message.locale('querytool.msg.sed.key.id'), - content: res.data.id - }) - : ''; - list += res.data.area - ? stringTemp('querytool.msg.sed.list', { - key: message.locale('querytool.msg.sed.key.area'), - content: res.data.area - }) - : ''; - return [ - 'querytool.msg.sed', - { - input: data.args[0], - time: Math.floor(res.takeTime), - count: res.count, - list - } - ]; - }) - .help('querytool.descr.sed'); + ctx.command('sed - sed.descr.sed').action(async (data, session) => { + if (data.args[0] === session.api.adapter.selfId.toString()) return ['sed.msg.sed.fail', [data.args[0]]]; + const res = await new Sed(String(data.args[0])).query(); + let list = ''; + list += res.qq ? session.format('sed.msg.sed.list', ['sed.msg.sed.key.qq', res.qq]) : ''; + list += res.phone ? session.format('sed.msg.sed.list', ['sed.msg.sed.key.phone', res.phone]) : ''; + list += res.location ? session.format('sed.msg.sed.list', ['sed.msg.sed.key.location', res.location]) : ''; + list += res.lol ? session.format('sed.msg.sed.list', ['sed.msg.sed.key.id', res.lol]) : ''; + list += res.area ? session.format('sed.msg.sed.list', ['sed.msg.sed.key.area', res.area]) : ''; + const count = Object.values(res).filter((el) => !!el).length; + return ['sed.msg.sed', [data.args[0], count === 0 ? count - 1 : 0, list]]; + }); } diff --git a/modules/sed/src/utils.ts b/modules/sed/src/utils.ts index a3233113..82c6ebe4 100644 --- a/modules/sed/src/utils.ts +++ b/modules/sed/src/utils.ts @@ -1,8 +1,12 @@ import Kotori from 'kotori-bot'; -class Sed { +export class Sed { message: string; + constructor(message: string) { + this.message = message; + } + async qqToPhone() { const data = (await Kotori.http.get(`https://zy.xywlapi.cc/qqapi?qq=${this.message}`)) as Record; if (data.status !== 200) return null; @@ -38,45 +42,98 @@ class Sed { async phoneToWeibo() { const data = (await Kotori.http.get(`https://zy.xywlapi.cc/wbphone?phone=${this.message}`)) as Record; - // ... + if (data.status !== 200) return null; + return { + id: data.id, + location: data.phonediqu + }; } async weiboToPhone() { const data = (await Kotori.http.get(`https://zy.xywlapi.cc/wbapi?id=${this.message}`)) as Record; - // ... + if (data.status !== 200) return null; + return { + phone: data.phone, + location: data.phonediqu + }; } async lolToQq() { const data = (await Kotori.http.get(`https://zy.xywlapi.cc/lolname?id=${this.message}`)) as Record; - // ... - } - - async toIdcard() { - const data = (await Kotori.http.get(`https://api.hotaru.icu/api/idcard?msg=${this.message}`)) as Record< - string, - any - >; - // ... + if (data.status !== 200) return null; + return { + qq: data.qq, + id: data.id, + area: data.daqu + }; } - async sedQuery() { - // 业务逻辑 + async query() { + let phone: string | undefined; + let qq: string | undefined; + let weibo: string | undefined; + let qqOldPass: string | undefined; + let location: string | undefined; + let lol: string | undefined; + let area: string | undefined; - return { - code: 200, - message: 'success', - takeTime: 0.1, - count: 3, - data: { - qq: '12345', - phone: '13800001111' + const arrTemp = await this.qqToPhone(); + const phoneTemp = arrTemp?.phone; + if (phoneTemp) { + phone = phoneTemp; + qq = this.message; + location = arrTemp.location; + weibo = (await this.phoneToWeibo())?.id; + this.message = qq; + qqOldPass = await this.qqToOldPass(); + const arrTemp2 = await this.qqToLol(); + lol = arrTemp2?.id; + area = lol ? arrTemp2?.area : null; + } else { + phone = (await this.weiboToPhone())?.phone; + if (phone) { + weibo = this.message; + this.message = phone; + const arrTemp2 = await this.phoneToQq(); + if (arrTemp2) { + qq = arrTemp2.qq; + location = arrTemp2.location; + this.message = qq!; + qqOldPass = await this.qqToOldPass(); + const arrTemp3 = await this.qqToLol(); + lol = arrTemp3?.id; + area = lol ? arrTemp3?.area : null; + } + } else { + const arrTemp2 = await this.phoneToQq(); + if (arrTemp2) { + qq = arrTemp2.qq; + phone = this.message; + location = arrTemp2.location; + weibo = (await this.phoneToWeibo())?.id; + this.message = qq!; + qqOldPass = await this.qqToOldPass(); + const arrTemp3 = await this.qqToLol(); + lol = arrTemp3?.id; + area = lol ? arrTemp3?.area : null; + } else { + const arrTemp3 = await this.lolToQq(); + if (arrTemp3) { + qq = arrTemp3.qq; + area = arrTemp3.area; + const arrTemp4 = await this.qqToPhone(); + if (arrTemp4) { + phone = arrTemp4.phone; + location = arrTemp4.location; + } + this.message = qq!; + qqOldPass = await this.qqToOldPass(); + } + } } - }; + } + return { qq, lol, phone, qqOldPass, location, area, weibo }; } } -const sed = new Sed(); - -sed.sedQuery().then((res) => { - // 处理结果 -}); +export default Sed; diff --git a/packages/core/src/service/adapter.ts b/packages/core/src/service/adapter.ts index e501eec4..797ebb7e 100644 --- a/packages/core/src/service/adapter.ts +++ b/packages/core/src/service/adapter.ts @@ -79,7 +79,7 @@ function formatFactory(i18n: I18n) { return (template: string, data: Record | CommandArgType[]) => { const params = data; if (Array.isArray(params)) { - let str = template; + let str = i18n.locale(template); params.forEach((value, index) => { str = str.replaceAll(`{${index}}`, i18n.locale(typeof value === 'string' ? value : String(value))); }); diff --git a/packages/loader/src/loader.ts b/packages/loader/src/loader.ts index ccab57ee..36582f9c 100644 --- a/packages/loader/src/loader.ts +++ b/packages/loader/src/loader.ts @@ -3,7 +3,7 @@ * @Blog: https://hotaru.icu * @Date: 2023-06-24 15:12:55 * @LastEditors: Hotaru biyuehuya@gmail.com - * @LastEditTime: 2024-02-08 21:35:56 + * @LastEditTime: 2024-02-10 19:47:05 */ import { KotoriError, @@ -16,8 +16,7 @@ import { loadConfig, TsuError, Core, - Context, - Service + Context } from '@kotori-bot/core'; import path from 'path'; import fs from 'fs'; @@ -162,7 +161,9 @@ export class Loader extends Container { ModuleError: () => this.ctx.logger.label('module').error, UnknownError: () => this.ctx.logger.error, DevError: () => this.ctx.logger.label('error').debug - })[err.name]()(err.message, err.stack); + }) + [err.name]() + .bind(this.ctx.logger)(err.message, err.stack); } private catchError() { diff --git a/packages/loader/src/runner.ts b/packages/loader/src/runner.ts index c27aa804..a6c5d0aa 100644 --- a/packages/loader/src/runner.ts +++ b/packages/loader/src/runner.ts @@ -39,7 +39,7 @@ export const localeTypeSchema = Tsu.Union([ ]); const modulePackageSchema = Tsu.Object({ - name: Tsu.String().regexp(/kotori-plugin-[a-z]([a-z,0-9]{3,13})\b/), + name: Tsu.String().regexp(/kotori-plugin-[a-z]([a-z,0-9]{2,13})\b/), version: Tsu.String(), description: Tsu.String(), main: Tsu.String(), diff --git a/packages/logger/src/index.ts b/packages/logger/src/index.ts index 5a162932..36e3d194 100644 --- a/packages/logger/src/index.ts +++ b/packages/logger/src/index.ts @@ -3,7 +3,7 @@ * @Blog: https://hotaru.icu * @Date: 2024-02-07 13:44:38 * @LastEditors: Hotaru biyuehuya@gmail.com - * @LastEditTime: 2024-02-07 14:47:52 + * @LastEditTime: 2024-02-10 19:59:11 */ import type { LoggerData, LoggerFilter, LoggerOptions } from './types/internal'; import { LoggerLevel } from './types/common';