-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/new db format #80
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
base: version/6.0.0
Are you sure you want to change the base?
Changes from all commits
f12cae4
fc2541e
62387c8
069e142
4d226b7
a733222
d4924fa
037b033
1c2eb11
42574e8
3b00422
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| version=6.0.18-SNAPSHOT | ||
| version=6.0.20-SNAPSHOT |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package dev.slne.surf.discord.command.console.impl | ||
|
|
||
| import dev.slne.surf.discord.command.console.ConsoleCommand | ||
| import dev.slne.surf.discord.ticket.database.whitelist.SocialsMigration | ||
| import kotlinx.coroutines.CoroutineScope | ||
| import kotlinx.coroutines.launch | ||
| import org.springframework.stereotype.Component | ||
|
|
||
| @Component | ||
| class SocialsMigrationCommand( | ||
| private val discordScope: CoroutineScope | ||
| ) : ConsoleCommand { | ||
| override val name = "migrate-socials" | ||
|
|
||
| override fun execute(args: List<String>) { | ||
| discordScope.launch { | ||
| println("Starting social whitelist migration...") | ||
| SocialsMigration.migrateLegacy() | ||
|
|
||
| println("\nMigration finished.") | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package dev.slne.surf.discord.ticket.command.whitelist | ||
|
|
||
| import dev.minn.jda.ktx.coroutines.await | ||
| import dev.slne.surf.discord.command.CommandOption | ||
| import dev.slne.surf.discord.command.CommandOptionType | ||
| import dev.slne.surf.discord.command.DiscordCommand | ||
| import dev.slne.surf.discord.command.SlashCommand | ||
| import dev.slne.surf.discord.config.botConfig | ||
| import dev.slne.surf.discord.jda | ||
| import dev.slne.surf.discord.messages.translatable | ||
| import dev.slne.surf.discord.permission.DiscordPermission | ||
| import dev.slne.surf.discord.permission.hasPermission | ||
| import dev.slne.surf.discord.ticket.database.whitelist.SocialService | ||
| import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent | ||
| import org.springframework.stereotype.Component | ||
|
|
||
| @DiscordCommand( | ||
| name = "wl-create", | ||
| description = "Whitelist Eintrag erstellen", | ||
| options = [CommandOption( | ||
| name = "discord-user", | ||
| description = "Der Discord Nutzer, der gewhitelisted werden soll", | ||
| type = CommandOptionType.USER, | ||
| required = true | ||
| ), | ||
| CommandOption( | ||
| name = "minecraft-name", | ||
| description = "Der Minecraft Name, der gewhitelisted werden soll.", | ||
| type = CommandOptionType.STRING, | ||
| required = true | ||
| )] | ||
| ) | ||
| @Component | ||
| class CreateWhitelistCommand( | ||
| private val socialService: SocialService | ||
| ) : SlashCommand { | ||
| override suspend fun execute(event: SlashCommandInteractionEvent) { | ||
| if (!event.member.hasPermission(DiscordPermission.WHITELIST_CREATE)) { | ||
| event.reply(translatable("no-permission")).setEphemeral(true).queue() | ||
| return | ||
| } | ||
|
|
||
| val userId = event.getOption("discord-user")?.asUser?.idLong ?: return | ||
| val minecraftName = event.getOption("minecraft-name")?.asString ?: return | ||
|
|
||
| if (socialService.getWhitelist(userId) != null) { | ||
| event.reply(translatable("whitelist.command.already-whitelisted.discord")) | ||
| .setEphemeral(true) | ||
| .queue() | ||
| return | ||
| } | ||
|
|
||
| if (socialService.getWhitelist(minecraftName) != null) { | ||
| event.reply(translatable("whitelist.command.already-whitelisted.minecraft")) | ||
| .setEphemeral(true) | ||
| .queue() | ||
| return | ||
| } | ||
|
|
||
| val whitelist = socialService.whitelist(userId, minecraftName) | ||
|
|
||
| val discordUser = event.jda.retrieveUserById(userId).await() | ||
|
|
||
| jda.guilds.forEach { | ||
| val role = it.getRoleById(botConfig.whitelistedRoleId) ?: return@forEach | ||
| it.addRoleToMember(discordUser, role).queue() | ||
| } | ||
|
|
||
| event.reply( | ||
| translatable( | ||
| "whitelist.command.create.success", | ||
| "<@${whitelist?.discordId}>", | ||
| whitelist?.getMinecraftName() ?: whitelist?.minecraftUuid.toString() | ||
| ) | ||
| ) | ||
|
Comment on lines
+60
to
+75
|
||
| .setEphemeral(true) | ||
| .queue() | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package dev.slne.surf.discord.ticket.database.util | ||
|
|
||
| import dev.slne.surf.discord.ticket.database.column.offsetDateTime | ||
| import org.jetbrains.exposed.v1.core.dao.id.LongIdTable | ||
|
|
||
| open class AuditableLongIdTable(name: String) : LongIdTable(name) { | ||
| val createdAt = offsetDateTime("created_at") | ||
| val updatedAt = offsetDateTime("updated_at") | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old-discord-idis used as the record selector for updates, but it's a normal editable text input. Despite the label warning, users can accidentally change it and end up editing a different whitelist entry than intended. Consider not taking this value from user input (e.g., keep the original ID in server-side state / modal custom-id payload), or at least validating it against the originally opened entry before applying changes.