-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da651a1
commit fae691f
Showing
4 changed files
with
4 additions
and
35 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
18 changes: 0 additions & 18 deletions
18
src/main/kotlin/com/hero/alignlab/client/discord/client/SuspendableDiscordWebhookClient.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 |
---|---|---|
@@ -1,41 +1,23 @@ | ||
package com.hero.alignlab.client.discord.client | ||
|
||
import com.hero.alignlab.client.discord.config.DiscordWebhookClientConfig | ||
import com.hero.alignlab.client.discord.model.request.SendMessageRequest | ||
import com.hero.alignlab.client.discord.model.response.GetWebhookWithTokenResponse | ||
import com.hero.alignlab.client.kakao.SuspendableClient | ||
import org.springframework.web.reactive.function.client.WebClient | ||
|
||
class SuspendableDiscordWebhookClient( | ||
client: WebClient, | ||
private val config: DiscordWebhookClientConfig.Config, | ||
) : DiscordWebhookClient, SuspendableClient(client) { | ||
override suspend fun getWebhookWithToken(id: Int): GetWebhookWithTokenResponse { | ||
return client | ||
.get() | ||
.discordUri(id) | ||
.request() | ||
} | ||
|
||
override suspend fun sendMessage(id: Int, request: SendMessageRequest) { | ||
return client | ||
.post() | ||
.discordUri(id) | ||
.bodyValue(request) | ||
.request() | ||
} | ||
|
||
private fun WebClient.RequestHeadersUriSpec<*>.discordUri(id: Int): WebClient.RequestHeadersSpec<*> { | ||
val credential = getWebhookCredential(id) | ||
return this.uri("/${credential.webhookId}/${credential.webhookToken}") | ||
} | ||
|
||
private fun WebClient.RequestBodyUriSpec.discordUri(id: Int): WebClient.RequestBodySpec { | ||
val credential = getWebhookCredential(id) | ||
return this.uri("/${credential.webhookId}/${credential.webhookToken}") | ||
} | ||
|
||
private fun getWebhookCredential(id: Int): DiscordWebhookClientConfig.Config.WebhookContext { | ||
return config.credential[id] ?: throw RuntimeException("Webhook Credential does not exist, $id") | ||
} | ||
} |
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