Skip to content

Commit

Permalink
optional graph 📈
Browse files Browse the repository at this point in the history
 * some just prefer a cleaner look 😎
  • Loading branch information
a-sync committed Dec 18, 2023
1 parent 20169a1 commit dc865c4
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
18 changes: 18 additions & 0 deletions public/game-server-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
"type": "boolean",
"format": "checkbox"
},
"showGraph": {
"title": "Show graph",
"default": true,
"type": "boolean",
"format": "checkbox"
},
"onlineColor": {
"title": "Online color",
"default": "#000000",
Expand Down Expand Up @@ -122,6 +128,12 @@
"default": true,
"type": "boolean",
"format": "checkbox"
},
"showGraph": {
"title": "Show graph",
"default": true,
"type": "boolean",
"format": "checkbox"
}
}
},
Expand Down Expand Up @@ -152,6 +164,12 @@
"default": true,
"type": "boolean",
"format": "checkbox"
},
"showGraph": {
"title": "Show graph",
"default": true,
"type": "boolean",
"format": "checkbox"
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion src/discord-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,15 @@ class ServerInfoMessage {
const fields: APIEmbedField[] = [];
embed.setFooter({ text: 'Last updated' });
embed.setTimestamp();
embed.setImage(gs.history.statsChart());

const onlineColor = conf.onlineColor || '#000000';
const offlineColor = conf.offlineColor || '#FF0000';
const showPlayersList = Boolean(conf.showPlayersList);
const showGraph = Boolean(conf.showGraph);

if (showGraph) {
embed.setImage(gs.history.statsChart());
}

if (gs.info && gs.online) {
embed.setTitle(gs.niceName.slice(0, 256));
Expand Down
29 changes: 16 additions & 13 deletions src/slack-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ class ServerInfoMessage {
}

async updatePost(gs: GameServer, conf: SlackConfig) {
const showPlayersList = Boolean(conf.showPlayersList);
const showGraph = Boolean(conf.showGraph);

const blocks: (KnownBlock | Block)[] = [];
const fields1: (PlainTextElement | MrkdwnElement)[] = [];
const fields2: (PlainTextElement | MrkdwnElement)[] = [];
let text;

const showPlayersList = Boolean(conf.showPlayersList);

let text;
if (gs.info && gs.online) {
text = this.escapeMarkdown(gs.niceName);

Expand Down Expand Up @@ -240,17 +241,19 @@ class ServerInfoMessage {
});
}

const unixTimestamp = Math.floor(+new Date() / 1000);
blocks.push({
type: 'image',
image_url: gs.history.statsChart(),
alt_text: 'Player numbers chart',
title: {
type: 'plain_text',
text: `📈`
}
});
if (showGraph) {
blocks.push({
type: 'image',
image_url: gs.history.statsChart(),
alt_text: 'Player numbers chart',
title: {
type: 'plain_text',
text: `📈`
}
});
}

const unixTimestamp = Math.floor(+new Date() / 1000);
// text += ' Last updated at ' + new Date().toLocaleString();
blocks.push({
"type": "context",
Expand Down
6 changes: 3 additions & 3 deletions src/telegram-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ class ServerInfoMessage {
}

async updatePost(gs: GameServer, conf: TelegramConfig) {
const chart = '[📈](' + gs.history.statsChart() + ')';
let infoText = this.escapeMarkdown(gs.niceName) + ' offline...';

const showPlayersList = Boolean(conf.showPlayersList);
const showGraph = Boolean(conf.showGraph);

const chart = showGraph ? '[📈](' + gs.history.statsChart() + ')' : '';
let infoText = this.escapeMarkdown(gs.niceName) + ' offline...';
if (gs.info && gs.online) {
infoText = [
this.escapeMarkdown(gs.niceName),
Expand Down
3 changes: 3 additions & 0 deletions src/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ export interface DiscordConfig {
showPlayersList?: boolean;
onlineColor?: string;
offlineColor?: string;
showGraph?: boolean;
}

export interface TelegramConfig {
chatId: string;
showPlayersList?: boolean;
showGraph?: boolean;
}

export interface SlackConfig {
channelId: string;
showPlayersList?: boolean;
showGraph?: boolean;
}

export interface GameServerConfig {
Expand Down

0 comments on commit dc865c4

Please sign in to comment.