mirror of
https://github.com/SrIzan10/awesome-plugins.git
synced 2026-05-01 10:35:27 +00:00
chore: Update JavaScript plugins (#31)
chore: update JavaScript plugins Co-authored-by: EvolutionX-10 <EvolutionX-10@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
18d658922a
commit
cf62cf7575
47
JavaScript/channelType.js
Normal file
47
JavaScript/channelType.js
Normal file
@@ -0,0 +1,47 @@
|
||||
// @ts-nocheck
|
||||
|
||||
/**
|
||||
* This plugin checks if a channel is the specified type
|
||||
*
|
||||
* @author @NeoYaBoi [<@762918086349029386>]
|
||||
* @version 1.0.0
|
||||
* @example
|
||||
* ```ts
|
||||
* import { channelType } from "../plugins/channelType";
|
||||
* import { ChannelType } from "discord.js"
|
||||
* import { commandModule } from "@sern/handler";
|
||||
* export default commandModule({
|
||||
* plugins: [ channelType([ChannelType.GuildText], 'This cannot be used here') ],
|
||||
* execute: (ctx) => {
|
||||
* //your code here
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
import { ChannelType } from "discord.js";
|
||||
import { PluginType } from "@sern/handler";
|
||||
export function channelType(channelType, onFail) {
|
||||
return {
|
||||
type: PluginType.Event,
|
||||
description: "Checks the channel type.",
|
||||
|
||||
async execute(event, controller) {
|
||||
const [ctx] = event;
|
||||
let channel = ctx.channel?.type; //for some reason the dm channel type was returning undefined at some points
|
||||
|
||||
if (channel === undefined) {
|
||||
channel = ChannelType.DM;
|
||||
}
|
||||
|
||||
if (channelType.includes(channel)) {
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
if (onFail) {
|
||||
await ctx.reply(onFail);
|
||||
}
|
||||
|
||||
return controller.stop();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -4,13 +4,13 @@
|
||||
* This is publish plugin, it allows you to publish your slash commands with ease.
|
||||
*
|
||||
* @author @EvolutionX-10 [<@697795666373640213>]
|
||||
* @version 1.1.0
|
||||
* @version 1.2.0
|
||||
* @example
|
||||
* ```ts
|
||||
* import { publish } from "../plugins/publish";
|
||||
* import { commandModule } from "@sern/handler";
|
||||
* export default commandModule({
|
||||
* plugins: [ publish() ], // put an array of guild ids for guild commands
|
||||
* plugins: [ publish() ], // put an object containing permissions, ids for guild commands, boolean for dmPermission
|
||||
* execute: (ctx) => {
|
||||
* //your code here
|
||||
* }
|
||||
@@ -19,13 +19,21 @@
|
||||
*/
|
||||
import { CommandType, PluginType } from "@sern/handler";
|
||||
import { ApplicationCommandType } from "discord.js";
|
||||
export function publish(guildIds = []) {
|
||||
export function publish(
|
||||
options = {
|
||||
guildIds: [],
|
||||
dmPermission: true,
|
||||
defaultMemberPermissions: null,
|
||||
}
|
||||
) {
|
||||
return {
|
||||
type: PluginType.Command,
|
||||
description: "Manage Slash Commands",
|
||||
name: "slash-auto-publish",
|
||||
|
||||
async execute({ client }, { absPath, mod: module }, controller) {
|
||||
async execute({ client }, { mod: module }, controller) {
|
||||
let { defaultMemberPermissions, dmPermission, guildIds } = options;
|
||||
|
||||
function c(e) {
|
||||
console.error("publish command didnt work for", module.name);
|
||||
console.error(e);
|
||||
@@ -37,6 +45,8 @@ export function publish(guildIds = []) {
|
||||
name: module.name,
|
||||
description: module.description,
|
||||
options: optionsTransformer(module.options ?? []),
|
||||
defaultMemberPermissions,
|
||||
dmPermission,
|
||||
};
|
||||
if (!Array.isArray(guildIds)) guildIds = [guildIds];
|
||||
|
||||
@@ -50,7 +60,7 @@ export function publish(guildIds = []) {
|
||||
console.log(
|
||||
`Found differences in global command ${module.name}`
|
||||
);
|
||||
await cmd.edit(commandData).then((c) => {
|
||||
cmd.edit(commandData).then(() => {
|
||||
console.log(
|
||||
`${module.name} updated with new data successfully!`
|
||||
);
|
||||
@@ -60,10 +70,12 @@ export function publish(guildIds = []) {
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
await client.application.commands
|
||||
client.application.commands
|
||||
.create(commandData)
|
||||
.then(() => {
|
||||
console.log("Command created", module.name);
|
||||
})
|
||||
.catch(c);
|
||||
console.log("Command created", module.name);
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
@@ -79,22 +91,30 @@ export function publish(guildIds = []) {
|
||||
console.log(
|
||||
`Found differences in command ${module.name}`
|
||||
);
|
||||
await guildcmd.edit(commandData).catch(c);
|
||||
console.log(
|
||||
`${module.name} updated with new data successfully!`
|
||||
);
|
||||
guildcmd
|
||||
.edit(commandData)
|
||||
.then(() =>
|
||||
console.log(
|
||||
`${module.name} updated with new data successfully!`
|
||||
)
|
||||
)
|
||||
.catch(c);
|
||||
continue;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
await guild.commands.create(commandData).catch(c);
|
||||
console.log(
|
||||
"Guild Command created",
|
||||
module.name,
|
||||
guild.name
|
||||
);
|
||||
guild.commands
|
||||
.create(commandData)
|
||||
.then(() =>
|
||||
console.log(
|
||||
"Guild Command created",
|
||||
module.name,
|
||||
guild.name
|
||||
)
|
||||
)
|
||||
.catch(c);
|
||||
}
|
||||
|
||||
return controller.next();
|
||||
|
||||
Reference in New Issue
Block a user