Commit 8f8f299f authored by nanahira's avatar nanahira

bump to Koishi 4.8

parent 5cbeb9ff
import { App } from 'koishi';
import { Context } from 'koishi';
import TargetPlugin from '../src';
import ConsolePlugin from '@koishijs/plugin-console';
import SandboxPlugin from '@koishijs/plugin-sandbox';
import * as DatabasePlugin from '@koishijs/plugin-database-memory';
import CachePlugin from '@koishijs/plugin-cache-lru';
import DatabasePlugin from '@koishijs/plugin-database-memory';
import CachePlugin from 'koishi-plugin-cache-aragami';
import ExtrasInDev from './extras';
const app = new App({
const app = new Context({
port: 14514,
host: 'localhost',
prefix: '.',
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -21,7 +21,7 @@
"qqbot",
"cqhttp",
"onebot",
"required:cache",
"required:cache-aragami",
"market:hidden"
],
"bugs": {
......@@ -29,22 +29,23 @@
},
"homepage": "https://code.mycard.moe/3rdeye/koishi-plugin-order-picker",
"dependencies": {
"koishi-thirdeye": "^10.3.2",
"koishi-thirdeye": "^11.0.6",
"moment": "^2.29.1"
},
"devDependencies": {
"@koishijs/plugin-cache-lru": "^1.0.0-rc.0",
"@koishijs/plugin-console": "^3.3.2",
"@koishijs/plugin-database-memory": "^1.3.0",
"@koishijs/plugin-sandbox": "^1.1.3",
"@koishijs/plugin-console": "^4.1.1",
"@koishijs/plugin-database-memory": "^1.4.1",
"@koishijs/plugin-sandbox": "^2.0.1",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.2",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"esbuild-loader": "^2.19.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^3.4.1",
"jest": "^27.5.1",
"koishi-plugin-cache-aragami": "^1.0.4",
"prettier": "^2.5.1",
"raw-loader": "^4.0.2",
"ts-jest": "^27.1.3",
......@@ -56,7 +57,8 @@
"ws": "^8.4.0"
},
"peerDependencies": {
"koishi": "^4.7.5"
"koishi": "^4.8.2",
"koishi-plugin-cache-aragami": "^1.0.4"
},
"jest": {
"moduleFileExtensions": [
......
// import 'source-map-support/register';
import { Context, Cache, Session, Next, Bot, segment } from 'koishi';
import { Context, Session, Next, segment } from 'koishi';
import { OrderPickerConfig, OrderPickerConfigLike } from './config';
import {
DefinePlugin,
......@@ -8,44 +8,39 @@ import {
UseMiddleware,
OnGuild,
OnPlatform,
OnApply,
LifecycleEvents,
} from 'koishi-thirdeye';
import moment from 'moment';
export * from './config';
import AragamiPlugin, { CacheKey } from 'koishi-plugin-cache-aragami';
export interface PickedOrderInfo {
export class PickedOrderInfo {
sourceGuildId: string;
@CacheKey()
sourceUserId: string;
sourceUserName: string;
description: string;
time: number;
}
declare module 'koishi' {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace Cache {
interface Tables {
orderPickerOnline: boolean;
pickedOrderInfo: PickedOrderInfo;
}
}
export class SelfOnline {
@CacheKey()
selfId: string;
online: boolean;
}
@OnPlatform('onebot')
@DefinePlugin({ name: 'order-picker', schema: OrderPickerConfig })
export default class OrderPicker implements OnApply {
export default class OrderPicker implements LifecycleEvents {
constructor(private ctx: Context, config: OrderPickerConfigLike) {}
@InjectConfig()
private config: OrderPickerConfig;
@Inject(true)
private cache: Cache;
private aragami: AragamiPlugin;
onApply() {
this.cache.table('orderPickerOnline', {});
this.cache.table('pickedOrderInfo', {
maxAge: 1000 * 60 * this.config.cooldown,
});
const cmd = this.ctx
.private(this.config.masterId)
.command('order-picker', '抢单管理');
......@@ -108,23 +103,26 @@ export default class OrderPicker implements OnApply {
}
private async getLastInfo(selfId: string) {
return this.cache.get('pickedOrderInfo', selfId);
return this.aragami.get(PickedOrderInfo, selfId);
}
private async setLastInfo(selfId: string, info: PickedOrderInfo) {
return this.cache.set('pickedOrderInfo', selfId, info);
return this.aragami.set(PickedOrderInfo, info, {
ttl: this.config.cooldown * 60 * 1000,
});
}
private async removeLastInfo(selfId: string) {
return this.cache.del('pickedOrderInfo', selfId);
return this.aragami.del(PickedOrderInfo, selfId);
}
private async isOnline(selfId: string) {
return this.cache.get('orderPickerOnline', selfId);
const online = await this.aragami.get(SelfOnline, selfId);
return !!online?.online;
}
private async setOnline(selfId: string, online: boolean) {
return this.cache.set('orderPickerOnline', selfId, online);
await this.aragami.set(SelfOnline, { selfId, online });
}
@OnGuild()
......
import { App } from 'koishi';
import { Context } from 'koishi';
import TargetPlugin from '../src';
describe('Test of plugin.', () => {
let app: App;
let app: Context;
beforeEach(async () => {
app = new App();
app = new Context();
// app.plugin(TargetPlugin);
await app.start();
});
......
const path = require('path');
const packgeInfo = require('./package.json');
const { ESBuildMinifyPlugin } = require('esbuild-loader');
function externalsFromDep() {
return Object.fromEntries(
......@@ -43,4 +44,11 @@ module.exports = {
koishi: 'koishi',
...(packAll ? {} : externalsFromDep()),
},
optimization: {
minimizer: [
new ESBuildMinifyPlugin({
keepNames: true,
}),
],
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment