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