File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
src/main/kotlin/io/github/arkosammy12/compsmpdiscordbot/extensions Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ class ApprovalExtension() : Extension() {
44
44
val approvalEmojiId: () -> Long = { CompSMPDiscordBot .CONFIG_MANAGER .getRawNumberSettingValue(ConfigUtils .APPROVAL_EMOJI_ID )!! }
45
45
val approvalRoleId: () -> Long = { CompSMPDiscordBot .CONFIG_MANAGER .getRawNumberSettingValue(ConfigUtils .APPROVAL_ROLE_ID )!! }
46
46
val approvalEmojiName: () -> String = { CompSMPDiscordBot .CONFIG_MANAGER .getRawStringSettingValue(ConfigUtils .APPROVAL_EMOJI_NAME )!! }
47
+ val httpClient: HttpClient by lazy {
48
+ HttpClient ()
49
+ }
47
50
48
51
override suspend fun setup () {
49
52
this .event<ReactionAddEvent > {
@@ -87,8 +90,7 @@ class ApprovalExtension() : Extension() {
87
90
action {
88
91
respond {
89
92
val username: String = arguments.username
90
- val client = HttpClient ()
91
- val response: HttpResponse = client.get(URLBuilder (" https://api.mojang.com/users/profiles/minecraft/${username} " ).build()) {
93
+ val response: HttpResponse = httpClient.get(URLBuilder (" https://api.mojang.com/users/profiles/minecraft/${username} " ).build()) {
92
94
method = HttpMethod .Get
93
95
timeout {
94
96
requestTimeoutMillis = 5_000
@@ -108,13 +110,16 @@ class ApprovalExtension() : Extension() {
108
110
} else {
109
111
content = " Error fetching game profile: ${response.status} "
110
112
}
111
- client.close()
112
113
}
113
114
}
114
115
}
115
116
116
117
}
117
118
119
+ override suspend fun unload () {
120
+ this .httpClient.close()
121
+ }
122
+
118
123
private suspend fun matchesApprovalContext (eventEmoji : ReactionEmoji , user : UserBehavior , message : MessageBehavior ): Boolean {
119
124
if (eventEmoji !is ReactionEmoji .Custom ) {
120
125
return false
You can’t perform that action at this time.
0 commit comments