-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Note: heavily refactors the database schema and bot commands
- Loading branch information
Showing
54 changed files
with
1,945 additions
and
1,006 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/main/kotlin/de/darkatra/vrising/discord/commands/ConfigurePlayerActivityFeedCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package de.darkatra.vrising.discord.commands | ||
|
||
import de.darkatra.vrising.discord.commands.parameters.ChannelIdParameter | ||
import de.darkatra.vrising.discord.commands.parameters.addChannelIdParameter | ||
import de.darkatra.vrising.discord.commands.parameters.addServerIdParameter | ||
import de.darkatra.vrising.discord.commands.parameters.addStatusParameter | ||
import de.darkatra.vrising.discord.commands.parameters.getChannelIdParameter | ||
import de.darkatra.vrising.discord.commands.parameters.getServerIdParameter | ||
import de.darkatra.vrising.discord.commands.parameters.getStatusParameter | ||
import de.darkatra.vrising.discord.persistence.ServerRepository | ||
import de.darkatra.vrising.discord.persistence.model.PlayerActivityFeed | ||
import de.darkatra.vrising.discord.persistence.model.Status | ||
import dev.kord.core.Kord | ||
import dev.kord.core.behavior.interaction.response.respond | ||
import dev.kord.core.entity.interaction.ChatInputCommandInteraction | ||
import dev.kord.core.entity.interaction.GlobalChatInputCommandInteraction | ||
import dev.kord.core.entity.interaction.GuildChatInputCommandInteraction | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class ConfigurePlayerActivityFeedCommand( | ||
private val serverRepository: ServerRepository | ||
) : Command { | ||
|
||
private val logger = LoggerFactory.getLogger(javaClass) | ||
|
||
private val name: String = "configure-player-activity-feed" | ||
private val description: String = "Configures the player activity feed for a given server." | ||
|
||
override fun getCommandName(): String = name | ||
|
||
override suspend fun register(kord: Kord) { | ||
|
||
kord.createGlobalChatInputCommand( | ||
name = name, | ||
description = description | ||
) { | ||
|
||
dmPermission = false | ||
disableCommandInGuilds() | ||
|
||
addServerIdParameter() | ||
|
||
addChannelIdParameter(required = false) | ||
addStatusParameter(required = false) | ||
} | ||
} | ||
|
||
override fun isSupported(interaction: ChatInputCommandInteraction, adminUserIds: Set<String>): Boolean { | ||
if (interaction is GlobalChatInputCommandInteraction) { | ||
return false | ||
} | ||
return super.isSupported(interaction, adminUserIds) | ||
} | ||
|
||
override suspend fun handle(interaction: ChatInputCommandInteraction) { | ||
|
||
val serverId = interaction.getServerIdParameter() | ||
|
||
val channelId = interaction.getChannelIdParameter() | ||
val status = interaction.getStatusParameter() | ||
|
||
val server = when (interaction) { | ||
is GuildChatInputCommandInteraction -> serverRepository.getServer(serverId, interaction.guildId.toString()) | ||
is GlobalChatInputCommandInteraction -> serverRepository.getServer(serverId) | ||
} | ||
|
||
if (server == null) { | ||
interaction.deferEphemeralResponse().respond { | ||
content = "No server with id '$serverId' was found." | ||
} | ||
return | ||
} | ||
|
||
val playerActivityFeed = server.playerActivityFeed | ||
if (playerActivityFeed == null) { | ||
|
||
if (channelId == null) { | ||
interaction.deferEphemeralResponse().respond { | ||
content = "'${ChannelIdParameter.NAME}' is required when using this command for the first time." | ||
} | ||
return | ||
} | ||
|
||
server.playerActivityFeed = PlayerActivityFeed( | ||
status = status ?: Status.ACTIVE, | ||
discordChannelId = channelId | ||
) | ||
|
||
logger.info("Successfully configured the player activity feed for server '$serverId'.") | ||
|
||
interaction.deferEphemeralResponse().respond { | ||
content = "Successfully configured the player activity feed for server with id '$serverId'." | ||
} | ||
return | ||
} | ||
|
||
if (channelId != null) { | ||
playerActivityFeed.discordChannelId = channelId | ||
} | ||
if (status != null) { | ||
playerActivityFeed.status = status | ||
} | ||
|
||
serverRepository.updateServer(server) | ||
|
||
logger.info("Successfully updated the player activity feed for server '$serverId'.") | ||
|
||
interaction.deferEphemeralResponse().respond { | ||
content = "Successfully updated the player activity feed for server with id '$serverId'." | ||
} | ||
} | ||
} |
Oops, something went wrong.