Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invite link generation #29

Merged
merged 1 commit into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/action/buildCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ export default [
.setDescription('Die ID der Nachricht vom Bot in dem der Giveaway verkündet wurde')
.setRequired(true)
),
new SlashCommandBuilder().setName("invite")
.setDefaultMemberPermissions(PermissionFlagsBits.SendMessages)
.setDescription("Erstellt einen einmaligen Invite-Link für den Server"),
/*
Blackjack
*/
Expand Down
44 changes: 43 additions & 1 deletion src/action/infoMessages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Client, CommandInteraction, EmbedBuilder } from 'discord.js'
import { ChannelType, Client, Colors, CommandInteraction, EmbedBuilder } from 'discord.js'
import { ILogger } from 'src/logger/logger'
import fs from 'fs'

Expand Down Expand Up @@ -110,3 +110,45 @@ export async function ping (client: Client, interaction: CommandInteraction, log
logger.logSync('ERROR', `Ping konnte nicht gesendet werden. Error ${JSON.stringify(err)}`)
}
}

/**
* Create an one use invite link for the server and send it to the user
* @param interaction
*/
export async function invite (interaction: CommandInteraction, logger: ILogger): Promise<void> {
try {
const guild = interaction.guild
if (!guild) {
await interaction.reply({ content: 'Dieser Befehl kann nur auf einem Server ausgeführt werden.', ephemeral: true })
return
}

if (interaction.channel?.type !== ChannelType.GuildText) {
await interaction.reply({ content: 'Dieser Befehl kann nur in einem Textkanal ausgeführt werden.', ephemeral: true })
return
}

const inviteLink = await guild.invites.create(interaction.channel, {
maxAge: 24 * 60 * 60, // 24 hours
maxUses: 1
})

await interaction.reply({
embeds: [
new EmbedBuilder()
.setAuthor({ name: 'FloBot' })
.setTitle("Einladungslink")
.setDescription(`Hier ein Einladungslink für diesen Server: ${inviteLink.url}\nDer Einladungslink ist für 24h und maximal eine Verwendung gültig. Für permanente Links, nutze einen von <@${guild.ownerId}> bereitgestellten Link (z.B. YouTube Videos).`)
.setColor(Colors.Navy)
],
ephemeral: true
})
} catch {
try {
await interaction.reply({ content: 'Ein Fehler ist aufgetreten. Bitte versuche es später erneut.', ephemeral: true })
} catch {
// ignore and log
logger.logSync("ERROR", "Invite Link konnte nicht gesendet werden")
}
}
}
6 changes: 5 additions & 1 deletion src/listeners/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AutocompleteInteraction
} from 'discord.js'
import { LogManager } from '../logger/logger'
import { codeblocks, metafrage, about, ping } from '../action/infoMessages'
import { codeblocks, metafrage, about, ping, invite } from '../action/infoMessages'
import { createRoleInterface } from '../action/roles_buttons_create'
import { toggleRoles } from '../action/toggleRole'
import startUserReport from '../action/userReport'
Expand Down Expand Up @@ -188,6 +188,10 @@ const handleSlashCommand = async (client: Client, interaction: CommandInteractio
break
case 'bj':
await handleBlackJackCommands(interaction, logger)
break
case 'invite':
await invite(interaction, logger.logger("INVITE"))
break
}
}

Expand Down