Skip to content

Commit

Permalink
add gamemode support & autocomplete for the ban command
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot121 authored and Meta Construct committed Jun 9, 2024
1 parent 4210095 commit 6549972
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
22 changes: 19 additions & 3 deletions app/services/discord/modules/commands/developer/Ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ const Ban = async (nickname: string, ctx: Discord.ChatInputCommandInteraction, b
const length = Math.round(
Date.now() / 1000 + parseLength(ctx.options.getString("length", true))
);
const gamemode = ctx.options.getString("gamemode");
const reason = ctx.options.getString("reason") ?? "no reason";
const code =
`if not banni then return false end ` +
`local data = banni.Ban("${steamid}", "${plyName}", "Discord (${ctx.user.username}|${ctx.user.mention})", [[${reason}]], ${length}) ` +
`local data = banni.Ban("${steamid}", "${plyName}", "Discord (${ctx.user.username}|${
ctx.user.mention
})", [[${reason}]], ${length}, false, ${gamemode ?? "nil"}) ` +
`if istable(data) then return data.b else return data end`;
try {
const res = await server.sendLua(code, "sv", ctx.user.displayName);
Expand Down Expand Up @@ -116,7 +119,11 @@ export const SlashBanCommand: SlashCommand = {
type: Discord.ApplicationCommandOptionType.String,
name: "reason",
description: "The reason for the ban",
required: false,
},
{
type: Discord.ApplicationCommandOptionType.String,
name: "gamemode",
description: "the gamemode to ban from (sandbox_modded by default)",
},
{
type: Discord.ApplicationCommandOptionType.Integer,
Expand Down Expand Up @@ -164,9 +171,18 @@ export const SlashBanCommand: SlashCommand = {
async autocomplete(ctx, bot) {
const focused = ctx.options.getFocused(true);
switch (focused.name) {
case "gamemode": {
const gamemodes = bot.bridge?.servers[
ctx.options.getInteger("server") ?? 2
]?.gamemodes.map(name => {
return { name: name, value: name };
});
await ctx.respond(gamemodes ?? []);
break;
}
case "steamid": {
const players =
bot.bridge?.servers[ctx.options.getInteger("server") ?? 2].status.players;
bot.bridge?.servers[ctx.options.getInteger("server") ?? 2]?.status.players;
if (!players) {
await ctx.respond([]);
return;
Expand Down
1 change: 1 addition & 0 deletions app/services/gamebridge/GameServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default class GameServer {
folderName: string;
name: string;
};
gamemodes: string[];
playerListImage: Buffer;
serverUptime: number;
status: {
Expand Down
9 changes: 6 additions & 3 deletions app/services/gamebridge/payloads/StatusPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default class StatusPayload extends Payload {
gamemode,
serverUptime,
mapUptime,
gamemodes,
} = payload.data;
const { bridge, discord } = server;
const webApp = bridge.container.getService("WebApp");
Expand All @@ -97,6 +98,7 @@ export default class StatusPayload extends Payload {
const current_map = mapName ?? server.mapName ?? "unknown map";
const current_gamemode = gamemode ??
server.gamemode ?? { folderName: "???", name: "unknown gamemode" };
const current_gamemodes = gamemodes ?? server.gamemodes ?? [];
const current_serverUptime = serverUptime ?? server.serverUptime ?? 0;
const current_mapUptime = mapUptime ?? server.mapUptime ?? 0;
const current_workshopMap = workshopMap ?? server.workshopMap;
Expand Down Expand Up @@ -252,14 +254,15 @@ export default class StatusPayload extends Payload {
}

// Server status metadata
server.status.mapThumbnail = mapThumbnail;
server.status.image = embed.data.image?.url ?? null;
server.status.players = current_players;
server.defcon = current_defcon;
server.gamemode = current_gamemode;
server.gamemodes = current_gamemodes;
server.mapName = current_map;
server.mapUptime = current_mapUptime;
server.serverUptime = current_serverUptime;
server.status.image = embed.data.image?.url ?? null;
server.status.mapThumbnail = mapThumbnail;
server.status.players = current_players;
server.workshopMap = current_workshopMap;

for (const [, player] of Object.entries(server.status.players)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export default interface StatusRequest extends PayloadRequest {
folderName: string;
name: string;
};
gamemodes?: string[];
};
}

0 comments on commit 6549972

Please sign in to comment.