Commit 0c179c8e authored by nanahira's avatar nanahira

migrate

parent eba8d3b3
Pipeline #6083 failed with stages
in 1 minute and 2 seconds
......@@ -14,14 +14,13 @@ npm install koishi-plugin-hisoutensoku-jammer
### 直接安装
在 https://cdn01.moecube.com/nanahira/koishi-plugin/hisoutensoku-jammer/index.js 下载,并配置 `koishi.config.js`
在 https://cdn02.moecube.com:444/nanahira/koishi-plugin/hisoutensoku-jammer/index.js 下载,并配置 `koishi.config.js`
```js
module.exports = {
plugins: {
"/path/to/hisoutensoku-jammer/index.js": {
target: (ctx) => ctx.all(),
attackTimeout: 10000,
addressWhitelist: []
}
}
......@@ -32,16 +31,12 @@ module.exports = {
```ts
const defaultConfig: HisoutensokuJammerConfig = {
target: (ctx: Context) => ctx.all(),
attackTimeout: 10000,
addressWhitelist: [],
};
```
### 说明
* `target` 一个上下文函数,决定作用域。如 `(ctx) => ctx.group('1111111111')` 为只对群 1111111111 有效。
* `attackTimeout` 每次的干扰时长,单位 ms 。
* `addressWhitelist` IP 白名单列表。白名单的 IP 地址不会被干扰。
\ No newline at end of file
* `addressWhitelist` IP 白名单列表。白名单的 IP 地址不会被干扰。
This diff is collapsed.
{
"name": "koishi-plugin-hisoutensoku-jammer",
"version": "1.1.10",
"version": "2.0.0",
"description": "A Koishi Plugin jamming hisoutensoku plays in group.",
"main": "dist/index.js",
"dependencies": {
"lodash": "^4.17.21",
"source-map-support": "^0.5.19"
},
"devDependencies": {
"@types/lodash": "^4.14.168",
"@types/lodash": "^4.14.175",
"@types/node": "^15.0.1",
"koishi-core": "^3.13.0",
"koishi-utils": "^4.2.3",
"lodash": "^4.17.21",
"koishi": "^4.0.0-alpha.8",
"moment": "^2.29.1",
"raw-loader": "^4.0.2",
"ts-loader": "^9.1.1",
......
import type { Context } from "koishi-core";
import _, { last } from "lodash";
import "source-map-support/register";
import type { Logger } from "koishi-utils";
import { Logger, Context, Schema } from "koishi";
import { Attacker } from "./attacker";
import moment from "moment";
export interface HisoutensokuJammerConfig {
target: (ctx: Context) => Context;
attackTimeout: number;
addressWhitelist: string[];
}
const defaultConfig: HisoutensokuJammerConfig = {
target: (ctx: Context) => ctx.all(),
attackTimeout: 10000,
addressWhitelist: [],
};
const chineseCharacterList = [
{ character: '', value: 0 },
{ character: '', value: 0 },
......@@ -58,12 +48,11 @@ class HisoutensokuJammer {
targetCtx: Context;
lastMessageMap = new Map<string, string>();
constructor(private ctx: Context, private config: HisoutensokuJammerConfig) {
this.targetCtx = config.target(ctx);
this.log = ctx.logger("hisoutensoku-jammer");
}
apply() {
this.targetCtx.middleware(async (session, next) => {
this.ctx.middleware(async (session, next) => {
const sender = session.userId;
const message = session.content;
this.handleMessage(message, sender).then();
......@@ -129,13 +118,14 @@ class HisoutensokuJammer {
}
export const name = "hisoutensoku-jammer";
export const schema: Schema<HisoutensokuJammerConfig> = Schema.object({
attackTimeout: Schema.number('干扰时间。').default(10000),
addressWhitelist: Schema.array(Schema.string(), 'IP 白名单').default([])
})
export function apply(
ctx: Context,
config: HisoutensokuJammerConfig = defaultConfig
config: HisoutensokuJammerConfig
) {
const hisoutensokuJammer = new HisoutensokuJammer(ctx, {
...defaultConfig,
...config,
});
const hisoutensokuJammer = new HisoutensokuJammer(ctx, Schema.validate(config, schema));
hisoutensokuJammer.apply();
}
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