Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add /bikeshed command component #30

Merged
merged 3 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export class TextBasedCommand extends Command {
public member: Discord.GuildMember | Discord.APIInteractionGuildMember | null;
public readonly user: Discord.User;

private response: Discord.Message | Discord.InteractionResponse | null = null;
public response: Discord.Message | Discord.InteractionResponse | null = null;
public replied = false;
private editing = false;

Expand Down
63 changes: 63 additions & 0 deletions src/components/bikeshed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import * as Discord from "discord.js";

import { strict as assert } from "assert";

import { M } from "../utils.js";
import { colors } from "../common.js";
import { BotComponent } from "../bot-component.js";
import { Wheatley } from "../wheatley.js";
import { TextBasedCommand, TextBasedCommandBuilder } from "../command.js";

const U_ARROW_DOUBLE_UP = "\u23eb";
Eisenwave marked this conversation as resolved.
Show resolved Hide resolved
const U_ARROW_DOUBLE_DOWN = "\u23ec";
const U_ARROW_UP = "\u2B06\uFE0F";
const U_ARROW_DOWN = "\u2B07\uFE0F";
const U_RECORD_BUTTON = "\u23FA\uFE0F";

const OPTIONS = [
{ symbol: U_ARROW_DOUBLE_UP, text: "Strongly Favor" },
{ symbol: U_ARROW_UP, text: "Favor" },
{ symbol: U_RECORD_BUTTON, text: "Neutral" },
{ symbol: U_ARROW_DOWN, text: "Against" },
{ symbol: U_ARROW_DOUBLE_DOWN, text: "Strongly Against" },
];

const DESCRIPTION = OPTIONS.map(({ symbol, text }) => `${symbol} - ${text}`).join("\n");

/**
* Adds a /bikeshed command for creating polls with responses ranging from
* strongly favor to strongly against.
*/
export default class Bikeshed extends BotComponent {
static override get is_freestanding() {
return true;
}

constructor(wheatley: Wheatley) {
super(wheatley);

this.add_command(
new TextBasedCommandBuilder("bikeshed")
.set_description("Create a poll from strongly favor to strongly against")
.add_string_option({
title: "title",
description: "The title of the poll",
required: true,
})
.set_handler(Bikeshed.bikeshed),
);
}

static async bikeshed(command: TextBasedCommand, arg: string) {
Eisenwave marked this conversation as resolved.
Show resolved Hide resolved
M.log("Creating bikeshed poll for question ");
await command.reply({
embeds: [new Discord.EmbedBuilder().setColor(colors.color).setTitle(arg).setDescription(DESCRIPTION)],
});
for (const option of OPTIONS) {
const message = await command.response!.fetch();
// Await in a loop is intentional here.
// Reactions have to be applied in a consistent order.
await message.react(option.symbol);
}
}
}