Skip to content

Commit

Permalink
fix: loader catch error
Browse files Browse the repository at this point in the history
  • Loading branch information
BIYUEHU committed Feb 10, 2024
1 parent 24b6549 commit d1914be
Show file tree
Hide file tree
Showing 26 changed files with 226 additions and 200 deletions.
Binary file modified kotori.db
Binary file not shown.
64 changes: 34 additions & 30 deletions modules/bangumi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,39 +58,43 @@ export const lang = [__dirname, '../locales'];
export const inject = ['cache'];

export function main(ctx: Context) {
ctx.command('bgm <content> [order:number=1] - bangumi.descr.bgm').action(async (data, session) => {
const prop = `bgm_${data.args[0]}`;
const res =
ctx.cache.get<Tsu.infer<typeof bgm1Schema>>(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<Tsu.infer<typeof bgm1Schema>>(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`));
Expand Down
8 changes: 4 additions & 4 deletions modules/github/locales/en_US.json
Original file line number Diff line number Diff line change
@@ -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%"
}
8 changes: 4 additions & 4 deletions modules/github/locales/ja_JP.json
Original file line number Diff line number Diff line change
@@ -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%"
}
8 changes: 4 additions & 4 deletions modules/github/locales/zh_CN.json
Original file line number Diff line number Diff line change
@@ -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%"
}
8 changes: 4 additions & 4 deletions modules/github/locales/zh_TW.json
Original file line number Diff line number Diff line change
@@ -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%"
}
6 changes: 3 additions & 3 deletions modules/github/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ const githubSchema = Tsu.Union([
export const lang = [__dirname, '../locales'];

export function main(ctx: Context) {
ctx.command('github <repository> - querytool.descr.github').action(async (data, session) => {
ctx.command('github <repository> - 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',
Expand Down
15 changes: 8 additions & 7 deletions modules/goodnight/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions modules/i18n-command/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
4 changes: 2 additions & 2 deletions modules/newnew/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 (≧_ ≦)"
}
4 changes: 2 additions & 2 deletions modules/newnew/locales/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "現在データがありません(≧_ ≦)"
}
6 changes: 3 additions & 3 deletions modules/newnew/locales/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "当前还没有数据噢~(≧﹏ ≦)"
}
6 changes: 3 additions & 3 deletions modules/newnew/locales/zh_TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "當前還沒有數據噢~(≧﹏ ≦)"
}
20 changes: 12 additions & 8 deletions modules/newnew/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Blog: https://hotaru.icu
* @Date: 2023-07-30 11:33:15
* @LastEditors: Hotaru [email protected]
* @LastEditTime: 2024-02-10 11:38:20
* @LastEditTime: 2024-02-10 20:25:58
*/
import { Context, Tsu } from 'kotori-bot';

Expand Down Expand Up @@ -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]]
];
});

Expand All @@ -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;
Expand All @@ -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]];
Expand Down
4 changes: 0 additions & 4 deletions modules/random-img/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 9 additions & 9 deletions modules/sed/locales/en_US.json
Original file line number Diff line number Diff line change
@@ -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}"
}
18 changes: 9 additions & 9 deletions modules/sed/locales/ja_JP.json
Original file line number Diff line number Diff line change
@@ -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}"
}
18 changes: 9 additions & 9 deletions modules/sed/locales/zh_CN.json
Original file line number Diff line number Diff line change
@@ -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}"
}
Loading

0 comments on commit d1914be

Please sign in to comment.