Compare commits

...

4 commits
0.1.7 ... main

Author SHA1 Message Date
ed492e9045
Use newer docker compose command
Some checks failed
Docker Build / build-and-push (push) Has been cancelled
2025-10-31 23:54:01 +01:00
24f65956ab Local development with webserver and demo files
Some checks failed
Docker Build / build-and-push (push) Has been cancelled
2025-07-10 17:25:29 +02:00
4e6668c2e5 Increased bot version to 0.1.8 2024-12-12 12:39:05 +01:00
696e8f1749 Added truncate for servers with long list of mods (discord max length 1024 chars) and feed parse optimization 2024-12-12 12:37:32 +01:00
11 changed files with 37 additions and 18 deletions

View file

@ -74,7 +74,7 @@ discord.js library to interact with Discord and fetches server stats via the XML
2. Build and start the container:
```bash
docker-compose up -d --build
docker compose up -d --build
```
3. The bot should now be running and posting server stats to the specified Discord channel.

View file

@ -1,8 +1,8 @@
{
"application": {
"serverPassword": "TypeMyServerPasswordHere",
"serverStatsUrl": "http://1.1.1.1:8080/feed/dedicated-server-stats.xml",
"serverMapUrl": "http://1.1.1.1:8080/feed/dedicated-server-stats-map.jpg",
"serverStatsUrl": "http://127.0.0.1:8080/feed/dedicated-server-stats.xml",
"serverMapUrl": "http://127.0.0.1:8080/feed/dedicated-server-stats-map.jpg",
"updateIntervalSeconds": 30
},
"discord": {

View file

@ -1,8 +1,8 @@
{
"application": {
"serverPassword": "TypeMyServerPasswordHere",
"serverStatsUrl": "http://1.1.1.1:8080/feed/dedicated-server-stats.xml",
"serverMapUrl": "http://1.1.1.1:8080/feed/dedicated-server-stats-map.jpg",
"serverStatsUrl": "http://127.0.0.1:8080/feed/dedicated-server-stats.xml",
"serverMapUrl": "http://127.0.0.1:8080/feed/dedicated-server-stats-map.jpg",
"updateIntervalSeconds": 30
},
"discord": {

View file

@ -1,5 +1,3 @@
version: "2"
services:
ls25bot:
build:
@ -25,3 +23,13 @@ services:
echo "Restarting ls25bot container at $(date)"
docker restart ls25bot
done
# This is used for development purposes only
webserver:
image: nginx:alpine
container_name: ls25bot-webserver
restart: always
volumes:
- ./misc/files:/usr/share/nginx/html
ports:
- "8080:80"

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

View file

@ -1,6 +1,6 @@
{
"name": "ls25-discord-bot",
"version": "0.1.7",
"version": "0.1.8",
"description": "A simple discord bot for farming simulator 25",
"main": "source/Main.ts",
"scripts": {

View file

@ -92,6 +92,16 @@ export default class DiscordEmbed {
return true;
}
/**
* Truncates a string at a given length
* @param text The input text to truncate
* @param maxLength The allowed characters until truncation
* @returns The truncated string
*/
private async truncateText(text: string, maxLength = 1024): Promise<string> {
return text.length > maxLength ? text.slice(0, maxLength - 3) + '...' : text;
}
/**
* Send server stats embed in a channel
* @param serverStats
@ -113,6 +123,8 @@ export default class DiscordEmbed {
embed.setThumbnail(config.application.serverMapUrl);
let playerListString: string;
let playerListTitleString = `${config.translation.discordEmbed.titlePlayerCount} (${serverStats.getPlayerCount()??0}/${serverStats.getMaxPlayerCount()??0}):`;
if(serverStats.getPlayerList().length === 0) {
playerListString = config.translation.discordEmbed.noPlayersOnline;
} else {
@ -127,7 +139,7 @@ export default class DiscordEmbed {
let serverMods = serverStats.getServerMods();
let serverModsText = "-/-";
if(serverMods.length > 0) {
serverModsText = serverMods.map(mod => `${mod.name}`).join(', ');
serverModsText = await this.truncateText(serverMods.map(mod => `${mod.name}`).join(', '));
}
// @ts-ignore
@ -138,12 +150,11 @@ export default class DiscordEmbed {
{name: config.translation.discordEmbed.titleServerMap, value: serverStats.getServerMap()},
{name: config.translation.discordEmbed.titleServerMods, value: serverModsText},
{
name: `${config.translation.discordEmbed.titlePlayerCount} (${serverStats.getPlayerCount()}/${serverStats.getMaxPlayerCount()}):`,
name: playerListTitleString,
value: playerListString
},
);
}
this.appLogger.debug(embed);
return embed;
}
}

View file

@ -161,18 +161,18 @@ export default class ServerStatusFeed {
/**
* Returns the server player count
* @returns {number} The server player count
* @returns {number | null | undefined} The server player count
*/
public getPlayerCount(): number {
return <number>this.getServerStats()?.Server.Slots.numUsed;
public getPlayerCount(): number | null | undefined {
return <number>this.getServerStats()?.Server?.Slots?.numUsed;
}
/**
* Returns the server player count
* @returns {number} The server player count
* @returns {number | null | undefined} The server player count
*/
public getMaxPlayerCount(): number {
return <number>this.getServerStats()?.Server.Slots.capacity;
public getMaxPlayerCount(): number | null | undefined {
return <number>this.getServerStats()?.Server?.Slots?.capacity;
}
/**