Commit be12e428 authored by nanahira's avatar nanahira

rewrite with koishi.js

parent 877d1308
...@@ -103,10 +103,11 @@ dist ...@@ -103,10 +103,11 @@ dist
# TernJS port file # TernJS port file
.tern-port .tern-port
/*.js /build
/config.yaml /output
/*.txt
.git*
.dockerignore .dockerignore
.gitignore
Dockerfile Dockerfile
.gitlab-ci.yml
/config.yaml
...@@ -103,7 +103,6 @@ dist ...@@ -103,7 +103,6 @@ dist
# TernJS port file # TernJS port file
.tern-port .tern-port
/*.js /build
/output
/config.yaml /config.yaml
/*.txt
/*.js.map
FROM node:buster-slim FROM node:buster-slim
RUN npm -g install typescript RUN apt update && apt -y install python3 build-essential && rm -rf /var/lib/apt/lists/*
RUN apt update && \
apt -y install build-essential python3 && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /usr/src/app WORKDIR /usr/src/app
COPY package*.json ./ COPY ./package*.json ./
RUN npm ci RUN npm ci
COPY . ./ COPY . ./
RUN npm run build RUN npm run build
CMD ["npm", "run", "start"] CMD ["npm", "run", "start"]
This diff is collapsed.
...@@ -20,8 +20,11 @@ This project may possibly be working only with Hisoutensoku ver 1.10a. Versions ...@@ -20,8 +20,11 @@ This project may possibly be working only with Hisoutensoku ver 1.10a. Versions
```yaml ```yaml
coolq: # CoolQ config. The docker-compose config below meets this configuration. coolq: # CoolQ config. The docker-compose config below meets this configuration.
host: coolq type: ws
qq: 1111111111 # Your QQ account here server: coolq
selfId: 1111111111 # Your QQ account here
token: qweqwe
secret: asdasd
attackTimeout: 10000 # The timeout the fake clients would wait for connection. attackTimeout: 10000 # The timeout the fake clients would wait for connection.
floodQQGroups: # Target QQ groups floodQQGroups: # Target QQ groups
- 111111111 - 111111111
...@@ -42,6 +45,8 @@ services: ...@@ -42,6 +45,8 @@ services:
environment: environment:
UIN: 1111111111 # Your QQ account here UIN: 1111111111 # Your QQ account here
PASS: aaaaaaaaa # Your QQ password here PASS: aaaaaaaaa # Your QQ password here
ACCESS_TOKEN: qweqwe
SECRET: asdasd
terminator: terminator:
restart: always restart: always
image: nanahira/hisoutensoku-terminator image: nanahira/hisoutensoku-terminator
......
This diff is collapsed.
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"description": "I hate hisoutensoku", "description": "I hate hisoutensoku",
"main": "run.js", "main": "run.js",
"scripts": { "scripts": {
"build": "tsc", "build": "./node_modules/.bin/tsc",
"start": "node run.js" "start": "node build/run.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
"@types/underscore": "^1.10.0", "@types/underscore": "^1.10.0",
"@types/yaml": "^1.9.7", "@types/yaml": "^1.9.7",
"bunyan": "^1.8.12", "bunyan": "^1.8.12",
"cq-websocket": "^2.1.1", "koishi": "^1.12.0",
"moment": "^2.26.0", "moment": "^2.26.0",
"udp-proxy": "^1.2.0", "udp-proxy": "^1.2.0",
"underscore": "^1.10.2", "underscore": "^1.10.2",
......
...@@ -6,18 +6,12 @@ import yaml from "yaml"; ...@@ -6,18 +6,12 @@ import yaml from "yaml";
import { spawn } from "child_process"; import { spawn } from "child_process";
import { Attacker } from "./attacker"; import { Attacker } from "./attacker";
import moment from "moment"; import moment from "moment";
import {AppConfig, App, Meta} from "koishi";
interface CoolQConfig {
host: string;
port: number;
qq: number;
accessToken: string;
}
interface Config { interface Config {
address: string; address: string;
port: number; port: number;
coolq: CoolQConfig; coolq: AppConfig;
floodQQGroups: Array<number>; floodQQGroups: Array<number>;
attackTimeout: number; attackTimeout: number;
addressWhitelist: string[]; addressWhitelist: string[];
...@@ -27,13 +21,7 @@ const log = bunyan.createLogger({ ...@@ -27,13 +21,7 @@ const log = bunyan.createLogger({
name: "hisoutensoku-terminator" name: "hisoutensoku-terminator"
}); });
let CoolQ: CQWebSocket, config: Config; let app: App, config: Config;
function sleep(time: number): Promise<void> {
return new Promise((resolve, reject) => {
setTimeout(resolve, time);
});
};
async function startAttack(address: string, port: number): Promise<boolean> { async function startAttack(address: string, port: number): Promise<boolean> {
if (_.contains(config.addressWhitelist, address)) { if (_.contains(config.addressWhitelist, address)) {
...@@ -60,11 +48,7 @@ async function startAttack(address: string, port: number): Promise<boolean> { ...@@ -60,11 +48,7 @@ async function startAttack(address: string, port: number): Promise<boolean> {
return true; return true;
} }
async function messageHandler(event: CQEvent, data: any, tags: CQTag[]): Promise<void> { async function messageHandler(data: Meta<"message">): Promise<void> {
const groupID: number = data.group_id;
if (!groupID || !_.contains(config.floodQQGroups, groupID)) {
return;
}
const messageMatch: RegExpMatchArray = data.message.match(/(\d{1,3}([\.: \uff1a]\d{1,3}){3})[\.: \uff1a]+(\d{4,5})/g); const messageMatch: RegExpMatchArray = data.message.match(/(\d{1,3}([\.: \uff1a]\d{1,3}){3})[\.: \uff1a]+(\d{4,5})/g);
if (!messageMatch) { if (!messageMatch) {
return; return;
...@@ -75,25 +59,13 @@ async function messageHandler(event: CQEvent, data: any, tags: CQTag[]): Promise ...@@ -75,25 +59,13 @@ async function messageHandler(event: CQEvent, data: any, tags: CQTag[]): Promise
const port = parseInt(patternArray[patternArray.length - 1]); const port = parseInt(patternArray[patternArray.length - 1]);
return startAttack(address, port); return startAttack(address, port);
}); });
const results: boolean[] = await Promise.all(attackPromises); const results: boolean[] = await Promise.all(attackPromises);
} }
async function main(): Promise<void> { async function main(): Promise<void> {
config = yaml.parse(await fs.promises.readFile("./config.yaml", "utf8")) as Config; config = yaml.parse(await fs.promises.readFile("./config.yaml", "utf8")) as Config;
CoolQ = new CQWebSocket(config.coolq); app = new App(config.coolq);
CoolQ.on("ready", async () => { app.group(...config.floodQQGroups).receiver.on("message", messageHandler);
log.info("bot init finished."); await app.start();
});
CoolQ.on("error", async (err) => {
log.warn("bot error", err.toString());
});
CoolQ.on("socket.error", async (err) => {
log.warn("bot socket error", err.toString());
});
CoolQ.on("socket.close", async (err) => {
log.warn("bot socket close", err.toString());
});
CoolQ.on("message", messageHandler);
CoolQ.connect();
} }
main(); main();
{ {
"compilerOptions": { "compilerOptions": {
"outDir": "build",
"module": "commonjs", "module": "commonjs",
"target": "esnext", "target": "esnext",
"esModuleInterop": true, "esModuleInterop": 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