Skip to content

Commit

Permalink
UPDATE basic commands
Browse files Browse the repository at this point in the history
  • Loading branch information
markkhoo committed May 9, 2023
1 parent d3f3f78 commit b44991c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Command } from "./types/Command";
import { List } from "./commands/List";
import { Online } from "./commands/Online";
import { PlayerAdd } from "./commands/PlayerAdd";
import { PlayerRemove } from "./commands/PlayerRemove";
import { Status } from "./commands/Status";

export const Commands: Command[] = [List, PlayerAdd, PlayerRemove, Status];
export const Commands: Command[] = [List, Online, PlayerAdd, PlayerRemove, Status];
25 changes: 24 additions & 1 deletion src/commands/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,32 @@ export const List: Command = {

const res = await rcon.send("whitelist list").catch(console.error);

if (!res){
await interaction.reply({
content: "ERROR: Missing response",
ephemeral: true,
});
return;
}

let listOfUsersString: string;

if (res === "There are no whitelisted players") {
listOfUsersString = "There are no players in the allow-list";
} else {
listOfUsersString = "*Players in the allow-list:* ";

const listOfUsers = res.match(/(?<=: ).*/)[0].split(", ");

listOfUsers.map((user, index) => {
listOfUsersString += `\`${user}\``;
listOfUsersString += index === listOfUsers.length - 1 ? "" : ", ";
});
}

await interaction.reply({
ephemeral: true,
content: res ? res : "ERROR: Missing response"
content: listOfUsersString
});
}
};
28 changes: 28 additions & 0 deletions src/commands/Online.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CommandInteraction, Client } from "discord.js";
import { ApplicationCommandType, ApplicationCommandOptionType } from 'discord-api-types/v10';
import { Command } from "../types/Command";
import { rcon, verifyConnection } from '../setRCON';

export const Online: Command = {
name: "online",
description: "Lists the players online in the Minecraft Server",
type: ApplicationCommandType.ChatInput,
run: async (client: Client, interaction: CommandInteraction) => {
const connectStatus = await verifyConnection();

if (!connectStatus) {
await interaction.reply({
content: "NOT CONNECTED to Minecraft Server!",
ephemeral: true,
});
return;
}

const res = await rcon.send("list").catch(console.error);

await interaction.reply({
ephemeral: true,
content: res ? res : "ERROR: Missing response",
});
}
};
10 changes: 9 additions & 1 deletion src/commands/PlayerAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ export const PlayerAdd: Command = {

const res = await rcon.send(`whitelist add ${user}`).catch(console.error);

if (!res){
await interaction.reply({
content: "ERROR: Missing response",
ephemeral: true,
});
return;
}

await interaction.reply({
ephemeral: true,
content: res ? res : "ERROR: Missing response"
content: res.replace(/whitelist/gi, "allow-list").replace(user, `**${user}**`).replace(/player/gi, `**${user}**`)
});
}
};
10 changes: 9 additions & 1 deletion src/commands/PlayerRemove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ export const PlayerRemove: Command = {

const res = await rcon.send(`whitelist remove ${user}`).catch(console.error);

if (!res){
await interaction.reply({
content: "ERROR: Missing response",
ephemeral: true,
});
return;
}

await interaction.reply({
ephemeral: true,
content: res ? res : "ERROR: Missing response"
content: res.replace(/whitelist/gi, "allow-list").replace(user, `**${user}**`).replace(/player/gi, `**${user}**`)
});
}
};

0 comments on commit b44991c

Please sign in to comment.