Skip to content

Commit 2734750

Browse files
committed
✨ Command to get logs of server
1 parent 68049bd commit 2734750

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
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;

0 commit comments

Comments
 (0)