Skip to content

Commit f299457

Browse files
authored
Merge pull request #126 from oof2win2/features
2 parents f0616a1 + 7842a7d commit f299457

File tree

7 files changed

+75
-8
lines changed

7 files changed

+75
-8
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"prisma": "^3.0.1",
5858
"prom-client": "^13.1.0",
5959
"rcon-client": "^4.2.3",
60+
"read-last-lines": "^1.8.0",
6061
"reflect-metadata": "^0.1.13",
6162
"request": "^2.88.2",
6263
"request-promise": "^4.2.6",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Message, MessageAttachment } from "discord.js";
2+
import { Command } from "../../base/Command.js";
3+
import serverJS from "../../servers";
4+
import lastLines from "read-last-lines"
5+
6+
const Rollback: Command<Message> = {
7+
name: "getlogs",
8+
description: "Get logs from a Factorio server",
9+
usage: "(channel) [logcount]",
10+
category: "Administration",
11+
aliases: [],
12+
examples: ["{{p}}getlogs #awf-regular 50"],
13+
dirname: __dirname,
14+
enabled: true,
15+
guildOnly: false,
16+
memberPermissions: ["ADMINISTRATOR"],
17+
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
18+
nsfw: false,
19+
ownerOnly: false,
20+
customPermissions: ["MANAGE_SERVER"],
21+
run: async ({ client, message, args }) => {
22+
if (!message.mentions.channels.first())
23+
return message.reply("No channel to get logs of provided!");
24+
args.shift(); // remove mention
25+
const lineCount = Math.min(Number(args.shift()) || 50, 50)
26+
const server = serverJS.find(
27+
(server) => server.discordid === message.mentions.channels.first().id
28+
);
29+
if (!server) return message.reply("Invalid channel, not tied to a server!");
30+
const fullPath = `${client.config.serverpath}/${server.path}/factorio-current.log`
31+
const lines = await lastLines.read(fullPath, lineCount < 0 ? lineCount : 50)
32+
const attachment = new MessageAttachment(Buffer.from(lines), "log.txt")
33+
return message.channel.send(`Logs for <#${server.discordid}> are sent as an attachement`, {files: [attachment]})
34+
},
35+
};
36+
37+
export default Rollback;

src/commands/Factorio/onlineplayers.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ const OnlinePlayers: Command<Message> = {
2323

2424
const serversWithScenario = rcon.rconConnections
2525
.filter((connection) => connection.hasScenario)
26-
.filter((connection) => connection.server.hidden === false)
26+
.filter((connection) => connection.server.hidden === false)
2727
.map((connection) => connection.server.discordname);
2828
const serversWithoutScenario = rcon.rconConnections
2929
.filter((connection) => !connection.hasScenario)
30-
.filter((connection) => connection.server.hidden === false)
30+
.filter((connection) => connection.server.hidden === false)
3131
.map((connection) => connection.server.discordname);
3232

3333
const scenarioOutputProm = serversWithScenario.map((discordname) =>
@@ -66,7 +66,14 @@ const OnlinePlayers: Command<Message> = {
6666
response.server.discordname,
6767
"Server is unreachable"
6868
);
69-
embed.addField(response.server.discordname, response.resp);
69+
const players = response.resp
70+
.split("\n")
71+
.slice(1)
72+
.map((line) => line.slice(0, line.indexOf(" (online)")));
73+
embed.addField(
74+
response.server.discordname,
75+
players.join("\n") || "Nobody is online"
76+
);
7077
});
7178
return message.channel.send(embed);
7279
},

src/helpers/functions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import discord from "discord.js";
1111
import fs from "fs";
1212
import { BannedPlayers, ExtraBans } from "./sqlitedb";
1313
import { FactorioServer } from "../types";
14+
import UserModel from "../base/User";
15+
import { mongoose } from "@typegoose/typegoose";
1416

1517
export type ArgumentTypes<F extends Function> = F extends (args: infer A) => any
1618
? A
@@ -208,6 +210,17 @@ export async function addban(playername: string, reason: string) {
208210
reason: reason || "No reason given",
209211
});
210212

213+
UserModel.deleteMany({factorioName: playername}).exec()
214+
mongoose.connections[1]
215+
.getClient()
216+
.db("scenario")
217+
.collections()
218+
.then((collections) => {
219+
collections.map((collection) => {
220+
collection.deleteMany({playername: playername})
221+
})
222+
})
223+
211224
return player;
212225
}
213226

src/helpers/serverHandler.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ class serverHandler {
136136
const server = out.server;
137137
let channel = this.client.channels.cache.get(server.discordid);
138138
if (!channel || !channel.isText() || channel.type === "dm") return;
139-
if (line.includes("; Factorio")) {
140-
return channel.setTopic(
141-
`Running ${this.formatVersion(line)} since ${this.formatDate(line)}`
142-
);
143-
}
144139
if (line.includes("Error")) {
145140
if (channel.name !== "dev-dump") {
146141
const errorChannel =

src/helpers/serverUPSHandler.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ class UPSManager {
6767
Object.keys(this.servers).forEach((serverKey) => {
6868
if (this.servers[serverKey]?.discordid === server.discordid)
6969
this.servers[serverKey].playercount++;
70+
if (this.servers[serverKey] == 1) {
71+
rcon.rconCommand("/sc game.tick_paused = true", server.discordid)
72+
}
7073
});
7174
}
7275
if (line.type === "leave") {
7376
Object.keys(this.servers).forEach((serverKey) => {
7477
if (this.servers[serverKey]?.discordid === server.discordid)
7578
this.servers[serverKey].playercount--;
79+
if (this.servers[serverKey] == 0) {
80+
rcon.rconCommand("/sc game.tick_paused = true", server.discordid)
81+
}
7682
});
7783
}
7884
}

0 commit comments

Comments
 (0)