mirror of
https://github.com/sern-handler/awesome-plugins
synced 2026-06-06 01:16:51 +00:00
feat: improve publish (#30)
* feat: improve publish * chore: address requested changes * chore: req changes
This commit is contained in:
@@ -3,13 +3,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
|
||||
* }
|
||||
@@ -22,16 +22,25 @@ import {
|
||||
PluginType,
|
||||
SernOptionsData,
|
||||
} from "@sern/handler";
|
||||
import { ApplicationCommandData, ApplicationCommandType } from "discord.js";
|
||||
import {
|
||||
ApplicationCommandData,
|
||||
ApplicationCommandType,
|
||||
PermissionResolvable,
|
||||
} from "discord.js";
|
||||
|
||||
export function publish(
|
||||
guildIds: string | Array<string> = []
|
||||
options: PublishOptions = {
|
||||
guildIds: [],
|
||||
dmPermission: true,
|
||||
defaultMemberPermissions: null,
|
||||
}
|
||||
): CommandPlugin<CommandType.Slash | CommandType.Both> {
|
||||
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: unknown) {
|
||||
console.error("publish command didnt work for", module.name!);
|
||||
console.error(e);
|
||||
@@ -42,6 +51,8 @@ export function publish(
|
||||
name: module.name!,
|
||||
description: module.description,
|
||||
options: optionsTransformer(module.options ?? []),
|
||||
defaultMemberPermissions,
|
||||
dmPermission,
|
||||
};
|
||||
if (!Array.isArray(guildIds)) guildIds = [guildIds];
|
||||
|
||||
@@ -54,7 +65,7 @@ export function publish(
|
||||
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!`
|
||||
);
|
||||
@@ -63,10 +74,13 @@ export function publish(
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
await client
|
||||
client
|
||||
.application!.commands.create(commandData)
|
||||
.then(() => {
|
||||
console.log("Command created", module.name!);
|
||||
})
|
||||
.catch(c);
|
||||
console.log("Command created", module.name!);
|
||||
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
@@ -81,20 +95,28 @@ export function publish(
|
||||
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();
|
||||
} catch (e) {
|
||||
@@ -118,3 +140,9 @@ export const CommandTypeRaw = {
|
||||
[CommandType.MenuUser]: ApplicationCommandType.User,
|
||||
[CommandType.Slash]: ApplicationCommandType.ChatInput,
|
||||
} as const;
|
||||
|
||||
interface PublishOptions {
|
||||
guildIds: string[];
|
||||
defaultMemberPermissions: PermissionResolvable | null;
|
||||
dmPermission: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user