mirror of
https://github.com/SrIzan10/awesome-plugins.git
synced 2026-05-01 10:35:27 +00:00
fix: multiple issues with publish plugin (#32)
This commit is contained in:
@@ -3,20 +3,21 @@
|
||||
* This is publish plugin, it allows you to publish your slash commands with ease.
|
||||
*
|
||||
* @author @EvolutionX-10 [<@697795666373640213>]
|
||||
* @version 1.2.0
|
||||
* @version 1.2.1
|
||||
* @example
|
||||
* ```ts
|
||||
* import { publish } from "../plugins/publish";
|
||||
* import { commandModule } from "@sern/handler";
|
||||
* export default commandModule({
|
||||
* plugins: [ publish() ], // put an object containing permissions, ids for guild commands, boolean for dmPermission
|
||||
* // plugins: [ publish({ guildIds: [], dmPermission: true})]
|
||||
* execute: (ctx) => {
|
||||
* //your code here
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
import {
|
||||
import {
|
||||
CommandPlugin,
|
||||
CommandType,
|
||||
PluginType,
|
||||
@@ -29,17 +30,18 @@ import {
|
||||
} from "discord.js";
|
||||
|
||||
export function publish(
|
||||
options: PublishOptions = {
|
||||
guildIds: [],
|
||||
dmPermission: true,
|
||||
defaultMemberPermissions: null,
|
||||
}
|
||||
options?: PublishOptions
|
||||
): CommandPlugin<CommandType.Slash | CommandType.Both> {
|
||||
return {
|
||||
type: PluginType.Command,
|
||||
description: "Manage Slash Commands",
|
||||
name: "slash-auto-publish",
|
||||
async execute({ client }, { mod: module }, controller) {
|
||||
const defaultOptions = {
|
||||
guildIds: [],
|
||||
dmPermission: true,
|
||||
};
|
||||
options = { ...defaultOptions, ...options };
|
||||
let { defaultMemberPermissions, dmPermission, guildIds } = options;
|
||||
function c(e: unknown) {
|
||||
console.error("publish command didnt work for", module.name!);
|
||||
@@ -54,17 +56,16 @@ export function publish(
|
||||
defaultMemberPermissions,
|
||||
dmPermission,
|
||||
};
|
||||
if (!Array.isArray(guildIds)) guildIds = [guildIds];
|
||||
|
||||
if (!Array.isArray(guildIds)) guildIds = [guildIds!];
|
||||
|
||||
if (!guildIds.length) {
|
||||
const cmd = (
|
||||
await client.application!.commands.fetch()
|
||||
).find((c) => c.name === module.name);
|
||||
const cmd = (await client.application!.commands.fetch()).find(
|
||||
(c) => c.name === module.name
|
||||
);
|
||||
if (cmd) {
|
||||
if (!cmd.equals(commandData, true)) {
|
||||
console.log(
|
||||
`Found differences in global command ${module.name}`
|
||||
);
|
||||
console.log(`Found differences in global command ${module.name}`);
|
||||
cmd.edit(commandData).then(() => {
|
||||
console.log(
|
||||
`${module.name} updated with new data successfully!`
|
||||
@@ -73,14 +74,12 @@ export function publish(
|
||||
}
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
client
|
||||
.application!.commands.create(commandData)
|
||||
.then(() => {
|
||||
console.log("Command created", module.name!);
|
||||
})
|
||||
.catch(c);
|
||||
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
@@ -92,9 +91,7 @@ export function publish(
|
||||
);
|
||||
if (guildcmd) {
|
||||
if (!guildcmd.equals(commandData, true)) {
|
||||
console.log(
|
||||
`Found differences in command ${module.name}`
|
||||
);
|
||||
console.log(`Found differences in command ${module.name}`);
|
||||
guildcmd
|
||||
.edit(commandData)
|
||||
.then(() =>
|
||||
@@ -110,11 +107,7 @@ export function publish(
|
||||
guild.commands
|
||||
.create(commandData)
|
||||
.then(() =>
|
||||
console.log(
|
||||
"Guild Command created",
|
||||
module.name!,
|
||||
guild.name
|
||||
)
|
||||
console.log("Guild Command created", module.name!, guild.name)
|
||||
)
|
||||
.catch(c);
|
||||
}
|
||||
@@ -141,8 +134,15 @@ export const CommandTypeRaw = {
|
||||
[CommandType.Slash]: ApplicationCommandType.ChatInput,
|
||||
} as const;
|
||||
|
||||
interface PublishOptions {
|
||||
guildIds: string[];
|
||||
defaultMemberPermissions: PermissionResolvable | null;
|
||||
dmPermission: boolean;
|
||||
interface DefaultPublishOptions {
|
||||
guildIds?: string | string[];
|
||||
defaultMemberPermissions?: PermissionResolvable;
|
||||
dmPermission?: boolean;
|
||||
}
|
||||
|
||||
type PublishOptions = DefaultPublishOptions &
|
||||
(
|
||||
| Required<Pick<DefaultPublishOptions, "defaultMemberPermissions">>
|
||||
| Required<Pick<DefaultPublishOptions, "dmPermission">>
|
||||
| Required<Pick<DefaultPublishOptions, "guildIds">>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user