Skip to content

Commit

Permalink
refactor: migrated to new discord command structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kk committed Nov 25, 2023
1 parent 247ad1f commit 97a65ef
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/discord/guild/GuildAcceptMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { CommandBase, CommandExecution } from "../../util/SlashCommandHandler";
import { Client, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { MinecraftBot } from "../../index";

export default class GuildMuteMember extends CommandBase {
constructor(discordClient: Client<true>, botInstance: MinecraftBot) {
super({
discordClient,
botInstance,
commandBuilder: new SlashCommandBuilder()
.setName("accept")
.setDescription("Accepts a member into the guild")
.addStringOption((command) => command.setName("player_name").setDescription("The name of the player you'd like to accept.").setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
});
}

async execute({ interaction, discordCommandMap }: CommandExecution): Promise<void> {
if (await this.hasPermissionToExecute({ interaction, discordCommandMap })) {
this.getBotInstance()
.getMineflayerInstance()
.chat(`/g accept ${interaction.options.get("player_name")?.value}`);
await interaction.editReply("Command has been executed!");
}
}
}
26 changes: 26 additions & 0 deletions src/discord/guild/GuildDemoteMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { CommandBase, CommandExecution } from "../../util/SlashCommandHandler";
import { Client, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { MinecraftBot } from "../../index";

export default class GuildDemoteMember extends CommandBase {
constructor(discordClient: Client<true>, botInstance: MinecraftBot) {
super({
discordClient,
botInstance,
commandBuilder: new SlashCommandBuilder()
.setName("demote")
.setDescription("Demotes a member in the guild")
.addStringOption((command) => command.setName("player_name").setDescription("The name of the player you'd like to demote.").setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
});
}

async execute({ interaction, discordCommandMap }: CommandExecution): Promise<void> {
if (await this.hasPermissionToExecute({ interaction, discordCommandMap })) {
this.getBotInstance()
.getMineflayerInstance()
.chat(`/g demote ${interaction.options.get("player_name")?.value}`);
await interaction.editReply("Command has been executed!");
}
}
}
27 changes: 27 additions & 0 deletions src/discord/guild/GuildKickPlayer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CommandBase, CommandExecution } from "../../util/SlashCommandHandler";
import { Client, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { MinecraftBot } from "../../index";

export default class GuildKickPlayer extends CommandBase {
constructor(discordClient: Client<true>, botInstance: MinecraftBot) {
super({
discordClient,
botInstance,
commandBuilder: new SlashCommandBuilder()
.setName("kick")
.setDescription("Kicks a member from the guild")
.addStringOption((options) => options.setName("player_name").setDescription("The name of the player you'd like to kick.").setRequired(true))
.addStringOption((options) => options.setName("reason").setDescription("Reason to kick the player").setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
});
}

async execute({ interaction, discordCommandMap }: CommandExecution): Promise<void> {
if (await this.hasPermissionToExecute({ interaction, discordCommandMap })) {
this.getBotInstance()
.getMineflayerInstance()
.chat(`/g kick ${interaction.options.get("player_name")?.value} ${interaction.options.get("reason")?.value}`);
await interaction.editReply("Command has been executed!");
}
}
}
26 changes: 26 additions & 0 deletions src/discord/guild/GuildMemberInvite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { CommandBase, CommandExecution } from "../../util/SlashCommandHandler";
import { Client, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { MinecraftBot } from "../../index";

export default class GuildMuteMember extends CommandBase {
constructor(discordClient: Client<true>, botInstance: MinecraftBot) {
super({
discordClient,
botInstance,
commandBuilder: new SlashCommandBuilder()
.setName("invite")
.setDescription("Invites a member to the guild")
.addStringOption((command) => command.setName("player_name").setDescription("The name of the player you'd like to invite.").setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
});
}

async execute({ interaction, discordCommandMap }: CommandExecution): Promise<void> {
if (await this.hasPermissionToExecute({ interaction, discordCommandMap })) {
this.getBotInstance()
.getMineflayerInstance()
.chat(`/g invite ${interaction.options.get("player_name")?.value}`);
await interaction.editReply("Command has been executed!");
}
}
}
27 changes: 27 additions & 0 deletions src/discord/guild/GuildMuteMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CommandBase, CommandExecution } from "../../util/SlashCommandHandler";
import { Client, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { MinecraftBot } from "../../index";

export default class GuildMuteMember extends CommandBase {
constructor(discordClient: Client<true>, botInstance: MinecraftBot) {
super({
discordClient,
botInstance,
commandBuilder: new SlashCommandBuilder()
.setName("mute")
.setDescription("Mutes a member in the guild")
.addStringOption((command) => command.setName("player_name").setDescription("The name of the player you'd like to mute.").setRequired(true))
.addStringOption((options) => options.setName("time_period").setDescription("Time period to mute").setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
});
}

async execute({ interaction, discordCommandMap }: CommandExecution): Promise<void> {
if (await this.hasPermissionToExecute({ interaction, discordCommandMap })) {
this.getBotInstance()
.getMineflayerInstance()
.chat(`/g mute ${interaction.options.get("player_name")?.value} ${interaction.options.get("time_period")?.value}`);
await interaction.editReply("Command has been executed!");
}
}
}
26 changes: 26 additions & 0 deletions src/discord/guild/GuildPromoteMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { CommandBase, CommandExecution } from "../../util/SlashCommandHandler";
import { Client, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { MinecraftBot } from "../../index";

export default class GuildPromoteMember extends CommandBase {
constructor(discordClient: Client<true>, botInstance: MinecraftBot) {
super({
discordClient,
botInstance,
commandBuilder: new SlashCommandBuilder()
.setName("promote")
.setDescription("Promotes a member in the guild")
.addStringOption((command) => command.setName("player_name").setDescription("The name of the player you'd like to promote.").setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
});
}

async execute({ interaction, discordCommandMap }: CommandExecution): Promise<void> {
if (await this.hasPermissionToExecute({ interaction, discordCommandMap })) {
this.getBotInstance()
.getMineflayerInstance()
.chat(`/g promote ${interaction.options.get("player_name")?.value}`);
await interaction.editReply("Command has been executed!");
}
}
}
26 changes: 26 additions & 0 deletions src/discord/guild/GuildUnmuteMember.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { CommandBase, CommandExecution } from "../../util/SlashCommandHandler";
import { Client, PermissionsBitField, SlashCommandBuilder } from "discord.js";
import { MinecraftBot } from "../../index";

export default class GuildUnmuteMember extends CommandBase {
constructor(discordClient: Client<true>, botInstance: MinecraftBot) {
super({
discordClient,
botInstance,
commandBuilder: new SlashCommandBuilder()
.setName("unmute")
.setDescription("Unmutes a member in the guild")
.addStringOption((command) => command.setName("player_name").setDescription("The name of the player you'd like to unmute.").setRequired(true))
.setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator),
});
}

async execute({ interaction, discordCommandMap }: CommandExecution): Promise<void> {
if (await this.hasPermissionToExecute({ interaction, discordCommandMap })) {
this.getBotInstance()
.getMineflayerInstance()
.chat(`/g unmute ${interaction.options.get("player_name")?.value}`);
await interaction.editReply("Command has been executed!");
}
}
}
2 changes: 2 additions & 0 deletions src/util/SlashCommandHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export abstract class CommandBase {

protected getPermissions = () => this.permissionNodes;

protected getBotInstance = () => this.botInstance;

protected hasPermissionToExecute = async ({ interaction, discordCommandMap }: CommandExecution) => {
const guild = this.discordClient.guilds.cache.get(process.env.DISCORD_GUILD_ID!);
if (guild) {
Expand Down

0 comments on commit 97a65ef

Please sign in to comment.