From 18e48024dce98c4725a8403059e15f185c83225b Mon Sep 17 00:00:00 2001 From: Aiko <159515125+AikooNee@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:51:23 +0530 Subject: [PATCH 1/4] Checking permission before creating invite link Signed-off-by: Aiko <159515125+AikooNee@users.noreply.github.com> --- src/commands/dev/CreateInvite.ts | 65 +++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/src/commands/dev/CreateInvite.ts b/src/commands/dev/CreateInvite.ts index f40ceba26..e288fde9a 100644 --- a/src/commands/dev/CreateInvite.ts +++ b/src/commands/dev/CreateInvite.ts @@ -1,17 +1,17 @@ -import { ChannelType } from "discord.js"; import { Command, type Context, type Lavamusic } from "../../structures/index.js"; +import { ChannelType, PermissionFlagsBits } from "discord.js"; export default class CreateInvite extends Command { constructor(client: Lavamusic) { super(client, { name: "createinvite", description: { - content: "Create a invite link for a guild", - examples: ["createinvite 0000000000000000000"], + content: "Create an invite link for a guild", + examples: ["createinvite 0123456789"], usage: "createinvite ", }, category: "dev", - aliases: ["ci"], + aliases: ["ci", "gi", "ginvite", "guildinvite"], cooldown: 3, args: true, player: { @@ -22,7 +22,7 @@ export default class CreateInvite extends Command { }, permissions: { dev: true, - client: ["SendMessages", "CreateInstantInvite", "ReadMessageHistory", "ViewChannel"], + client: ["SendMessages", "CreateInstantInvite", "ReadMessageHistory", "EmbedLinks", "ViewChannel"], user: [], }, slashCommand: false, @@ -30,32 +30,53 @@ export default class CreateInvite extends Command { }); } - public async run(client: Lavamusic, ctx: Context, args: string[]): Promise { + async run(client: Lavamusic, ctx: Context, args: string[]): Promise { const guildId = args[0]; - const guild = client.guilds.cache.get(guildId); if (!guild) { - return await ctx.sendMessage("Guild not found."); + return await ctx.sendMessage({ + embeds: [ + this.client.embed() + .setColor(client.color.red) + .setDescription("Guild not found"), + ], + }); } - try { - const textChannel = guild.channels.cache.find((channel) => channel.type === ChannelType.GuildText); + const textChannel = guild.channels.cache.find( + (c) => + c.type === ChannelType.GuildText && + c.permissionsFor(guild.members.me!)?.has([ + PermissionFlagsBits.CreateInstantInvite, + PermissionFlagsBits.SendMessages, + PermissionFlagsBits.ViewChannel, + ]) + ); - if (!textChannel) { - return await ctx.sendMessage("No text channel found in the guild."); - } - - const invite = await textChannel.createInvite({ - maxUses: 0, - maxAge: 0, + if (!textChannel) { + return await ctx.sendMessage({ + embeds: [ + this.client.embed() + .setColor(client.color.red) + .setDescription("No suitable channel found"), + ], }); - - await ctx.author.send(`Guild: ${guild.name}\nInvite Link: ${invite.url}`); - await ctx.sendMessage("Invite link has been sent to your DM."); - } catch (_error) { - await ctx.sendMessage("Failed to create invite link."); } + + const invite = await textChannel.createInvite({ + maxAge: 3600, // 1 hour + maxUses: 1, + reason: `Requested by my admin: ${ctx.author.username}`, + }); + + return await ctx.sendMessage({ + embeds: [ + this.client.embed() + .setColor(client.color.main) + .setDescription(`Invite link for ${guild.name}: [Link](${invite.url})`), + ], + }); } } From 4b1bdca144ff6447f0dfd0937666c2935903a462 Mon Sep 17 00:00:00 2001 From: Aiko <159515125+AikooNee@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:52:31 +0530 Subject: [PATCH 2/4] fix Signed-off-by: Aiko <159515125+AikooNee@users.noreply.github.com> --- src/commands/dev/CreateInvite.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/dev/CreateInvite.ts b/src/commands/dev/CreateInvite.ts index e288fde9a..5baa0a715 100644 --- a/src/commands/dev/CreateInvite.ts +++ b/src/commands/dev/CreateInvite.ts @@ -30,7 +30,7 @@ export default class CreateInvite extends Command { }); } - async run(client: Lavamusic, ctx: Context, args: string[]): Promise { + public async run(client: Lavamusic, ctx: Context, args: string[]): Promise { const guildId = args[0]; const guild = client.guilds.cache.get(guildId); From 205018d897baa08517e0080aa114ec59e87b2966 Mon Sep 17 00:00:00 2001 From: Aiko <159515125+AikooNee@users.noreply.github.com> Date: Tue, 20 Aug 2024 11:03:07 +0530 Subject: [PATCH 3/4] fix Signed-off-by: Aiko <159515125+AikooNee@users.noreply.github.com> --- src/commands/dev/CreateInvite.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/dev/CreateInvite.ts b/src/commands/dev/CreateInvite.ts index 5baa0a715..555ffbee6 100644 --- a/src/commands/dev/CreateInvite.ts +++ b/src/commands/dev/CreateInvite.ts @@ -30,7 +30,7 @@ export default class CreateInvite extends Command { }); } - public async run(client: Lavamusic, ctx: Context, args: string[]): Promise { + public async run(client: Lavamusic, ctx: Context, args: string[]): Promise { const guildId = args[0]; const guild = client.guilds.cache.get(guildId); From a6acfb06963dc00fadd0ae5e867e15ff21004c72 Mon Sep 17 00:00:00 2001 From: LucasB25 <50886682+LucasB25@users.noreply.github.com> Date: Tue, 20 Aug 2024 17:10:32 +0200 Subject: [PATCH 4/4] fix and update --- Lavalink/example.application.yml | 2 +- src/commands/dev/CreateInvite.ts | 30 +++++++++--------------------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Lavalink/example.application.yml b/Lavalink/example.application.yml index 94ced2b2b..a788e2db5 100644 --- a/Lavalink/example.application.yml +++ b/Lavalink/example.application.yml @@ -93,7 +93,7 @@ lavalink: plugins: - dependency: "com.github.appujet:jiosaavn-plugin:0.1.7" repository: "https://jitpack.io" - - dependency: "com.dunctebot:skybot-lavalink-plugin:1.7.0" + - dependency: "com.dunctebot:skybot-lavalink-plugin:1.7.1" snapshot: false # set to true if you want to use snapshot builds. - dependency: "com.github.topi314.lavasearch:lavasearch-plugin:1.0.0" snapshot: false # set to true if you want to use snapshot builds. diff --git a/src/commands/dev/CreateInvite.ts b/src/commands/dev/CreateInvite.ts index 555ffbee6..a1cbf2be2 100644 --- a/src/commands/dev/CreateInvite.ts +++ b/src/commands/dev/CreateInvite.ts @@ -1,5 +1,5 @@ import { Command, type Context, type Lavamusic } from "../../structures/index.js"; -import { ChannelType, PermissionFlagsBits } from "discord.js"; +import { ChannelType, PermissionFlagsBits, type TextChannel } from "discord.js"; export default class CreateInvite extends Command { constructor(client: Lavamusic) { @@ -7,7 +7,7 @@ export default class CreateInvite extends Command { name: "createinvite", description: { content: "Create an invite link for a guild", - examples: ["createinvite 0123456789"], + examples: ["createinvite 0000000000000000000"], usage: "createinvite ", }, category: "dev", @@ -36,31 +36,21 @@ export default class CreateInvite extends Command { if (!guild) { return await ctx.sendMessage({ - embeds: [ - this.client.embed() - .setColor(client.color.red) - .setDescription("Guild not found"), - ], + embeds: [this.client.embed().setColor(this.client.color.red).setDescription("Guild not found")], }); } const textChannel = guild.channels.cache.find( (c) => c.type === ChannelType.GuildText && - c.permissionsFor(guild.members.me!)?.has([ - PermissionFlagsBits.CreateInstantInvite, - PermissionFlagsBits.SendMessages, - PermissionFlagsBits.ViewChannel, - ]) - ); + c + .permissionsFor(guild.members.me!) + ?.has([PermissionFlagsBits.CreateInstantInvite, PermissionFlagsBits.SendMessages, PermissionFlagsBits.ViewChannel]), + ) as TextChannel; if (!textChannel) { return await ctx.sendMessage({ - embeds: [ - this.client.embed() - .setColor(client.color.red) - .setDescription("No suitable channel found"), - ], + embeds: [this.client.embed().setColor(this.client.color.red).setDescription("No suitable channel found")], }); } @@ -72,9 +62,7 @@ export default class CreateInvite extends Command { return await ctx.sendMessage({ embeds: [ - this.client.embed() - .setColor(client.color.main) - .setDescription(`Invite link for ${guild.name}: [Link](${invite.url})`), + this.client.embed().setColor(this.client.color.main).setDescription(`Invite link for ${guild.name}: [Link](${invite.url})`), ], }); }