Skip to content

Commit

Permalink
Say logs (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
RafDevX authored Sep 18, 2021
1 parent b053411 commit 81a0118
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion src/modules/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as Builders from "@discordjs/builders";
import { CommandDescriptor } from "../bot.d";
import { CommandPermission } from "../bot";
import * as utils from "./utils";
import { SlashCommandBuilder } from "@discordjs/builders";

export function provideCommands(): CommandDescriptor[] {
const say = new Builders.SlashCommandBuilder()
Expand All @@ -33,6 +34,15 @@ export function provideCommands(): CommandDescriptor[] {
)
.setRequired(false)
);
const whoSaid = new SlashCommandBuilder()
.setName("who-said")
.setDescription("Shows who ordered the bot to say something");
whoSaid.addStringOption(
new Builders.SlashCommandStringOption()
.setName("message-id")
.setDescription("Message ID in question")
.setRequired(true)
);
return [
{
builder: new Builders.SlashCommandBuilder()
Expand All @@ -45,6 +55,10 @@ export function provideCommands(): CommandDescriptor[] {
builder: say,
handler: handleSayCommand,
},
{
builder: whoSaid,
handler: handleWhoSaidCommand,
},
];
}

Expand Down Expand Up @@ -92,6 +106,8 @@ export async function handleAboutCommand(
});
}

const sayLogs: Discord.Collection<string, string> = new Discord.Collection();

export async function handleSayCommand(
interaction: Discord.CommandInteraction
): Promise<void> {
Expand All @@ -103,10 +119,21 @@ export async function handleSayCommand(
interaction.options.getBoolean("allow-mentions", false) ?? false;

if (channel && channel.isText()) {
await channel.send({
const msg = await channel.send({
content: message.replace(/\\n/g, "\n"),
allowedMentions: allowMentions ? undefined : { parse: [] },
});
const uid = interaction.member?.user.id;
if (uid) {
sayLogs.set(msg.id, uid);
console.log(
`User ${
interaction.member?.user.username
} said «${message}» (w/${
allowMentions ? "" : "o"
} mentions)`
);
}
await interaction.editReply("✅ Successfully sent message.");
return;
}
Expand All @@ -115,3 +142,23 @@ export async function handleSayCommand(
await interaction.editReply("❌ Something went wrong.");
}
}

export async function handleWhoSaidCommand(
interaction: Discord.CommandInteraction
): Promise<void> {
try {
const messageId = interaction.options.getString("message-id", true);
const split = messageId.split("-");
const who = sayLogs.get(split[split.length - 1]);

if (who) {
await interaction.editReply(`<@${who}> said it!`);
} else {
await interaction.editReply("I don't know who said it...");
}
} catch (e) {
await interaction.editReply(
"❌ Something went wrong, maybe wrong message ID?"
);
}
}

0 comments on commit 81a0118

Please sign in to comment.