Commit f65b1b33 authored by nanahira's avatar nanahira

bump to Koishi 4.8

parent 1345f6f0
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.
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
"Koishi.js", "Koishi.js",
"qqbot", "qqbot",
"cqhttp", "cqhttp",
"required:cache", "required:cache-aragami",
"market:hidden" "market:hidden"
], ],
"bugs": { "bugs": {
...@@ -30,22 +30,22 @@ ...@@ -30,22 +30,22 @@
"dependencies": { "dependencies": {
"crypto-random-string": "^3.3.1", "crypto-random-string": "^3.3.1",
"ip": "^1.1.5", "ip": "^1.1.5",
"koishi-thirdeye": "^10.3.2", "koishi-thirdeye": "^11.0.6",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"moment": "^2.29.1", "moment": "^2.29.1",
"tesseract.js": "^2.1.5" "tesseract.js": "^2.1.5"
}, },
"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/ip": "^1.1.0", "@types/ip": "^1.1.0",
"@types/jest": "^27.4.0", "@types/jest": "^27.4.0",
"@types/lodash": "^4.14.177", "@types/lodash": "^4.14.177",
"@types/node": "^16.11.9", "@types/node": "^16.11.9",
"@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",
...@@ -61,7 +61,8 @@ ...@@ -61,7 +61,8 @@
"ws": "^8.3.0" "ws": "^8.3.0"
}, },
"peerDependencies": { "peerDependencies": {
"koishi": "^4.7.5" "koishi": "^4.8.2",
"koishi-plugin-cache-aragami": "^1.0.4"
}, },
"jest": { "jest": {
"moduleFileExtensions": [ "moduleFileExtensions": [
......
...@@ -36,7 +36,7 @@ export class HisoutensokuJammerPluginConfig { ...@@ -36,7 +36,7 @@ export class HisoutensokuJammerPluginConfig {
} }
try { try {
const worker = createWorker({ const worker = createWorker({
logger: (m) => logger.debug(m), logger: (m) => logger.info(m),
//dataPath: path.join(__dirname, '..', 'lang-data'), //dataPath: path.join(__dirname, '..', 'lang-data'),
...(this.ocrExtraOptions || {}), ...(this.ocrExtraOptions || {}),
}); });
......
// import 'source-map-support/register'; // import 'source-map-support/register';
import { Logger, Next, Session, Cache, segment } from 'koishi'; import { Logger, Next, Session, segment } from 'koishi';
import { HisoutensokuJammerPluginConfig } from './config'; import { HisoutensokuJammerPluginConfig } from './config';
import { import {
DefinePlugin, DefinePlugin,
...@@ -7,8 +7,7 @@ import { ...@@ -7,8 +7,7 @@ import {
InjectLogger, InjectLogger,
Inject, Inject,
UseEvent, UseEvent,
OnApply, StarterPlugin,
BasePlugin,
} from 'koishi-thirdeye'; } from 'koishi-thirdeye';
import { Attacker } from './attacker'; import { Attacker } from './attacker';
import moment from 'moment'; import moment from 'moment';
...@@ -16,15 +15,14 @@ import { chineseCharacterList } from './chinese-replace'; ...@@ -16,15 +15,14 @@ import { chineseCharacterList } from './chinese-replace';
import { Worker } from 'tesseract.js'; import { Worker } from 'tesseract.js';
import _ from 'lodash'; import _ from 'lodash';
import { recursiveMatch } from './utils'; import { recursiveMatch } from './utils';
import AragamiPlugin, { CacheKey, CacheTTL } from 'koishi-plugin-cache-aragami';
export * from './config'; export * from './config';
declare module 'koishi' { @CacheTTL(600000)
// eslint-disable-next-line @typescript-eslint/no-namespace class LastMessage {
namespace Cache { @CacheKey()
interface Tables { sender: string;
lastMessages: string; message: string;
}
}
} }
const matcherSingle = const matcherSingle =
...@@ -36,19 +34,14 @@ const PROTOCOL_BASE64 = 'base64://'; ...@@ -36,19 +34,14 @@ const PROTOCOL_BASE64 = 'base64://';
name: 'hisoutensoku-jammer', name: 'hisoutensoku-jammer',
schema: HisoutensokuJammerPluginConfig, schema: HisoutensokuJammerPluginConfig,
}) })
export default class HisoutensokuJammerPlugin export default class HisoutensokuJammerPlugin extends StarterPlugin(
extends BasePlugin<HisoutensokuJammerPluginConfig> HisoutensokuJammerPluginConfig,
implements OnApply ) {
{
@InjectLogger() @InjectLogger()
private log: Logger; private log: Logger;
@Inject('cache', true) @Inject(true)
private cache: Cache; private aragami: AragamiPlugin;
onApply() {
this.cache.table('lastMessages', { maxAge: 600000 });
}
ocrWorker: Worker; ocrWorker: Worker;
...@@ -155,20 +148,23 @@ export default class HisoutensokuJammerPlugin ...@@ -155,20 +148,23 @@ export default class HisoutensokuJammerPlugin
let messageMatch = recursiveMatch(receivedMessage, matcherSingle); let messageMatch = recursiveMatch(receivedMessage, matcherSingle);
if (useCache) { if (useCache) {
const lastMessage = await this.cache.get('lastMessages', sender); const lastMessage = await this.aragami.get(LastMessage, sender);
const currentMessage = receivedMessage; const currentMessage = receivedMessage;
if (lastMessage) { if (lastMessage) {
receivedMessage = `${lastMessage} ${receivedMessage}`; receivedMessage = `${lastMessage.message} ${receivedMessage}`;
this.log.info(`Merged message from ${sender}: ${receivedMessage}`); this.log.info(`Merged message from ${sender}: ${receivedMessage}`);
if (!messageMatch) { if (!messageMatch) {
messageMatch = recursiveMatch(receivedMessage, matcherSingle); messageMatch = recursiveMatch(receivedMessage, matcherSingle);
} }
} }
if (!messageMatch) { if (!messageMatch) {
await this.cache.set('lastMessages', sender, currentMessage); const message = new LastMessage();
message.sender = sender;
message.message = currentMessage;
await this.aragami.set(message);
return; return;
} }
await this.cache.del('lastMessages', sender); await this.aragami.del(LastMessage, sender);
} else if (!messageMatch) { } else if (!messageMatch) {
return; return;
} }
......
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