From bd27624e38fb8fab1f3425fc558a4efbc472a73f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 1 Aug 2022 08:50:39 +0530 Subject: [PATCH] chore: Update JavaScript plugins (#19) chore: update JavaScript plugins Co-authored-by: EvolutionX-10 --- JavaScript/nsfwOnly.js | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 JavaScript/nsfwOnly.js diff --git a/JavaScript/nsfwOnly.js b/JavaScript/nsfwOnly.js new file mode 100644 index 0000000..7a750f9 --- /dev/null +++ b/JavaScript/nsfwOnly.js @@ -0,0 +1,66 @@ +//@ts-nocheck + +/** + * @author: @NeoYaBoi + * @version: 1.0.0 + * @description: This plugin checks if the channel is nsfw and responds to user with a specified response if not nsfw + * @license: Null + * @example: + * ```ts + * import { nsfwOnly } from "../plugins/nsfwOnly"; //(change if need be) + * import { sernModule, CommandType } from "@sern/handler"; + * export default commandModule({ + * plugins: [ nsfwOnly('response', true/false) ], + * execute: (ctx) => { + * //your code here + * } + * }) + * ``` + */ +import { ChannelType } from "discord.js"; +import { PluginType } from "@sern/handler"; + +function isGuildText(channel) { + return ( + channel?.type == ChannelType.GuildPublicThread || + channel?.type == ChannelType.GuildPrivateThread + ); +} + +export function nsfwOnly(onFail, ephemeral) { + return { + type: PluginType.Event, + description: "Checks if the channel is nsfw or not.", + + async execute(event, controller) { + const [ctx] = event; //checking if command was executed in dms + + if (ctx.guild === null) { + await ctx.reply({ + content: onFail, + ephemeral, + }); + return controller.stop(); + } //channel is thread (not supported by nsfw) + + if (isGuildText(ctx.channel) == true) { + await ctx.reply({ + content: onFail, + ephemeral, + }); + return controller.stop(); + } + + if (!ctx.channel.nsfw) { + //channel is not nsfw + await ctx.reply({ + content: onFail, + ephemeral, + }); + return controller.stop(); + } //continues to command if nsfw + + return controller.next(); + }, + }; +}