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

chore: update disable.ts #110

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
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
49 changes: 31 additions & 18 deletions plugins/disable.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @ts-nocheck
//@ts-nocheck
/**
* @plugin
* Disables a command entirely, for whatever reasons you may need.
*
* @author @jacoobes [<@182326315813306368>]
* @author @Peter-MJ-Parker [<@371759410009341952>]
* @version 2.0.0
* @version 2.1.0
* @example
* ```ts
* import { disable } from "../plugins/disable";
Expand All @@ -20,36 +20,49 @@
* @end
*/
import { CommandType, CommandControlPlugin, controller } from "@sern/handler";
import { InteractionReplyOptions, ReplyMessageOptions } from "discord.js";
import { InteractionReplyOptions, MessageReplyOptions } from "discord.js";

export function disable(
onFail?:
| string
| Omit<InteractionReplyOptions, "fetchReply">
| ReplyMessageOptions,
| MessageReplyOptions
) {
return CommandControlPlugin<CommandType.Both>(async (ctx, [args]) => {
if (onFail !== undefined) {
switch (args) {
case "text":
//reply to text command
const msg = await ctx.reply(onFail);
setTimeout(() => {
//deletes the bots reply to the user
msg.delete();
//deletes the original authors message (text command).
ctx.message.delete();
//waits 5 seconds before deleting messages
}, 5000).catch((e) => {
//logs error to console (if any).
console.log(e);
});
try {
//reply to text command
const msg = await ctx.reply(onFail);
setTimeout(() => {
//deletes the bots reply to the user
msg.delete();
//deletes the original authors message (text command).
ctx.message.delete();
//waits 5 seconds before deleting messages
}, 5000);
} catch (error) {
console.log(
"Could not delete disabled response due to: " +
error
);
}

break;

case "slash":
//ephemeral response to say the command is disabled with users response.
await ctx.reply({ content: onFail, ephemeral: true });
//response to say the command is disabled with users response.
let reply = await ctx.reply(onFail);
try {
setTimeout(async () => {
await reply.delete();
}, 5000);
} catch (error) {
console.log(
"Could not delete disabled response due to it being ephemeral."
);
}
break;

default:
Expand Down
Loading