Skip to content

Commit

Permalink
Add !topic command
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Nov 9, 2024
1 parent 573efa7 commit 45c78e8
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/components/topic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as Discord from "discord.js";

import { strict as assert } from "assert";

import { M } from "../utils/debugging-and-logging.js";
import { colors } from "../common.js";
import { BotComponent } from "../bot-component.js";
import { Wheatley, create_error_reply } from "../wheatley.js";
import { EarlyReplyMode, TextBasedCommandBuilder } from "../command-abstractions/text-based-command-builder.js";
import { TextBasedCommand } from "../command-abstractions/text-based-command.js";
import { build_description } from "../utils/strings.js";

export default class Topic extends BotComponent {
static override get is_freestanding() {
return true;
}

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

this.add_command(
new TextBasedCommandBuilder("topic", EarlyReplyMode.none)
.set_description("Posts the channel topic")
.set_handler(this.topic.bind(this)),
);
}

async topic(command: TextBasedCommand) {
const channel = await command.get_channel();
if (channel.isDMBased() || channel.isThread() || channel.isVoiceBased()) {
await command.reply("Must be used in a guild text-based non-thread channel");
return;
}
if (channel.topic) {
await command.reply(channel.topic);
} else {
await command.reply("No channel description set");
}
}
}

0 comments on commit 45c78e8

Please sign in to comment.