mirror of
https://github.com/SrIzan10/awesome-plugins.git
synced 2026-05-01 10:35:27 +00:00
chore: Update JavaScript plugins (#17)
chore: update JavaScript plugins Co-authored-by: EvolutionX-10 <EvolutionX-10@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
96204b34ee
commit
01508914f7
37
JavaScript/dmOnly.js
Normal file
37
JavaScript/dmOnly.js
Normal file
@@ -0,0 +1,37 @@
|
||||
// @ts-nocheck
|
||||
|
||||
/**
|
||||
* @author: @EvolutionX-10
|
||||
* @version: 1.1.0-beta
|
||||
* @description: This is dmOnly plugin, it allows commands to be run only in DMs.
|
||||
* @requires `partials: [Partials.Channel], intents: [GatewayIntentBits.DirectMessages, GatewayIntentBits.MessageContent]
|
||||
* @license: MIT
|
||||
* @example:
|
||||
* ```ts
|
||||
* import { dmOnly } from "../path/to/your/plugin/folder";
|
||||
* import { commandModule } from "@sern/handler";
|
||||
* export default commandModule({
|
||||
* plugins: [dmOnly()],
|
||||
* execute: // your code
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
import { PluginType } from "@sern/handler";
|
||||
export function dmOnly(content, ephemeral) {
|
||||
return {
|
||||
type: PluginType.Event,
|
||||
description: "Allows commands to be run in DM only",
|
||||
|
||||
async execute(event, controller) {
|
||||
const [ctx] = event;
|
||||
if (ctx.channel?.isDMBased()) return controller.next();
|
||||
if (content)
|
||||
await ctx.reply({
|
||||
content,
|
||||
ephemeral,
|
||||
}); // Change this if you want or remove it for silent deny
|
||||
|
||||
return controller.stop();
|
||||
},
|
||||
};
|
||||
}
|
||||
33
JavaScript/ownerOnly.js
Normal file
33
JavaScript/ownerOnly.js
Normal file
@@ -0,0 +1,33 @@
|
||||
// @ts-nocheck
|
||||
|
||||
/**
|
||||
* @author: @EvolutionX-10
|
||||
* @version: 1.0.0
|
||||
* @description: This is OwnerOnly plugin, it allows only bot owners to run the command, like eval.
|
||||
* @license: MIT
|
||||
* @example:
|
||||
* ```ts
|
||||
* import { ownerOnly } from "../path/to/your/plugin/folder";
|
||||
* import { sernModule, CommandType } from "@sern/handler";
|
||||
* export default sernModule<CommandType.Slash>([OwnerOnly()], {
|
||||
* // your code
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
import { PluginType } from "@sern/handler";
|
||||
const ownerIDs = ["697795666373640213"]; //! Fill your ID
|
||||
|
||||
export function ownerOnly() {
|
||||
return {
|
||||
type: PluginType.Event,
|
||||
description: "Allows only bot owner to run command",
|
||||
|
||||
async execute(event, controller) {
|
||||
const [ctx] = event;
|
||||
if (ownerIDs.includes(ctx.user.id)) return controller.next(); //* If you want to reply when the command fails due to user not being owner, you can use following
|
||||
// await ctx.reply("Only owner can run it!!!");
|
||||
|
||||
return controller.stop(); //! Important: It stops the execution of command!
|
||||
},
|
||||
};
|
||||
}
|
||||
46
JavaScript/permCheck.js
Normal file
46
JavaScript/permCheck.js
Normal file
@@ -0,0 +1,46 @@
|
||||
// @ts-nocheck
|
||||
|
||||
/**
|
||||
* @author: @NeoYaBoi
|
||||
* @version: 1.0.1
|
||||
* @description: This is perm check, it allows users to parse the permission you want and let the plugin do the rest. (check user for that perm).
|
||||
* @license: Null
|
||||
* @example:
|
||||
* ```ts
|
||||
* import { permCheck } from "../plugins/permCheck"; //(change if need be)
|
||||
* import { sernModule, CommandType } from "@sern/handler";
|
||||
* export default commandModule({
|
||||
* plugins: [ permCheck('permission', 'No permission response') ],
|
||||
* execute: (ctx) => {
|
||||
* //your code here
|
||||
* }
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
import { PluginType } from "@sern/handler";
|
||||
export function permCheck(perm, response) {
|
||||
return {
|
||||
type: PluginType.Event,
|
||||
description: "Checks for specified perm",
|
||||
|
||||
async execute(event, controller) {
|
||||
const [ctx] = event;
|
||||
|
||||
if (ctx.guild === null) {
|
||||
ctx.reply("This command cannot be used here");
|
||||
console.warn(
|
||||
"PermCheck > A command stopped because we couldn't check a users permissions (was used in dms)"
|
||||
); //delete this line if you dont want to be notified when a command is used outside of a guild/server
|
||||
|
||||
return controller.stop();
|
||||
}
|
||||
|
||||
if (!ctx.member.permissions.has(perm)) {
|
||||
await ctx.reply(response);
|
||||
return controller.stop();
|
||||
}
|
||||
|
||||
return controller.next();
|
||||
},
|
||||
};
|
||||
}
|
||||
116
JavaScript/publish.js
Normal file
116
JavaScript/publish.js
Normal file
@@ -0,0 +1,116 @@
|
||||
// @ts-nocheck
|
||||
|
||||
/**
|
||||
* @author: @EvolutionX-10
|
||||
* @version: 1.1.0-beta
|
||||
* @description: This is publish plugin, it allows you to publish your slash commands with ease.
|
||||
* @license: MIT
|
||||
* @example:
|
||||
* ```ts
|
||||
* import { publish } from "../path/to/your/plugin/folder";
|
||||
* import { sernModule, CommandType } from "@sern/handler";
|
||||
* export default sernModule<CommandType.Slash>([publish()], { // put guild id in array for guild commands
|
||||
* // your code
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
import { CommandType, PluginType } from "@sern/handler";
|
||||
import { ApplicationCommandType } from "discord.js";
|
||||
export function publish(guildIds = []) {
|
||||
return {
|
||||
type: PluginType.Command,
|
||||
description: "Manage Slash Commands",
|
||||
name: "slash-auto-publish",
|
||||
|
||||
async execute({ client }, { absPath, mod: module }, controller) {
|
||||
function c(e) {
|
||||
console.error("publish command didnt work for", module.name);
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
try {
|
||||
const commandData = {
|
||||
type: CommandTypeRaw[module.type],
|
||||
name: module.name,
|
||||
description: module.description,
|
||||
options: optionsTransformer(module.options ?? []),
|
||||
};
|
||||
if (!Array.isArray(guildIds)) guildIds = [guildIds];
|
||||
|
||||
if (!guildIds.length) {
|
||||
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}`
|
||||
);
|
||||
await cmd.edit(commandData).then((c) => {
|
||||
console.log(
|
||||
`${module.name} updated with new data successfully!`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
await client.application.commands
|
||||
.create(commandData)
|
||||
.catch(c);
|
||||
console.log("Command created", module.name);
|
||||
return controller.next();
|
||||
}
|
||||
|
||||
for (const id of guildIds) {
|
||||
const guild = await client.guilds.fetch(id).catch(c);
|
||||
if (!guild) continue;
|
||||
const guildcmd = (await guild.commands.fetch()).find(
|
||||
(c) => c.name === module.name
|
||||
);
|
||||
|
||||
if (guildcmd) {
|
||||
if (!guildcmd.equals(commandData, true)) {
|
||||
console.log(
|
||||
`Found differences in command ${module.name}`
|
||||
);
|
||||
await guildcmd.edit(commandData).catch(c);
|
||||
console.log(
|
||||
`${module.name} updated with new data successfully!`
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
await guild.commands.create(commandData).catch(c);
|
||||
console.log(
|
||||
"Guild Command created",
|
||||
module.name,
|
||||
guild.name
|
||||
);
|
||||
}
|
||||
|
||||
return controller.next();
|
||||
} catch (e) {
|
||||
console.log("Command did not register" + module.name);
|
||||
console.log(e);
|
||||
return controller.stop();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
export function optionsTransformer(ops) {
|
||||
return ops.map((el) =>
|
||||
el.autocomplete ? (({ command, ...el }) => el)(el) : el
|
||||
);
|
||||
}
|
||||
export const CommandTypeRaw = {
|
||||
[CommandType.Both]: ApplicationCommandType.ChatInput,
|
||||
[CommandType.MenuMsg]: ApplicationCommandType.Message,
|
||||
[CommandType.MenuUser]: ApplicationCommandType.User,
|
||||
[CommandType.Slash]: ApplicationCommandType.ChatInput,
|
||||
};
|
||||
Reference in New Issue
Block a user