Skip to content

Commit

Permalink
fix: update service content
Browse files Browse the repository at this point in the history
  • Loading branch information
BIYUEHU committed Feb 9, 2024
1 parent 536a6b9 commit dd7f912
Show file tree
Hide file tree
Showing 32 changed files with 248 additions and 364 deletions.
Binary file modified kotori.db
Binary file not shown.
9 changes: 5 additions & 4 deletions modules/adapter-onebot/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @Blog: https://hotaru.icu
* @Date: 2023-09-29 14:31:09
* @LastEditors: Hotaru biyuehuya@gmail.com
* @LastEditTime: 2024-02-08 18:31:53
* @LastEditTime: 2024-02-09 21:37:40
*/
import { Adapter, AdapterConfig, Context, EventDataApiBase, EventDataTargetId, MessageScope, Tsu } from 'kotori-bot';
import WebSocket from 'ws';
Expand All @@ -27,7 +27,9 @@ declare module 'kotori-bot' {
export const config = Tsu.Intersection([
Tsu.Object({
port: Tsu.Number().int().range(1, 65535),
address: Tsu.String().regexp(/^ws(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/),
address: Tsu.String()
.regexp(/^ws(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)
.default('ws://127.0.0.1'),
retry: Tsu.Number().int().min(1).default(10)
}),
Tsu.Union([
Expand All @@ -50,7 +52,7 @@ export class OnebotAdapter extends Adapter {
constructor(ctx: Context, config: OnebotConfig, identity: string) {
super(ctx, config, identity, OnebotApi, new OnebotElements());
this.config = config;
this.address = `${this.config.address}:${this.config.port}`;
this.address = `${this.config.address ?? 'ws://127.0.0.1'}:${this.config.port}`;
}

handle(data: EventDataType) {
Expand Down Expand Up @@ -100,7 +102,6 @@ export class OnebotAdapter extends Adapter {
} else if (data.post_type === 'request' && data.request_type === 'private') {
this.session('on_request', {
type: MessageScope.PRIVATE,

userId: data.user_id
});
} else if (data.post_type === 'request' && data.request_type === 'group') {
Expand Down
6 changes: 3 additions & 3 deletions modules/adapter-qq/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* @Blog: https://hotaru.icu
* @Date: 2023-09-29 14:31:09
* @LastEditors: Hotaru biyuehuya@gmail.com
* @LastEditTime: 2024-02-08 18:33:57
* @LastEditTime: 2024-02-09 21:17:42
*/
import { Adapter, AdapterConfig, Context, MessageScope, Tsu, obj } from 'kotori-bot';
import { Adapter, AdapterConfig, Context, MessageScope, Tsu } from 'kotori-bot';
import WebSocket from 'ws';
import QQApi from './api';
import { PlayloadData } from './types';
Expand Down Expand Up @@ -111,7 +111,7 @@ export class QQAdapter extends Adapter<QQApi> {
}
let address = '/';
let cancel = false;
let req: obj = {};
let req: Record<string, any> = {};
if (action === 'send_group_msg' && 'groupId' in params && 'message' in params && 'id' in params) {
if (!params.message) return null;
address += `groups/${params.groupId}/messages`;
Expand Down
6 changes: 3 additions & 3 deletions modules/bangumi/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, Tsu, stringTemp } from 'kotori-bot';
import { Context, Tsu } from 'kotori-bot';
import http from './http';

const bgm1Schema = Tsu.Object({
Expand Down Expand Up @@ -68,7 +68,7 @@ export function main(ctx: Context) {
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 += stringTemp(session.i18n.locale('bangumi.msg.bgm.list'), {
list += session.format('bangumi.msg.bgm.list', {
...result,
num: init + 1
});
Expand Down Expand Up @@ -102,7 +102,7 @@ export function main(ctx: Context) {
let list = '';
for (let init = 0; init < 3; init += 1) {
const item = items[init];
list += stringTemp(session.i18n.locale('bangumi.msg.bgmc.list'), {
list += session.format('bangumi.msg.bgmc.list', {
name: item.name,
name_cn: item.name_cn,
air_date: item.air_date,
Expand Down
10 changes: 6 additions & 4 deletions modules/better-join/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Context, EventsList, getRandomInt, stringTemp } from 'kotori-bot';
import { Context, EventsList, getRandomInt } from 'kotori-bot';
import data from './data';

export class Main {
constructor(Ctx: Context) {
Ctx.on('on_group_increase', (data) => Main.handle(data));
constructor(ctx: Context) {
ctx.on('on_group_increase', (data) => Main.handle(data));
}

private static handle(session: EventsList['on_group_increase']) {
const standard = getRandomInt(0, 2);
for (let init = 0; init < standard; init += 1) {
session.send(stringTemp(data[getRandomInt(0, Object.keys(data).length)], { at: session.el.at(session.userId) }));
session.send(
session.format(data[getRandomInt(0, Object.keys(data).length)], { at: session.el.at(session.userId) })
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/bilibili/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, Tsu, formatTime } from 'kotori-bot';
import { Context, Tsu } from 'kotori-bot';

const biliSchema = Tsu.Object({
data: Tsu.Object({
Expand Down Expand Up @@ -43,7 +43,7 @@ export function main(ctx: Context) {
'bilibili.msg.bili',
{
...res.data,
time: formatTime(new Date(res.data.time)),
time: session.i18n.time(res.data.time),
image: session.el.image(res.data.cover)
}
];
Expand Down
24 changes: 12 additions & 12 deletions modules/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* @Blog: https://hotaru.icu
* @Date: 2023-07-11 14:18:27
* @LastEditors: Hotaru biyuehuya@gmail.com
* @LastEditTime: 2024-02-06 20:01:48
* @LastEditTime: 2024-02-09 21:33:48
*/

import { Context, Symbols, formatTime, stringTemp } from 'kotori-bot';
import { Context, Symbols } from 'kotori-bot';

export const lang = [__dirname, '../locales'];

export function main(ctx: Context) {
ctx.command('core - core.descr.core').action((_, events) => {
const { config, baseDir, options } = events.api.adapter.ctx;
ctx.command('core - core.descr.core').action((_, session) => {
const { config, baseDir, options } = session.api.adapter.ctx;
let botsLength = 0;
ctx[Symbols.bot].forEach((bots) =>
bots.forEach(() => {
Expand All @@ -35,30 +35,30 @@ export function main(ctx: Context) {
];
});

ctx.command('bot - core.descr.bot').action((_, events) => {
const { identity, platform, selfId, config, status } = events.api.adapter;
ctx.command('bot - core.descr.bot').action((_, session) => {
const { identity, platform, selfId, config, status } = session.api.adapter;
return [
'core.msg.bot',
{
identity,
lang: config.lang,
platform,
self_id: selfId,
create_time: formatTime(status.createTime),
last_msg_time: formatTime(status.lastMsgTime),
create_time: session.i18n.time(status.createTime),
last_msg_time: status.lastMsgTime ? session.i18n.time(status.lastMsgTime) : '',
received_msg: status.receivedMsg,
sent_msg: status.sentMsg,
offline_times: status.offlineTimes
}
];
});

ctx.command('bots - core.descr.bots').action((_, events) => {
ctx.command('bots - core.descr.bots').action((_, session) => {
let list = '';
ctx[Symbols.bot].forEach((bots) =>
bots.forEach((bot) => {
const { identity, platform, config, status } = bot.adapter;
list += stringTemp(events.i18n.locale('core.msg.bots.list'), {
list += session.format('core.msg.bots.list', {
identity,
lang: config.lang,
platform,
Expand All @@ -69,8 +69,8 @@ export function main(ctx: Context) {
return ['core.msg.bots', { list }];
});

ctx.command('about - core.descr.about').action((_, events) => {
const { version, license } = events.api.adapter.ctx.pkg;
ctx.command('about - core.descr.about').action((_, session) => {
const { version, license } = session.api.adapter.ctx.pkg;
return ['core.msg.about', { version, license, node_version: process.version }];
});
}
2 changes: 1 addition & 1 deletion modules/goodnight/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kotori-plugin-goodnight",
"version": "1.2.0",
"version": "1.3.0",
"description": "And in case i don't see you,good afternoon,good evening,and good night!",
"main": "lib/index.js",
"scripts": {
Expand Down
8 changes: 0 additions & 8 deletions modules/goodnight/src/config.ts

This file was deleted.

134 changes: 73 additions & 61 deletions modules/goodnight/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,84 @@
import { Context } from 'kotori-bot';
import { Context, Tsu, getRandomInt } from 'kotori-bot';

interface Good {
morning: Record<string, number>;
night: Record<string, number>;
}

export const lang = [__dirname, '../locales'];

export class Main {
/*
private static getTodayPath(yesterday: boolean = false) {
const TIME = new Date();
const date = TIME.getDate();
const time = `${TIME.getFullYear()}-${TIME.getMonth() + 1}-${yesterday ? date - 1 : date}`;
return path.join(Main.Consts.DATA_PLUGIN_PATH, `${time}.json`);
};
private static defaultData: good = { morning: {}, night: {} };
private static loadTodayData(yesterday: boolean = false)
(loadConfig(this.getTodayPath(yesterday), 'json', this.defaultData) as good) || this.defaultData;
private static saveTodayData(data: good) this.saveConfig(this.getTodayPath(), data); */
export const inject = ['file'];

constructor(Ctx: Context) {
Ctx.regexp(
/^(早|早安|早上好)$/,
() => '早安~'
/* const record = loadTodayData();
const at = SDK.cq_at(data.user_id);
if (data.user_id in record.morning) return ['goodnight.msg.morning.already', { at }];
export const config = Tsu.Object({
getupTimeLess: Tsu.Number().default(6),
getupTimeLate: Tsu.Number().default(18),
sleepTimeLess: Tsu.Number().default(3),
sleepTimeLater: Tsu.Tuple([Tsu.Number(), Tsu.Number()]).default([1, 7]),
sleepTimeLate: Tsu.Tuple([Tsu.Number(), Tsu.Number()]).default([23, 1]),
sleepTimeNormal: Tsu.Tuple([Tsu.Number(), Tsu.Number()]).default([20, 23])
});

const hours = new Date().getHours();
if (hours < config.getupTimeLess)
return ['goodnight.msg.morning.early', { at, hour: config.getupTimeLess }];
export type Config = Tsu.infer<typeof config>;

record.morning[data.user_id] = new Date().getTime();
saveTodayData(record);
const count = Object.keys(record.morning).length;
if (count <= 10) addExp(data.group_id!, data.user_id, 15);
if (count > 10 && count <= 20) addExp(data.group_id!, data.user_id, 5);
const sex = getSex(data.sender.sex);
if (hours < 12) return ['goodnight.msg.morning.morning', { at, count, sex }];
if (hours >= 12 && hours < config.getupTimeLate)
return ['goodnight.msg.morning.afternoon', { at, count, sex }];
return ['goodnight.msg.morning.late', { at, count, sex }]; */
);
function getSex(val: string) {
switch (val) {
case 'male':
return 'goodnight.msg.morning.male';
case 'female':
return 'goodnight.msg.morning.female';
default:
return getSex(getRandomInt(1) === 1 ? 'male' : 'femal');
}
}

Ctx.regexp(
/^(晚|晚安|晚上好)$/,
() => '晚安~'
/* const record = loadTodayData();
const at = SDK.cq_at(data.user_id);
if (data.user_id in record.night) return ['goodnight.msg.night.already', { at }];
export function main(ctx: Context, config: Config) {
const getTodayPath = (yesterday: boolean = false) =>
`${new Date().getFullYear()}-${new Date().getMonth() + 1}-${yesterday ? new Date().getDate() - 1 : new Date().getDate()}.json`;
const defaultData: Good = { morning: {}, night: {} };
const loadTodayData = (yesterday: boolean = false) =>
(ctx.file.load(getTodayPath(yesterday), 'json', defaultData) as Good) || defaultData;
const saveTodayData = (data: Good) => ctx.file.save(getTodayPath(), data);

const record2 = loadTodayData(true);
if (!(data.user_id in record.morning) && !(data.user_id in record2.morning))
return ['goodnight.msg.night.not', { at }];
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 nowTime = new Date().getTime();
const timecal = nowTime - (record.morning[data.user_id] || record2.morning[data.user_id]);
if (timecal < config.sleepTimeLess * 60 * 60 * 1000) return ['goodnight.msg.night.less', { at }];
const hours = new Date().getHours();
if (hours < config.getupTimeLess) return ['goodnight.msg.morning.early', { at, hour: config.getupTimeLess }];

record.night[data.user_id] = nowTime;
saveTodayData(record);
const time = formatTime(timecal);
const hours = new Date().getHours();
const { sleepTimeLater: later, sleepTimeLate: late, sleepTimeNormal: normal } = config;
if (hours >= later[0] && hours < later[1]) return ['goodnight.msg.night.later', { at, time }];
if (hours >= late[0] || hours < late[1]) return ['goodnight.msg.night.late', { at, time }];
if (hours >= normal[0] && hours < normal[1]) return ['goodnight.msg.night.normal', { at, time }];
return ['goodnight.msg.night.early', { at, time }]; */
);
}
record.morning[session.userId] = new Date().getTime();
saveTodayData(record);
const count = Object.keys(record.morning).length;
// if (count <= 10) addExp(data.group_id!, session.userId, 15);
// if (count > 10 && count <= 20) addExp(data.group_id!, session.userId, 5);
const sex = getSex(session.sender.sex);
if (hours < 12) return ['goodnight.msg.morning.morning', { at, count, sex }];
if (hours >= 12 && hours < config.getupTimeLate) return ['goodnight.msg.morning.afternoon', { at, count, sex }];
return ['goodnight.msg.morning.late', { at, count, sex }];
});

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 record2 = loadTodayData(true);
if (!(session.userId in record.morning) && !(session.userId 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]);
if (timecal < config.sleepTimeLess * 60 * 60 * 1000) return ['goodnight.msg.night.less', { at }];

record.night[session.userId] = nowTime;
saveTodayData(record);
const time = ctx.i18n.rtime(timecal, 'hours');
const hours = new Date().getHours();
const { sleepTimeLater: later, sleepTimeLate: late, sleepTimeNormal: normal } = config;
if (hours >= later[0] && hours < later[1]) return ['goodnight.msg.night.later', { at, time }];
if (hours >= late[0] || hours < late[1]) return ['goodnight.msg.night.late', { at, time }];
if (hours >= normal[0] && hours < normal[1]) return ['goodnight.msg.night.normal', { at, time }];
return ['goodnight.msg.night.early', { at, time }];
});
}
export default Main;
27 changes: 0 additions & 27 deletions modules/goodnight/src/method.tss

This file was deleted.

6 changes: 0 additions & 6 deletions modules/goodnight/src/type.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit dd7f912

Please sign in to comment.