Skip to content

Commit 9f22630

Browse files
authored
Merge pull request #121 from oof2win2/master
2 parents 85f3429 + b949c88 commit 9f22630

22 files changed

+218
-450
lines changed

pm2.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ module.exports = {
22
apps: [
33
{
44
name: "AwF-Bot",
5-
script: "index.js",
5+
script: "dist/index.js",
66
env: {
77
NODE_ENV: "production",
88
},
9-
watch: ["*"],
9+
watch: ["dist"],
1010
ignore_watch: ["node_modules", ".git"],
1111
},
1212
],

src/base/Comfy.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ import {
1111
TextChannel,
1212
} from "discord.js";
1313
import NodeCache from "node-cache";
14-
import factorioServers, { FactorioServer } from "../servers";
14+
import factorioServers from "../servers";
15+
import {
16+
FactorioServer,
17+
BotConfig as BotConfigType,
18+
BotConfigEmojis,
19+
} from "../types";
1520
import FIFO from "fifo";
1621
import path from "path";
1722
import moment from "moment";
18-
import BotConfig, {
19-
BotConfig as BotConfigType,
20-
BotConfigEmojis,
21-
} from "../config";
23+
// import BotConfig from "../config";
24+
import BotConfig from "../config";
2225
import BotConsts, { BotConsts as BotConstsType } from "../consts";
2326
import { Command } from "./Command";
2427
import BotLogger from "../helpers/logger";

src/base/GrafanaHandler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import config from "../config";
22
import rcon from "../helpers/rcon";
3-
import servers, { FactorioServer } from "../servers";
3+
import servers from "../servers";
4+
import { FactorioServer } from "../types";
45
import { promClient, register } from "./Prometheus";
56

67
// this may conflict with stuff in ./Prometheus.js
@@ -161,8 +162,8 @@ const logisticDeliveryItem = new promClient.Gauge({
161162
register.registerMetric(logisticDeliveryItem);
162163

163164
class GrafanaHandler {
164-
servers: FactorioServer[]
165-
timeout: NodeJS.Timeout
165+
servers: FactorioServer[];
166+
timeout: NodeJS.Timeout;
166167
constructor() {
167168
this.servers = servers
168169
.map((server) => {

src/base/Tails.ts

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,49 @@
11
import { EventEmitter } from "events";
22
import { Tail } from "tail";
3-
import servers, { FactorioServer } from "../servers";
3+
import servers from "../servers";
4+
import { FactorioServer } from "../types";
45
import config from "../config";
56
import Comfy from "./Comfy";
67

78
export interface OutputData {
8-
line: string,
9-
server: FactorioServer
9+
line: string;
10+
server: FactorioServer;
1011
}
1112
export interface playerJoinData {
12-
line: {type: "join", playerName: string}
13-
server: FactorioServer
13+
line: { type: "join"; playerName: string };
14+
server: FactorioServer;
1415
}
1516
export interface playerLeaveData {
16-
line: {type: "leave", playerName: string, reason: string}
17-
server: FactorioServer
17+
line: { type: "leave"; playerName: string; reason: string };
18+
server: FactorioServer;
1819
}
1920

2021
export declare interface TailEvents {
21-
ALL: (data: OutputData) => void
22-
CHAT: (data: OutputData) => void
23-
JLOGGER: (data: OutputData) => void
24-
playerJoin: (data: playerJoinData) => void
25-
playerLeave: (data: playerLeaveData) => void
26-
out: (data: OutputData) => void
27-
start: (data: OutputData) => void
28-
logging: (data: OutputData) => void
29-
datastore: (data: OutputData) => void
30-
discord: (data: OutputData) => void
22+
ALL: (data: OutputData) => void;
23+
CHAT: (data: OutputData) => void;
24+
JLOGGER: (data: OutputData) => void;
25+
playerJoin: (data: playerJoinData) => void;
26+
playerLeave: (data: playerLeaveData) => void;
27+
out: (data: OutputData) => void;
28+
start: (data: OutputData) => void;
29+
logging: (data: OutputData) => void;
30+
datastore: (data: OutputData) => void;
31+
discord: (data: OutputData) => void;
3132
}
3233

3334
declare interface tailListener {
34-
on<E extends keyof TailEvents>(
35-
event: E,
36-
listener: TailEvents[E]
37-
): this
38-
off<E extends keyof TailEvents>(
39-
event: E,
40-
listener: TailEvents[E]
41-
): this
42-
once<E extends keyof TailEvents>(
43-
event: E,
44-
listener: TailEvents[E]
45-
): this
35+
on<E extends keyof TailEvents>(event: E, listener: TailEvents[E]): this;
36+
off<E extends keyof TailEvents>(event: E, listener: TailEvents[E]): this;
37+
once<E extends keyof TailEvents>(event: E, listener: TailEvents[E]): this;
4638
emit<E extends keyof TailEvents>(
4739
event: E,
4840
...args: Parameters<TailEvents[E]>
49-
): boolean
41+
): boolean;
5042
}
5143

5244
class tailListener extends EventEmitter {
53-
client: Comfy
54-
private tailLocations: tailLocation[]
45+
client: Comfy;
46+
private tailLocations: tailLocation[];
5547
constructor(tailLocations: tailLocation[]) {
5648
super();
5749
this.client = undefined;
@@ -100,9 +92,9 @@ class tailListener extends EventEmitter {
10092
}
10193

10294
interface tailLocation {
103-
path: string
104-
server: FactorioServer
105-
type: "out" | "logging" | "datastore" | "discord"
95+
path: string;
96+
server: FactorioServer;
97+
type: "out" | "logging" | "datastore" | "discord";
10698
}
10799

108100
let tailLocations: tailLocation[] = [];
@@ -134,4 +126,4 @@ servers.forEach((server) => {
134126
});
135127

136128
const listen = new tailListener(tailLocations);
137-
export default listen
129+
export default listen;

src/commands/Administration/resetserver.ts

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,6 @@ const Resetserver: Command<Message> = {
3535
);
3636
if (!server) return message.reply("Invalid channel, not tied to a server!");
3737

38-
// stop server
39-
childprocess.spawnSync(`./factorio-init/factorio`, ["stop"], {
40-
cwd: `${client.config.serverpath}/${server.path}`,
41-
});
42-
43-
// back up saves
44-
const saves = fs
45-
.readdirSync(`${client.config.serverpath}/${server.path}/saves`)
46-
.map(
47-
(save) => `${client.config.serverpath}/${server.path}/saves/${save}`
48-
);
49-
const latestSavePath = saves[0];
50-
// if there are saves, back up latest and remove all after
51-
if (latestSavePath) {
52-
const latestSave = latestSavePath.slice(
53-
latestSavePath.lastIndexOf("/") + 1,
54-
latestSavePath.indexOf(".")
55-
);
56-
if (!fs.existsSync(`${client.config.archivePath}/${server.path}/`))
57-
fs.mkdirSync(`${client.config.archivePath}/${server.path}/`);
58-
fs.copyFileSync(
59-
latestSavePath,
60-
`${client.config.archivePath}/${
61-
server.path
62-
}/${latestSave}_${moment().format("YYYY-MM-DD-mm-ss")}.zip`
63-
);
64-
saves.forEach((savePath) => fs.rmSync(savePath));
65-
}
66-
67-
// remove stats
68-
ServerStatistics.findOneAndDelete({ serverID: server.discordid }).then(
69-
() => {
70-
ServerStatistics.create({
71-
serverID: server.discordid,
72-
serverName: server.name,
73-
});
74-
}
75-
);
76-
7738
let cmdArgs = minimist(args);
7839
let command = "";
7940
// add scenario / map to command
@@ -129,10 +90,47 @@ const Resetserver: Command<Message> = {
12990
if (reaction.emoji.name !== "✅")
13091
return message.channel.send("Wrong emoji");
13192

132-
let output = [];
133-
const serverStartRegExp = new RegExp(
134-
/Info ServerMultiplayerManager.cpp:\d\d\d: Matching server connection resumed/
93+
// stop server
94+
childprocess.spawnSync(`./factorio-init/factorio`, ["stop"], {
95+
cwd: `${client.config.serverpath}/${server.path}`,
96+
});
97+
98+
// back up saves
99+
const saves = fs
100+
.readdirSync(`${client.config.serverpath}/${server.path}/saves`)
101+
.map(
102+
(save) => `${client.config.serverpath}/${server.path}/saves/${save}`
103+
);
104+
const latestSavePath = saves[0];
105+
// if there are saves, back up latest and remove all after
106+
if (latestSavePath) {
107+
const latestSave = latestSavePath.slice(
108+
latestSavePath.lastIndexOf("/") + 1,
109+
latestSavePath.indexOf(".")
110+
);
111+
if (!fs.existsSync(`${client.config.archivePath}/${server.path}/`))
112+
fs.mkdirSync(`${client.config.archivePath}/${server.path}/`);
113+
fs.copyFileSync(
114+
latestSavePath,
115+
`${client.config.archivePath}/${
116+
server.path
117+
}/${latestSave}_${moment().format("YYYY-MM-DD-mm-ss")}.zip`
118+
);
119+
saves.forEach((savePath) => fs.rmSync(savePath));
120+
}
121+
122+
// remove stats
123+
ServerStatistics.findOneAndDelete({ serverID: server.discordid }).then(
124+
() => {
125+
ServerStatistics.create({
126+
serverID: server.discordid,
127+
serverName: server.name,
128+
});
129+
}
135130
);
131+
132+
let output = [];
133+
const serverStartRegExp = new RegExp(/Hosting game at IP ADDR/);
136134
let factorio = childprocess.spawn(
137135
`./bin/x64/factorio`,
138136
command.split(" "),

src/commands/Owner/emit.js

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/commands/Owner/eval.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/commands/Owner/load.js

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)