Skip to content

Commit

Permalink
Adding commands for manual user adding
Browse files Browse the repository at this point in the history
  • Loading branch information
pattyjogal committed Sep 25, 2021
1 parent 99ee31b commit 849425d
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 29 deletions.
51 changes: 42 additions & 9 deletions src/commands/tenmans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class QueueAction<

abstract updateQueue();

afterUserExecute(): Promise<any> {
async afterUserExecute(): Promise<any> {
if (activeTenmansMessage === null) {
this.interaction.reply({
content: "I must wait a moment! There is no active 10mans queue.",
Expand All @@ -42,7 +42,7 @@ abstract class QueueAction<
return;
}

this.updateQueue();
await this.updateQueue();

activeTenmansMessage.edit({
embeds: [createEmbed(time)],
Expand Down Expand Up @@ -72,6 +72,36 @@ class LeaveQueueButtonAction extends QueueAction<ButtonInteraction> {
}
}

class ManualAddUserToQueue extends QueueAction<CommandInteraction> {
async updateQueue() {
const targetUser = this.interaction.options.getUser("member");
const targetMember = (await this.db.collection("members").findOne({
discordId: targetUser.id,
})) as Member;
tenmansQueue.push(targetMember);
this.interaction.reply({
content: `User \`${targetUser.username}\` added to the queue.`,
ephemeral: true,
});
}
}

class ManualRemoveUserToQueue extends QueueAction<CommandInteraction> {
async updateQueue() {
const targetUser = this.interaction.options.getUser("member");
const targetMember = (await this.db.collection("members").findOne({
discordId: targetUser.id,
})) as Member;
tenmansQueue = tenmansQueue.filter(
(member) => member.discordId !== targetMember.discordId
);
this.interaction.reply({
content: `User \`${targetUser.username}\` removed from the queue.`,
ephemeral: true,
});
}
}

class SubcommandTenmansStart extends MessageExecutable<CommandInteraction> {
async execute(): Promise<any> {
const interaction_user = this.interaction.user;
Expand Down Expand Up @@ -133,22 +163,25 @@ class TenmansCloseSubcommand extends MessageExecutable<CommandInteraction> {
}

// Teardown - clear current queue
tenmansQueue = []
tenmansQueue = [];
await activeTenmansMessage.delete();
}
}

export async function cmd_tenmans(interaction, db: Db) {
export async function cmd_tenmans(interaction: CommandInteraction, db: Db) {
const commands: {
[key: string]: {
new (
interaction: Interaction,
db: Db
db: Db,
queueId: string
): MessageExecutable<CommandInteraction>;
};
} = {
start: SubcommandTenmansStart,
end: TenmansCloseSubcommand
end: TenmansCloseSubcommand,
add_user: ManualAddUserToQueue,
remove_user: ManualRemoveUserToQueue,
};

// Wrap function call to pass same args to all methods
Expand All @@ -157,11 +190,11 @@ export async function cmd_tenmans(interaction, db: Db) {
console.error("Bad action:", interaction.options.getSubcommand());
interaction.reply({
ephemeral: true,
content: "Error logged; please tell an admin what you were trying to do."
content: "Error logged; please tell an admin what you were trying to do.",
});
return;
}
const command = new Action(interaction, db);
const command = new Action(interaction, db, interaction.options.getString("queueId"));
command.execute();
}

Expand All @@ -185,7 +218,7 @@ export async function handleButton(interaction: ButtonInteraction, db: Db) {
console.error("Bad action:", interaction.customId);
interaction.reply({
ephemeral: true,
content: "Error logged; please tell an admin what you were trying to do."
content: "Error logged; please tell an admin what you were trying to do.",
});
return;
}
Expand Down
83 changes: 63 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ const commands = [
},
{
name: "pronouns",
description: "Your preferred third-person pronouns (used by casters)",
description:
"Your preferred third-person pronouns (used by casters)",
type: ApplicationCommandOptionType.String,
required: true,
},
]
],
},
{
name: "update",
Expand All @@ -43,12 +44,13 @@ const commands = [
},
{
name: "pronouns",
description: "Your new preferred third-person pronouns (used by casters)",
description:
"Your new preferred third-person pronouns (used by casters)",
type: ApplicationCommandOptionType.String,
required: false,
},
]
}
],
},
],
},
{
Expand All @@ -64,16 +66,16 @@ const commands = [
name: "time",
description: "The time to start queue",
type: ApplicationCommandOptionType.String,
}
]
},
],
},
{
name: "close",
description: "Closes a 10mans queue",
type: ApplicationCommandOptionType.Subcommand,
options: [
// TODO: Add an option for queue id after adding multi-queue support
]
],
},
{
name: "vote",
Expand All @@ -83,11 +85,49 @@ const commands = [
{
name: "time",
description: "The time to start the queue",
type: ApplicationCommandOptionType.String
}
]
}
]
type: ApplicationCommandOptionType.String,
},
],
},
{
name: "add_user",
description: "Adds a specified user to a 10mans queue",
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: "member",
description: "The member to add to the queue",
type: ApplicationCommandOptionType.User,
required: true
},
{
name: "queue_id",
description: "The queue to modify",
type: ApplicationCommandOptionType.String,
required: false
},
],
},
{
name: "remove_user",
description: "Removes a specified user to a 10mans queue",
type: ApplicationCommandOptionType.Subcommand,
options: [
{
name: "member",
description: "The member to remove from the queue",
type: ApplicationCommandOptionType.User,
required: true
},
{
name: "queue_id",
description: "The queue to modify",
type: ApplicationCommandOptionType.String,
required: false
},
],
},
],
},
{
name: "config",
Expand All @@ -101,12 +141,12 @@ const commands = [
{
name: "channel",
description: "Channel to place messages",
type: ApplicationCommandOptionType.Channel
}
]
}
]
}
type: ApplicationCommandOptionType.Channel,
},
],
},
],
},
];

const rest = new REST({ version: "9" }).setToken(process.env.CYPHERBOT_TOKEN);
Expand All @@ -116,7 +156,10 @@ const rest = new REST({ version: "9" }).setToken(process.env.CYPHERBOT_TOKEN);
console.log("Started refreshing application (/) commands.");

await rest.put(
Routes.applicationGuildCommands(process.env.CYPHERBOT_CLIENT_ID, process.env.CYPHERBOT_TARGET_GUILD_ID),
Routes.applicationGuildCommands(
process.env.CYPHERBOT_CLIENT_ID,
process.env.CYPHERBOT_TARGET_GUILD_ID
),
{
body: commands,
}
Expand Down

0 comments on commit 849425d

Please sign in to comment.