Added current game month in discord embed #2

This commit is contained in:
Dennis Heinrich 2024-11-26 00:48:02 +01:00
parent ef8deb53b5
commit c8c0e1018a
7 changed files with 85 additions and 2 deletions

View file

@ -16,10 +16,26 @@
"descriptionOffline": "Server is offline", "descriptionOffline": "Server is offline",
"descriptionUnknown": "Server status fetching", "descriptionUnknown": "Server status fetching",
"titleServerName": "Server name", "titleServerName": "Server name",
"titleServerMap": "Server map",
"titleServerMods": "Server mods",
"titleServerPassword": "Server password", "titleServerPassword": "Server password",
"titleServerTime": "Server time", "titleServerTime": "Server time",
"titlePlayerCount": "Players online", "titlePlayerCount": "Players online",
"noPlayersOnline": "No players online" "noPlayersOnline": "No players online"
},
"common": {
"monthJanuary": "January",
"monthFebruary": "February",
"monthMarch": "March",
"monthApril": "April",
"monthMay": "May",
"monthJune": "June",
"monthJuly": "July",
"monthAugust": "August",
"monthSeptember": "September",
"monthOctober": "October",
"monthNovember": "November",
"monthDecember": "December"
} }
} }
} }

View file

@ -1,5 +1,7 @@
import ITranslationDiscordEmbed from "./ITranslationDiscordEmbed"; import ITranslationDiscordEmbed from "./ITranslationDiscordEmbed";
import ITranslationCommon from "./ITranslationCommon";
export default interface ITranslation { export default interface ITranslation {
discordEmbed: ITranslationDiscordEmbed; discordEmbed: ITranslationDiscordEmbed;
common: ITranslationCommon;
} }

View file

@ -0,0 +1,14 @@
export default interface ITranslationCommon {
monthJanuary: string;
monthFebruary: string;
monthMarch: string;
monthApril: string;
monthMay: string;
monthJune: string;
monthJuly: string;
monthAugust: string;
monthSeptember: string;
monthOctober: string;
monthNovember: string;
monthDecember: string;
}

View file

@ -4,6 +4,8 @@ export default interface ITranslationDiscordEmbed {
descriptionOffline: string; descriptionOffline: string;
descriptionUnknown: string; descriptionUnknown: string;
titleServerName: string; titleServerName: string;
titleServerMap: string;
titleServerMods: string;
titleServerPassword: string; titleServerPassword: string;
titleServerTime: string; titleServerTime: string;
titlePlayerCount: string; titlePlayerCount: string;

View file

@ -76,8 +76,22 @@ export default class Configuration implements IConfiguration{
|| this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.titleServerName) || this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.titleServerName)
|| this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.titleServerPassword) || this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.titleServerPassword)
|| this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.titleServerTime) || this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.titleServerTime)
|| this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.titleServerMap)
|| this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.titleServerMods)
|| this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.titlePlayerCount) || this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.titlePlayerCount)
|| this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.noPlayersOnline) || this.isValueEmptyOrUndefined(this?.translation?.discordEmbed?.noPlayersOnline)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthJanuary)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthFebruary)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthMarch)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthApril)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthMay)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthJune)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthJuly)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthAugust)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthSeptember)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthOctober)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthNovember)
|| this.isValueEmptyOrUndefined(this?.translation?.common?.monthDecember)
); );
} }

View file

@ -98,6 +98,8 @@ export default class DiscordEmbed {
let embed = new EmbedBuilder(); let embed = new EmbedBuilder();
let config = this.appConfiguration; let config = this.appConfiguration;
serverStats.getServerMonth();
embed.setTitle(config.translation.discordEmbed.title); embed.setTitle(config.translation.discordEmbed.title);
if (!serverStats.isOnline()) { if (!serverStats.isOnline()) {
embed.setColor(0xCA0000); embed.setColor(0xCA0000);
@ -127,6 +129,7 @@ export default class DiscordEmbed {
{name: config.translation.discordEmbed.titleServerName, value: serverStats.getServerName()}, {name: config.translation.discordEmbed.titleServerName, value: serverStats.getServerName()},
{name: config.translation.discordEmbed.titleServerPassword, value: serverPassword}, {name: config.translation.discordEmbed.titleServerPassword, value: serverPassword},
{name: config.translation.discordEmbed.titleServerTime, value: serverStats.getServerTime()}, {name: config.translation.discordEmbed.titleServerTime, value: serverStats.getServerTime()},
{name: config.translation.discordEmbed.titleServerMap, value: serverStats.getServerMap()},
{ {
name: `${config.translation.discordEmbed.titlePlayerCount} (${serverStats.getPlayerCount()}/${serverStats.getMaxPlayerCount()}):`, name: `${config.translation.discordEmbed.titlePlayerCount} (${serverStats.getPlayerCount()}/${serverStats.getMaxPlayerCount()}):`,
value: playerListString value: playerListString

View file

@ -3,6 +3,7 @@ import Configuration from "./Configuration";
import {XMLParser} from "fast-xml-parser"; import {XMLParser} from "fast-xml-parser";
import Logging from "./Logging"; import Logging from "./Logging";
import IPlayer from "../Interfaces/Feed/IPlayer"; import IPlayer from "../Interfaces/Feed/IPlayer";
import IConfiguration from "../Interfaces/Configuration/IConfiguration";
export const CONNECTION_REFUSED = 'ECONNREFUSED'; export const CONNECTION_REFUSED = 'ECONNREFUSED';
export const NOT_FOUND = 'ENOTFOUND'; export const NOT_FOUND = 'ENOTFOUND';
@ -102,7 +103,7 @@ export default class ServerStatusFeed {
* @returns {string} The server map name * @returns {string} The server map name
*/ */
public getServerMap(): string { public getServerMap(): string {
return <string>this.getServerStats()?.Server.map; return <string>this.getServerStats()?.Server.mapName;
} }
/** /**
@ -117,6 +118,37 @@ export default class ServerStatusFeed {
return dayTime / (60 * 60 * 1000) + 0.0001; return dayTime / (60 * 60 * 1000) + 0.0001;
} }
/**
* Returns the server month as a string
* @returns {string} The server month as a string
*/
public getServerMonth(): string {
let config: IConfiguration = Configuration.getConfiguration();
let dayTime = this.getServerStats()?.Server.dayTime;
if (dayTime === undefined) {
return "Error";
}
let month = dayTime / (60 * 60 * 1000 * 24);
month = month % 1;
month = month * 12;
month = Math.floor(month);
let months = [
config.translation.common.monthJanuary,
config.translation.common.monthFebruary,
config.translation.common.monthMarch,
config.translation.common.monthApril,
config.translation.common.monthMay,
config.translation.common.monthJune,
config.translation.common.monthJuly,
config.translation.common.monthAugust,
config.translation.common.monthSeptember,
config.translation.common.monthOctober,
config.translation.common.monthNovember,
config.translation.common.monthDecember
]
return months[month-1];
}
/** /**
* Returns the server time in the format HH:MM * Returns the server time in the format HH:MM
* @returns {string} The server time in the format HH:MM * @returns {string} The server time in the format HH:MM
@ -136,7 +168,7 @@ export default class ServerStatusFeed {
if(minutesString.length === 1) { if(minutesString.length === 1) {
minutesString = `0${minutesString}`; minutesString = `0${minutesString}`;
} }
return `${hoursString}:${minutesString}`; return `${hoursString}:${minutesString} (${this.getServerMonth()})`;
} }
/** /**