mirror of
https://github.com/cloudmaker97/FS25-Discord-Bot.git
synced 2025-12-06 00:18:34 +00:00
Showing server mods in discord embed #5
This commit is contained in:
parent
e4f485217f
commit
ae1413db60
3 changed files with 27 additions and 0 deletions
5
source/Interfaces/Feed/IMod.ts
Normal file
5
source/Interfaces/Feed/IMod.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
export default interface IMod {
|
||||
name: string;
|
||||
author: string;
|
||||
version: string;
|
||||
}
|
||||
|
|
@ -124,12 +124,19 @@ export default class DiscordEmbed {
|
|||
serverPassword = "-/-";
|
||||
}
|
||||
|
||||
let serverMods = serverStats.getServerMods();
|
||||
let serverModsText = "-/-";
|
||||
if(serverMods.length > 0) {
|
||||
serverModsText = serverMods.map(mod => `${mod.name}`).join(', ');
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
embed.addFields(
|
||||
{name: config.translation.discordEmbed.titleServerName, value: serverStats.getServerName()},
|
||||
{name: config.translation.discordEmbed.titleServerPassword, value: serverPassword},
|
||||
{name: config.translation.discordEmbed.titleServerTime, value: serverStats.getServerTime()},
|
||||
{name: config.translation.discordEmbed.titleServerMap, value: serverStats.getServerMap()},
|
||||
{name: config.translation.discordEmbed.titleServerMods, value: serverModsText},
|
||||
{
|
||||
name: `${config.translation.discordEmbed.titlePlayerCount} (${serverStats.getPlayerCount()}/${serverStats.getMaxPlayerCount()}):`,
|
||||
value: playerListString
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import {XMLParser} from "fast-xml-parser";
|
|||
import Logging from "./Logging";
|
||||
import IPlayer from "../Interfaces/Feed/IPlayer";
|
||||
import IConfiguration from "../Interfaces/Configuration/IConfiguration";
|
||||
import IMod from "../Interfaces/Feed/IMod";
|
||||
|
||||
export const CONNECTION_REFUSED = 'ECONNREFUSED';
|
||||
export const NOT_FOUND = 'ENOTFOUND';
|
||||
|
|
@ -118,6 +119,20 @@ export default class ServerStatusFeed {
|
|||
return dayTime / (60 * 60 * 1000) + 0.0001;
|
||||
}
|
||||
|
||||
public getServerMods(): IMod[] {
|
||||
let modList = this.getServerStats()?.Server.Mods.Mod;
|
||||
if(modList === undefined || !Array.isArray(modList)) {
|
||||
return [];
|
||||
}
|
||||
return modList.map((mod: any) => {
|
||||
return {
|
||||
name: mod['#text'],
|
||||
author: mod.author,
|
||||
version: mod.version
|
||||
} as IMod;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server month as a string
|
||||
* @returns {string} The server month as a string
|
||||
|
|
|
|||
Loading…
Reference in a new issue