Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"prisma": "^3.0.1",
"prom-client": "^13.1.0",
"rcon-client": "^4.2.3",
"read-last-lines": "^1.8.0",
"reflect-metadata": "^0.1.13",
"request": "^2.88.2",
"request-promise": "^4.2.6",
Expand Down
37 changes: 37 additions & 0 deletions src/commands/Administration/getlogs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Message, MessageAttachment } from "discord.js";
import { Command } from "../../base/Command.js";
import serverJS from "../../servers";
import lastLines from "read-last-lines"

const Rollback: Command<Message> = {
name: "getlogs",
description: "Get logs from a Factorio server",
usage: "(channel) [logcount]",
category: "Administration",
aliases: [],
examples: ["{{p}}getlogs #awf-regular 50"],
dirname: __dirname,
enabled: true,
guildOnly: false,
memberPermissions: ["ADMINISTRATOR"],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
nsfw: false,
ownerOnly: false,
customPermissions: ["MANAGE_SERVER"],
run: async ({ client, message, args }) => {
if (!message.mentions.channels.first())
return message.reply("No channel to get logs of provided!");
args.shift(); // remove mention
const lineCount = Math.min(Number(args.shift()) || 50, 50)
const server = serverJS.find(
(server) => server.discordid === message.mentions.channels.first().id
);
if (!server) return message.reply("Invalid channel, not tied to a server!");
const fullPath = `${client.config.serverpath}/${server.path}/factorio-current.log`
const lines = await lastLines.read(fullPath, lineCount < 0 ? lineCount : 50)
const attachment = new MessageAttachment(Buffer.from(lines), "log.txt")
return message.channel.send(`Logs for <#${server.discordid}> are sent as an attachement`, {files: [attachment]})
},
};

export default Rollback;
13 changes: 10 additions & 3 deletions src/commands/Factorio/onlineplayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ const OnlinePlayers: Command<Message> = {

const serversWithScenario = rcon.rconConnections
.filter((connection) => connection.hasScenario)
.filter((connection) => connection.server.hidden === false)
.filter((connection) => connection.server.hidden === false)
.map((connection) => connection.server.discordname);
const serversWithoutScenario = rcon.rconConnections
.filter((connection) => !connection.hasScenario)
.filter((connection) => connection.server.hidden === false)
.filter((connection) => connection.server.hidden === false)
.map((connection) => connection.server.discordname);

const scenarioOutputProm = serversWithScenario.map((discordname) =>
Expand Down Expand Up @@ -66,7 +66,14 @@ const OnlinePlayers: Command<Message> = {
response.server.discordname,
"Server is unreachable"
);
embed.addField(response.server.discordname, response.resp);
const players = response.resp
.split("\n")
.slice(1)
.map((line) => line.slice(0, line.indexOf(" (online)")));
embed.addField(
response.server.discordname,
players.join("\n") || "Nobody is online"
);
});
return message.channel.send(embed);
},
Expand Down
13 changes: 13 additions & 0 deletions src/helpers/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import discord from "discord.js";
import fs from "fs";
import { BannedPlayers, ExtraBans } from "./sqlitedb";
import { FactorioServer } from "../types";
import UserModel from "../base/User";
import { mongoose } from "@typegoose/typegoose";

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

UserModel.deleteMany({factorioName: playername}).exec()
mongoose.connections[1]
.getClient()
.db("scenario")
.collections()
.then((collections) => {
collections.map((collection) => {
collection.deleteMany({playername: playername})
})
})

return player;
}

Expand Down
5 changes: 0 additions & 5 deletions src/helpers/serverHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,6 @@ class serverHandler {
const server = out.server;
let channel = this.client.channels.cache.get(server.discordid);
if (!channel || !channel.isText() || channel.type === "dm") return;
if (line.includes("; Factorio")) {
return channel.setTopic(
`Running ${this.formatVersion(line)} since ${this.formatDate(line)}`
);
}
if (line.includes("Error")) {
if (channel.name !== "dev-dump") {
const errorChannel =
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/serverUPSHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,18 @@ class UPSManager {
Object.keys(this.servers).forEach((serverKey) => {
if (this.servers[serverKey]?.discordid === server.discordid)
this.servers[serverKey].playercount++;
if (this.servers[serverKey] == 1) {
rcon.rconCommand("/sc game.tick_paused = true", server.discordid)
}
});
}
if (line.type === "leave") {
Object.keys(this.servers).forEach((serverKey) => {
if (this.servers[serverKey]?.discordid === server.discordid)
this.servers[serverKey].playercount--;
if (this.servers[serverKey] == 0) {
rcon.rconCommand("/sc game.tick_paused = true", server.discordid)
}
});
}
}
Expand Down