Skip to content

Commit c4bd092

Browse files
committed
feat: Add slapCommand to bring back the IRC vibe of trout slapping
1 parent b6e178c commit c4bd092

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ export * from "./quickLinksCommand";
2626
export * from "./quoteCommand";
2727
export * from "./testCommand";
2828
export * from "./userCommand";
29+
export * from "./slapCommand";

src/commands/slapCommand.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
3+
*
4+
* SPDX-License-Identifier: BSD-2-Clause
5+
*/
6+
7+
import { ChatInputCommandInteraction, GuildMember, SlashCommandBuilder } from "discord.js";
8+
import Command from "./command";
9+
10+
export class SlapCommand extends Command {
11+
private readonly baseReply: string = `*$USER slaps $TARGET around a bit with a large trout*`;
12+
13+
override data() {
14+
const aliases = ["slap"];
15+
const description = "Slap someone around a bit with a large trout";
16+
17+
const baseCommand = new SlashCommandBuilder()
18+
.setDescription(description)
19+
.addUserOption(user => user.setName("target").setDescription("The user to slap"));
20+
21+
return aliases.map(name => baseCommand.setName(name).toJSON());
22+
}
23+
24+
override async handleCommand(interaction: ChatInputCommandInteraction): Promise<void> {
25+
if (!interaction.isCommand()) return;
26+
27+
let content = this.baseReply;
28+
29+
const target = interaction.options.getMember("target");
30+
const user = interaction.member;
31+
let username = "";
32+
if (user instanceof GuildMember) {
33+
username = user.displayName;
34+
} else {
35+
username = user?.nick ?? user?.user.username ?? "Someone";
36+
}
37+
38+
let targetName = "";
39+
if (target instanceof GuildMember) {
40+
targetName = target.displayName;
41+
} else {
42+
targetName = target?.nick ?? "Someone";
43+
}
44+
45+
if (user) content = content.replace("$USER", `@${username}`);
46+
if (target) content = content.replace("$TARGET", `@${targetName}`);
47+
48+
await interaction.reply({
49+
content,
50+
});
51+
}
52+
}

0 commit comments

Comments
 (0)