Skip to content

Commit 67d2c16

Browse files
authored
Merge pull request #170 from oof2win2/master
2 parents d3ba236 + 8fe34a3 commit 67d2c16

File tree

13 files changed

+141
-114
lines changed

13 files changed

+141
-114
lines changed

src/base/Comfy.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
* @file Jammy's core. Based off of ComfyBot
33
*/
44

5-
import {
6-
Client,
7-
ClientOptions,
8-
Collection,
9-
TextChannel,
10-
} from "discord.js";
5+
import { Client, ClientOptions, Collection, TextChannel } from "discord.js";
116
import NodeCache from "node-cache";
127
import factorioServers from "../servers";
138
import {

src/base/Prometheus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import http from "http";
77
import serverUPS from "../helpers/serverUPSHandler";
88
import config from "../config";
99

10-
export * as promClient from "prom-client"
10+
export * as promClient from "prom-client";
1111

1212
const collectDefaultMetrics = promClient.collectDefaultMetrics;
1313
const Registry = promClient.Registry;
@@ -50,4 +50,4 @@ http
5050
return res.end(await register.metrics());
5151
}
5252
})
53-
.listen(config.promPort);
53+
.listen(config.promPort);

src/commands/Administration/resetserver.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,19 @@ const Resetserver: Command<Message> = {
118118
);
119119
saves.forEach((savePath) => fs.rmSync(savePath));
120120
}
121-
// back up deconlog, if exists
122-
if (fs.existsSync(`${client.config.serverpath}/${server.path}/script-output/log/decon.log`)) {
123-
fs.renameSync(`${client.config.serverpath}/${server.path}/script-output/log/decon.log`, `${client.config.serverpath}/${server.path}/script-output/log/decon_${moment().format("YYYY-MM-DD-mm-ss")}.log`);
124-
}
121+
// back up deconlog, if exists
122+
if (
123+
fs.existsSync(
124+
`${client.config.serverpath}/${server.path}/script-output/log/decon.log`
125+
)
126+
) {
127+
fs.renameSync(
128+
`${client.config.serverpath}/${server.path}/script-output/log/decon.log`,
129+
`${client.config.serverpath}/${
130+
server.path
131+
}/script-output/log/decon_${moment().format("YYYY-MM-DD-mm-ss")}.log`
132+
);
133+
}
125134

126135
// remove stats
127136
ServerStatistics.findOneAndDelete({ serverID: server.discordid }).then(

src/commands/Administration/updatescenarios.ts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,31 @@ const UpdateScenarios: Command<Message> = {
2525
ownerOnly: false,
2626
customPermissions: ["MANAGE_SERVER"],
2727
run: async ({ client, message, args }) => {
28-
const scenarios = fs.readdirSync(client.config.scenarioRootPath)
29-
const results = await Promise.all(
30-
scenarios.map(async (scenarioName): Promise<string[]> => {
31-
return [scenarioName, await runShellCommand(`cd ${client.config.scenarioRootPath}/${scenarioName} && git pull 1>/dev/null`).catch(x=>x)]
32-
})
33-
)
34-
const final = results
35-
.map(result => {
36-
if (result[1]) return result[0]
37-
return false
38-
})
39-
.filter((x): x is string => Boolean(x))
28+
const scenarios = fs.readdirSync(client.config.scenarioRootPath);
29+
const results = await Promise.all(
30+
scenarios.map(async (scenarioName): Promise<string[]> => {
31+
return [
32+
scenarioName,
33+
await runShellCommand(
34+
`cd ${client.config.scenarioRootPath}/${scenarioName} && git pull 1>/dev/null`
35+
).catch((x) => x),
36+
];
37+
})
38+
);
39+
const final = results
40+
.map((result) => {
41+
if (result[1]) return result[0];
42+
return false;
43+
})
44+
.filter((x): x is string => Boolean(x));
4045

41-
return message.channel.send(`Scenarios updated. ${final.length ? `\`${final.join("`, `")}\` had issues` : "No issues updating"}`)
46+
return message.channel.send(
47+
`Scenarios updated. ${
48+
final.length
49+
? `\`${final.join("`, `")}\` had issues`
50+
: "No issues updating"
51+
}`
52+
);
4253
},
4354
};
4455

src/commands/Factorio/onlineplayers.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ const OnlinePlayers: Command<Message> = {
3636
name
3737
)
3838
);
39-
const withoutScenarioOutputProm = serversWithoutScenario.map(
40-
(name) => rcon.rconCommand("/p o", name)
39+
const withoutScenarioOutputProm = serversWithoutScenario.map((name) =>
40+
rcon.rconCommand("/p o", name)
4141
);
4242
const scenarioOutput = await Promise.all(scenarioOutputProm);
4343
const withoutScenarioOutput = await Promise.all(withoutScenarioOutputProm);
4444

4545
scenarioOutput.forEach((response) => {
4646
if (!response.resp)
4747
return embed.addField(
48-
response.resp != false ? response.server.discordname : response.identifier,
48+
response.resp != false
49+
? response.server.discordname
50+
: response.identifier,
4951
"Server is unreachable"
5052
);
5153
const playerRoles = JSON.parse(
@@ -63,7 +65,9 @@ const OnlinePlayers: Command<Message> = {
6365
withoutScenarioOutput.forEach((response) => {
6466
if (!response.resp || typeof response.resp !== "string")
6567
return embed.addField(
66-
response.resp != false ? response.server.discordname : response.identifier,
68+
response.resp != false
69+
? response.server.discordname
70+
: response.identifier,
6771
"Server is unreachable"
6872
);
6973
const players = response.resp

src/commands/Moderation/rconcmdall.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ const RconcmdAll: Command<Message> = {
4141
if (out.resp && out.resp.length > 1024)
4242
throw Error("Response too long!");
4343
else
44-
outEmbed.addField(`${out.resp != false ? out.server.discordname : out.identifier}`, out.resp.toString());
44+
outEmbed.addField(
45+
`${out.resp != false ? out.server.discordname : out.identifier}`,
46+
out.resp.toString()
47+
);
4548
} catch (error) {
46-
outEmbed.addField(`${out.resp != false ? out.server.discordname : out.identifier}`, error);
49+
outEmbed.addField(
50+
`${out.resp != false ? out.server.discordname : out.identifier}`,
51+
error
52+
);
4753
console.error(error);
4854
}
4955
});

src/config.example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const config: BotConfig = {
5454
trusted: { id: "", name: "" },
5555
},
5656
archivePath: "", // path to your archive folder
57-
scenarioRootPath: "", // root path to scenario folders
57+
scenarioRootPath: "", // root path to scenario folders
5858
promPort: 9111, // port for prometheus to run on
5959

6060
moderatorroleid: "", // discord moderator role id

src/consts.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export interface BotConsts {
2-
discordMessageLengthLimit: number
3-
veteranUserHours: number
4-
guildid: string
2+
discordMessageLengthLimit: number;
3+
veteranUserHours: number;
4+
guildid: string;
55
}
66

77
const consts: BotConsts = {
@@ -10,4 +10,4 @@ const consts: BotConsts = {
1010
guildid: "548410604679856151",
1111
};
1212

13-
export default consts
13+
export default consts;

src/events/guild/guildMemberUpdate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ export default async (
5252
`/interface Roles.assign_player('${user.factorioName}', '${role}', "JammyBot", true)`
5353
);
5454
});
55-
await user.save()
55+
await user.save();
5656
}
5757
};

src/helpers/logger.ts

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,36 @@ function format(tDate: Date) {
2626
);
2727
}
2828

29-
type LogType =
30-
| "log"
31-
| "warn"
32-
| "error"
33-
| "debug"
34-
| "cmd"
35-
| "ready"
29+
type LogType = "log" | "warn" | "error" | "debug" | "cmd" | "ready";
3630

3731
export default function logger(content: any, type: LogType = "log") {
3832
const date = `[${format(new Date(Date.now()))}]`;
39-
switch (type) {
40-
case "log": {
41-
return console.log(`${date} ${bgBlue(type.toUpperCase())} ${content}`);
42-
}
43-
case "warn": {
44-
return console.log(
45-
`${date} ${black.bgYellow(type.toUpperCase())} ${content}`
46-
);
47-
}
48-
case "error": {
49-
return console.log(
50-
`${date} ${black.bgRed(type.toUpperCase())} ${content}`
51-
);
52-
}
53-
case "debug": {
54-
return console.log(`${date} ${green(type.toUpperCase())} ${content}`);
55-
}
56-
case "cmd": {
57-
return console.log(
58-
`${date} ${black.bgWhite(type.toUpperCase())} ${content}`
59-
);
60-
}
61-
case "ready": {
62-
return console.log(
63-
`${date} ${black.bgGreen(type.toUpperCase())} ${content}`
64-
);
65-
}
33+
switch (type) {
34+
case "log": {
35+
return console.log(`${date} ${bgBlue(type.toUpperCase())} ${content}`);
6636
}
67-
}
37+
case "warn": {
38+
return console.log(
39+
`${date} ${black.bgYellow(type.toUpperCase())} ${content}`
40+
);
41+
}
42+
case "error": {
43+
return console.log(
44+
`${date} ${black.bgRed(type.toUpperCase())} ${content}`
45+
);
46+
}
47+
case "debug": {
48+
return console.log(`${date} ${green(type.toUpperCase())} ${content}`);
49+
}
50+
case "cmd": {
51+
return console.log(
52+
`${date} ${black.bgWhite(type.toUpperCase())} ${content}`
53+
);
54+
}
55+
case "ready": {
56+
return console.log(
57+
`${date} ${black.bgGreen(type.toUpperCase())} ${content}`
58+
);
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)