Skip to content

Commit 087ecc4

Browse files
Techbot121Meta Construct
authored and
Meta Construct
committed
switch status display to component
1 parent 813e5fe commit 087ecc4

File tree

1 file changed

+87
-52
lines changed

1 file changed

+87
-52
lines changed

app/services/gamebridge/payloads/StatusPayload.ts

+87-52
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as requestSchema from "./structures/StatusRequest.json";
2-
import { CountdownType } from "./structures/StatusRequest";
32
import { GameServer } from "..";
43
import { StatusRequest } from "./structures";
54
import Discord, { TextChannel } from "discord.js";
@@ -101,9 +100,6 @@ export default class StatusPayload extends Payload {
101100
const gamemodeExtras = GamemodeExtras[gamemodeName as keyof typeof GamemodeExtras];
102101
const gamemodeIcon = gamemodeExtras?.seagull ?? gamemodeExtras?.icon;
103102

104-
if (current_countdown && current_countdown.typ === CountdownType.AOWL_COUNTDOWN_CUSTOM)
105-
return;
106-
107103
const count = current_players.length;
108104

109105
if (!discord) return;
@@ -155,7 +151,7 @@ export default class StatusPayload extends Payload {
155151
}
156152
// Permanent status message
157153
// Map name w/ workshop link
158-
let desc = `>>> ### ${
154+
let desc = `### ${
159155
current_workshopMap
160156
? `[${current_workshopMap.name}](https://steamcommunity.com/sharedfiles/filedetails/?id=${current_workshopMap.id})`
161157
: current_map
@@ -170,8 +166,8 @@ export default class StatusPayload extends Payload {
170166
const servertime = dayjs().subtract(current_serverUptime, "s").unix();
171167
const maptime = dayjs().subtract(current_mapUptime, "s").unix();
172168

173-
desc += `\n:repeat: Map uptime: <t:${maptime}:R>`;
174-
desc += `\n:file_cabinet: Server uptime: <t:${servertime}:R>`;
169+
desc += `\n:repeat: Map up since: <t:${maptime}:R>`;
170+
desc += `\n:file_cabinet: Server up since: <t:${servertime}:R>`;
175171
if (current_countdown)
176172
desc += `\n<a:ALERTA:843518761160015933> \`${current_countdown.text} in ${current_countdown.time} seconds\` <a:ALERTA:843518761160015933>`;
177173
if (current_defcon && current_defcon !== 5)
@@ -186,58 +182,92 @@ export default class StatusPayload extends Payload {
186182
} else if (current_map && current_map.toLowerCase().trim() == "rp_unioncity") {
187183
mapThumbnail = `${url}/map-thumbnails/rp_unioncity.png`;
188184
}
185+
186+
if (!mapThumbnail && current_workshopMap) {
187+
const res = await Steam.getPublishedFileDetails([current_workshopMap.id]).catch(
188+
console.error
189+
);
190+
const thumbnailURI = res?.publishedfiledetails?.[0]?.preview_url;
191+
192+
if (thumbnailURI) {
193+
mapThumbnail = thumbnailURI;
194+
}
195+
}
189196
}
190197

191-
const embed = new Discord.EmbedBuilder()
192-
.setColor(
198+
const container = {
199+
type: Discord.ComponentType.Container,
200+
accent_color:
193201
current_defcon === 1 || current_countdown
194202
? 0xff0000
195203
: current_gamemode
196204
? gamemodeExtras?.color ?? null
197-
: null
198-
)
199-
.setFooter({
200-
text: gamemodeName,
201-
iconURL: gamemodeExtras?.icon,
202-
})
203-
.setAuthor({
204-
name: server.config.name,
205-
iconURL: gamemodeIcon,
206-
url: `https://metastruct.net/${
207-
server.config.label ? "join/" + server.config.label : ""
208-
}`,
209-
})
210-
.setDescription(desc)
211-
.setThumbnail(mapThumbnail);
205+
: null,
206+
components: [
207+
{
208+
type: Discord.ComponentType.Section,
209+
components: [
210+
{
211+
type: Discord.ComponentType.TextDisplay,
212+
content: desc,
213+
},
214+
],
215+
accessory: {
216+
type: Discord.ComponentType.Thumbnail,
217+
media: {
218+
url: mapThumbnail ?? `${url}/map-thumbnails/gm_construct_m.png`,
219+
},
220+
description: current_map,
221+
},
222+
},
223+
],
224+
} as Discord.APIContainerComponent;
212225

213226
if (count > 0) {
214-
embed
215-
.setImage(
216-
players
217-
? `http://${host}:${port}/server-status/${
218-
server.config.id
219-
}/${Date.now()}`
220-
: server.status.image
221-
)
222-
.setFooter({
223-
text: `${
224-
embed.data.footer ? `${embed.data.footer.text} | ` : ""
225-
}Middle-click the player list to open an interactive version`,
226-
iconURL: embed.data.footer?.icon_url,
227-
});
228-
}
229-
230-
if (mapThumbnail === null && current_workshopMap) {
231-
const res = await Steam.getPublishedFileDetails([current_workshopMap.id]).catch(
232-
console.error
227+
container.components.push(
228+
{ type: Discord.ComponentType.Separator },
229+
{
230+
type: Discord.ComponentType.MediaGallery,
231+
items: [
232+
{
233+
media: {
234+
url: players
235+
? `http://${host}:${port}/server-status/${
236+
server.config.id
237+
}/${Date.now()}`
238+
: server.status.image ?? "",
239+
},
240+
},
241+
],
242+
}
233243
);
234-
const thumbnailURI = res?.publishedfiledetails?.[0]?.preview_url;
235-
236-
if (thumbnailURI) {
237-
embed.setThumbnail(thumbnailURI);
238-
mapThumbnail = thumbnailURI;
239-
}
240244
}
245+
// footer
246+
container.components.push(
247+
{ type: Discord.ComponentType.Separator },
248+
{
249+
type: Discord.ComponentType.TextDisplay,
250+
content: `-# ${gamemodeName}${
251+
count > 0
252+
? " | Middle-click the player list to open an interactive version"
253+
: ""
254+
}`,
255+
}
256+
);
257+
258+
container.components.push({
259+
type: Discord.ComponentType.ActionRow,
260+
components: [
261+
{
262+
type: Discord.ComponentType.Button,
263+
style: Discord.ButtonStyle.Link,
264+
label: "Connect",
265+
url: `https://metastruct.net/${
266+
server.config.label ? "join/" + server.config.label : ""
267+
}`,
268+
},
269+
],
270+
});
241271

242272
if (mapThumbnail && server.discordBanner !== mapThumbnail) {
243273
server.changeBanner(mapThumbnail);
@@ -257,7 +287,12 @@ export default class StatusPayload extends Payload {
257287
server.mapName = current_map;
258288
server.mapUptime = current_mapUptime;
259289
server.serverUptime = current_serverUptime;
260-
server.status.image = embed.data.image?.url ?? null;
290+
server.status.image =
291+
(
292+
container.components.find(
293+
c => c.type === Discord.ComponentType.MediaGallery
294+
) as Discord.APIMediaGalleryComponent
295+
)?.items[0].media.url ?? null;
261296
server.status.mapThumbnail = mapThumbnail;
262297
server.status.players = current_players;
263298
server.workshopMap = current_workshopMap;
@@ -294,9 +329,9 @@ export default class StatusPayload extends Payload {
294329
.filter((msg: Discord.Message) => msg.author.id == discord.user?.id)
295330
.first();
296331
if (message) {
297-
await message.edit({ embeds: [embed] }).catch();
332+
await message.edit({ components: [container], flags: 1 << 15 }).catch();
298333
} else {
299-
channel.send({ embeds: [embed] }).catch();
334+
channel.send({ components: [container], flags: 1 << 15 }).catch();
300335
}
301336
};
302337

0 commit comments

Comments
 (0)