Skip to content

Commit

Permalink
Merge pull request #29 from Mickhat/invite-urls
Browse files Browse the repository at this point in the history
invite link generation
  • Loading branch information
Mickhat committed Jul 1, 2023
2 parents 014b69d + 19034ec commit fa91ada
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
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

0 comments on commit fa91ada

Please sign in to comment.