File tree Expand file tree Collapse file tree
src/main/kotlin/io/github/arkosammy12/compsmpdiscordbot/extensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,6 +44,9 @@ class ApprovalExtension() : Extension() {
4444 val approvalEmojiId: () -> Long = { CompSMPDiscordBot .CONFIG_MANAGER .getRawNumberSettingValue(ConfigUtils .APPROVAL_EMOJI_ID )!! }
4545 val approvalRoleId: () -> Long = { CompSMPDiscordBot .CONFIG_MANAGER .getRawNumberSettingValue(ConfigUtils .APPROVAL_ROLE_ID )!! }
4646 val approvalEmojiName: () -> String = { CompSMPDiscordBot .CONFIG_MANAGER .getRawStringSettingValue(ConfigUtils .APPROVAL_EMOJI_NAME )!! }
47+ val httpClient: HttpClient by lazy {
48+ HttpClient ()
49+ }
4750
4851 override suspend fun setup () {
4952 this .event<ReactionAddEvent > {
@@ -87,8 +90,7 @@ class ApprovalExtension() : Extension() {
8790 action {
8891 respond {
8992 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()) {
9294 method = HttpMethod .Get
9395 timeout {
9496 requestTimeoutMillis = 5_000
@@ -108,13 +110,16 @@ class ApprovalExtension() : Extension() {
108110 } else {
109111 content = " Error fetching game profile: ${response.status} "
110112 }
111- client.close()
112113 }
113114 }
114115 }
115116
116117 }
117118
119+ override suspend fun unload () {
120+ this .httpClient.close()
121+ }
122+
118123 private suspend fun matchesApprovalContext (eventEmoji : ReactionEmoji , user : UserBehavior , message : MessageBehavior ): Boolean {
119124 if (eventEmoji !is ReactionEmoji .Custom ) {
120125 return false
You can’t perform that action at this time.
0 commit comments