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