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