Complete contextdelete command
This commit is contained in:
parent
9d57598352
commit
654e360f37
|
@ -23,8 +23,9 @@ import {
|
||||||
ContextMenuCommandType
|
ContextMenuCommandType
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import Logger from "../utils/Logger";
|
import Logger from "../utils/Logger";
|
||||||
|
import { dt } from "../main";
|
||||||
|
import { deleteConfession } from "../commandutils";
|
||||||
import { messageOpts } from "../constants";
|
import { messageOpts } from "../constants";
|
||||||
import { BotClient } from "../bot";
|
|
||||||
|
|
||||||
const logger = new Logger("(:) contextdel");
|
const logger = new Logger("(:) contextdel");
|
||||||
|
|
||||||
|
@ -37,12 +38,20 @@ export const data = new ContextMenuCommandBuilder()
|
||||||
.setType(ApplicationCommandType.Message as ContextMenuCommandType);
|
.setType(ApplicationCommandType.Message as ContextMenuCommandType);
|
||||||
|
|
||||||
export async function execute(interaction: ContextMenuCommandInteraction) {
|
export async function execute(interaction: ContextMenuCommandInteraction) {
|
||||||
const text = `Target: ${interaction.targetId}`;
|
const { guildId, targetId } = interaction;
|
||||||
|
|
||||||
logger.log(text);
|
if (!dt.getConfessionById(guildId!, targetId)) {
|
||||||
|
return interaction.reply({
|
||||||
|
content: "Either that confession wasn't found or you aren't allowed to remove it.",
|
||||||
|
...messageOpts
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return interaction.reply({
|
const { id: confessionId } = dt.getConfessionById(guildId!, targetId)!;
|
||||||
content: text,
|
|
||||||
...messageOpts
|
try {
|
||||||
});
|
deleteConfession(interaction, confessionId);
|
||||||
|
} catch (err) {
|
||||||
|
logger.error("An error occured:", err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,6 +182,20 @@ export class StoreMan {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getConfessionById(guildId: string, messageId: string): Confession | null {
|
||||||
|
for (const guild of this.data) {
|
||||||
|
if (guild.id === guildId) {
|
||||||
|
for (const confession of guild.confessions) {
|
||||||
|
if (confession.messageId === messageId) {
|
||||||
|
return confession;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Attempts to delete a confession. If it is sucessfully deleted, returns true, else false.
|
// Attempts to delete a confession. If it is sucessfully deleted, returns true, else false.
|
||||||
public delConfesssion(
|
public delConfesssion(
|
||||||
{ guild, user }: CommandInteraction,
|
{ guild, user }: CommandInteraction,
|
||||||
|
|
Loading…
Reference in a new issue