Skip to content

Commit 3d68db6

Browse files
Techbot121Meta Construct
authored andcommitted
send status image directly for now
1 parent 8976dc8 commit 3d68db6

File tree

2 files changed

+47
-17
lines changed

2 files changed

+47
-17
lines changed

app/services/gamebridge/payloads/StatusPayload.ts

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import Payload from "./Payload.js";
55
import SteamID from "steamid";
66
import dayjs from "dayjs";
77
import requestSchema from "./structures/StatusRequest.json" with { type: "json" };
8+
import nodeHtmlToImage from "node-html-to-image";
9+
import pug from "pug";
10+
import path from "path";
811

912
const GamemodeAlias = {
1013
qbox: "metastruct",
@@ -57,6 +60,7 @@ const getRandomActivity = (gamemode: string) => {
5760
return activities[(Math.random() * activities.length) | 0];
5861
};
5962

63+
const DEFAULT_THUMBNAIL = path.join(process.cwd(), "resources/map-thumbnails/gm_construct_m.png");
6064
export default class StatusPayload extends Payload {
6165
protected static requestSchema = requestSchema;
6266
private static retryCount = 0;
@@ -76,9 +80,6 @@ export default class StatusPayload extends Payload {
7680
gamemodes,
7781
} = payload.data;
7882
const { bridge, discord } = server;
79-
const {
80-
config: { host, port, url },
81-
} = bridge.webApp;
8283
const Steam = await bridge.container.getService("Steam");
8384

8485
const updateStatus = async () => {
@@ -182,9 +183,12 @@ export default class StatusPayload extends Payload {
182183
let mapThumbnail: string | null = mapChanged ? null : server.status.mapThumbnail;
183184
if (mapThumbnail === null) {
184185
if (current_map && /^gm_construct_m/i.test(current_map)) {
185-
mapThumbnail = `${url}/map-thumbnails/gm_construct_m.png`;
186+
mapThumbnail = DEFAULT_THUMBNAIL;
186187
} else if (current_map && current_map.toLowerCase().trim() == "rp_unioncity") {
187-
mapThumbnail = `${url}/map-thumbnails/rp_unioncity.png`;
188+
mapThumbnail = path.join(
189+
process.cwd(),
190+
"resources/map-thumbnails/rp_unioncity.png"
191+
);
188192
}
189193

190194
if (!mapThumbnail && current_workshopMap) {
@@ -219,7 +223,7 @@ export default class StatusPayload extends Payload {
219223
accessory: {
220224
type: Discord.ComponentType.Thumbnail,
221225
media: {
222-
url: mapThumbnail ?? `${url}/map-thumbnails/gm_construct_m.png`,
226+
url: "attachment://map.png",
223227
},
224228
description: current_map,
225229
},
@@ -235,11 +239,7 @@ export default class StatusPayload extends Payload {
235239
items: [
236240
{
237241
media: {
238-
url: players
239-
? `http://${host}:${port}/server-status/${
240-
server.config.id
241-
}/${Date.now()}`
242-
: (server.status.image ?? ""),
242+
url: "attachment://players.png",
243243
},
244244
},
245245
],
@@ -251,11 +251,7 @@ export default class StatusPayload extends Payload {
251251
{ type: Discord.ComponentType.Separator },
252252
{
253253
type: Discord.ComponentType.TextDisplay,
254-
content: `-# ${gamemodeName}${
255-
count > 0
256-
? " | Middle-click the player list to open an interactive version"
257-
: ""
258-
}`,
254+
content: `-# ${gamemodeName}`,
259255
}
260256
);
261257

@@ -329,6 +325,24 @@ export default class StatusPayload extends Payload {
329325
if (!channel) return;
330326

331327
try {
328+
const html = pug.renderFile(
329+
path.join(process.cwd(), "resources/game-server-status/view.pug"),
330+
{
331+
server,
332+
mapThumbnail,
333+
image: true,
334+
}
335+
);
336+
337+
server.playerListImage = (await nodeHtmlToImage({
338+
html,
339+
transparent: true,
340+
selector: "main",
341+
puppeteerArgs: {
342+
args: ["--no-sandbox"],
343+
},
344+
})) as Buffer;
345+
332346
const messages = await channel.messages.fetch();
333347
const message = messages
334348
.filter((msg: Discord.Message) => msg.author.id == discord.user?.id)
@@ -337,13 +351,29 @@ export default class StatusPayload extends Payload {
337351
await message
338352
.edit({
339353
components: [container],
354+
files: [
355+
new Discord.AttachmentBuilder(server.playerListImage, {
356+
name: "players.png",
357+
}),
358+
new Discord.AttachmentBuilder(mapThumbnail ?? DEFAULT_THUMBNAIL, {
359+
name: "map.png",
360+
}),
361+
],
340362
flags: Discord.MessageFlags.IsComponentsV2,
341363
})
342364
.catch();
343365
} else {
344366
channel
345367
.send({
346368
components: [container],
369+
files: [
370+
new Discord.AttachmentBuilder(server.playerListImage, {
371+
name: "players.png",
372+
}),
373+
new Discord.AttachmentBuilder(mapThumbnail ?? DEFAULT_THUMBNAIL, {
374+
name: "map.png",
375+
}),
376+
],
347377
flags: Discord.MessageFlags.IsComponentsV2,
348378
})
349379
.catch();

resources/game-server-status/view.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ html(lang="en")
1717
justify-content: center;
1818
}
1919
body
20-
main(style=`background-image: url(${server.status.mapThumbnail})`)
20+
main(style=`background-image: url(${mapThumbnail})`)
2121
ul.playerlist
2222
each player in server.status.players
2323
li.player(class={ 'is-admin': player.isAdmin, 'is-banned': player.isBanned, 'is-afk': player.isAfk, 'is-pirate': player.isPirate })

0 commit comments

Comments
 (0)