-
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.
Merge pull request #29 from TeamMiso/feat/discord-setting
๐ :: Discord ์ธํ
- Loading branch information
Showing
4 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...n/kotlin/andreas311/miso/domain/inquiry/application/port/output/DiscordMessageSendPort.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,9 @@ | ||
package andreas311.miso.domain.inquiry.application.port.output | ||
|
||
interface DiscordMessageSendPort { | ||
fun sendDiscordMessage(message: String) | ||
|
||
fun toSingleDiscordMessage(string: String): String | ||
|
||
fun createInquiryMessage(inquiryName: String): String | ||
} |
2 changes: 1 addition & 1 deletion
2
...s311/miso/global/config/QuerydslConfig.kt โ ...11/miso/global/querydsl/QuerydslConfig.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
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/andreas311/miso/global/webhook/WebHookConfig.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,13 @@ | ||
package andreas311.miso.global.webhook | ||
|
||
import okhttp3.OkHttpClient | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
@Configuration | ||
class WebHookConfig { | ||
private val httpClient = OkHttpClient() | ||
|
||
@Bean | ||
fun httpClient() = httpClient | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/kotlin/andreas311/miso/thirdparty/discord/DiscordMessageSendAdapter.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,70 @@ | ||
package andreas311.miso.thirdparty.discord | ||
|
||
import andreas311.miso.domain.inquiry.application.port.output.DiscordMessageSendPort | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class DiscordMessageSendAdapter( | ||
private val okHttpClient: OkHttpClient | ||
): DiscordMessageSendPort { | ||
|
||
@Value("\${discord.webhook.url}") | ||
private lateinit var discordWebhookUrl: String | ||
|
||
private val log = LoggerFactory.getLogger(this.javaClass.simpleName) | ||
|
||
override fun sendDiscordMessage(message: String) { | ||
|
||
val requestBody = message.toRequestBody("application/json; charset=utf-8".toMediaType()) | ||
|
||
val request = Request.Builder() | ||
.url(discordWebhookUrl) | ||
.post(requestBody) | ||
.build() | ||
|
||
okHttpClient.newCall(request).execute().use { response -> | ||
if (response.isSuccessful) { | ||
log.trace("๋ฌธ์๋ด์ด ๋ฌธ์์ฌํญ ์์ฒญ์ ์ฑ๊ณต์ ์ผ๋ก ์ ๋ฌํ์ด์!") | ||
} else { | ||
log.error(response.body?.string()) | ||
log.error("๋ฌธ์๋ด์ด ๋ฌธ์์ฌํญ ์์ฒญ ๋์ ${response.code} ์ฝ๋๋ฅผ ๋ณด๋์ด์!") | ||
} | ||
} | ||
} | ||
|
||
override fun toSingleDiscordMessage(string: String): String { | ||
return """ | ||
{ | ||
"content":"$string" | ||
} | ||
""".trimIndent() | ||
} | ||
|
||
override fun createInquiryMessage(inquiryName: String): String { | ||
return """ | ||
{ | ||
"content": "๋ฌธ์์ฌํญ ์์ฒญ์ด ๋ค์ด์์ด์!", | ||
"embeds": [ | ||
{ | ||
"title": "๋ฌธ์์ฌํญ์ ํ์ธํด์ฃผ์ธ์!", | ||
"color": 5725911, | ||
"fields": [ | ||
{ | ||
"name": "๋ฌธ์์ฌํญ ์ ๋ชฉ", | ||
"value": "$inquiryName", | ||
"inline": true | ||
} | ||
] | ||
} | ||
], | ||
"attachments": [] | ||
} | ||
""".trimIndent() | ||
} | ||
} |