You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -55,9 +59,9 @@ class AutoApprovalExtension() : Extension() {
55
59
return@action
56
60
}
57
61
val applicant:Member= event.messageAuthor?.asMember(CompSMPDiscordBot.guildSnowFlake) ?:return@action
58
-
applicant.addRole(Snowflake(approvalRoleId()))
62
+
applicant.addRole(Snowflake(approvalRoleId))
63
+
CompSMPDiscordBot.LOGGER.info("Successfully approved Discord user ${applicant.username}.")
59
64
}
60
-
61
65
}
62
66
this.event<ReactionRemoveEvent> {
63
67
action {
@@ -66,26 +70,28 @@ class AutoApprovalExtension() : Extension() {
66
70
}
67
71
val applicant:Member= event.message.asMessage().author?.asMember(CompSMPDiscordBot.guildSnowFlake) ?:return@action
68
72
val applicantRoles:Set<Snowflake> = applicant.roleIds
69
-
if (!applicantRoles.any { roleId -> roleId.value.toLong() == approvalRoleId() }) {
73
+
if (!applicantRoles.any { roleId -> roleId.value.toLong() == approvalRoleId }) {
70
74
return@action
71
75
}
72
-
val reactionEmoji:ReactionEmoji=ReactionEmoji.Custom(Snowflake(approvalEmojiId()), approvalEmojiName(), false)
76
+
val reactionEmoji:ReactionEmoji=ReactionEmoji.Custom(Snowflake(approvalEmojiId), approvalEmojiName, false)
73
77
var hasApprovedRoleByOtherAdmin =false
74
78
event.message.getReactors(reactionEmoji).filter { user -> user.id != event.user }.collect { user ->
75
79
val member:Member= user.asMember(CompSMPDiscordBot.guildSnowFlake)
76
-
if (member.roleIds.any {roleId -> roleId.value.toLong() == adminRoleId() }) {
80
+
if (member.roleIds.any {roleId -> roleId.value.toLong() == adminRoleId }) {
77
81
hasApprovedRoleByOtherAdmin =true
78
82
return@collect
79
83
}
80
84
}
81
85
if (!hasApprovedRoleByOtherAdmin) {
82
-
applicant.removeRole(Snowflake(approvalRoleId()))
86
+
applicant.removeRole(Snowflake(approvalRoleId))
87
+
CompSMPDiscordBot.LOGGER.info("Successfully de-approved Discord user ${applicant.username}.")
83
88
}
89
+
CompSMPDiscordBot.LOGGER.info("Tried to de-approve applicant ${applicant.username} but their message still has $approvalEmojiName reactions from other admins!")
84
90
}
85
91
}
86
92
publicSlashCommand(::FetchProfileArguments) {
87
-
name =Key("fetchGameProfile")
88
-
description =Key("Fetches a gameprofile for a given Minecraft username")
93
+
name ="getGameProfile".toKey()
94
+
description ="Retrieves the username and UUID of the specified Minecraft user.".toKey()
89
95
guild(CompSMPDiscordBot.guildSnowFlake)
90
96
action {
91
97
respond {
@@ -96,19 +102,22 @@ class AutoApprovalExtension() : Extension() {
96
102
requestTimeoutMillis =5_000
97
103
}
98
104
}
99
-
if (response.status ==HttpStatusCode.OK) {
100
-
val json:JsonObject=Json.parseToJsonElement(response.body()).jsonObject
101
-
val rawUuid:String?= json["id"]?.jsonPrimitive?.content
102
-
if (rawUuid ==null) {
103
-
content ="Error deserializing uuid. Missing field \"id\" from json response!"
104
-
} else {
105
-
val uuid:UUID=UUID.fromString(addDashesToUuid(rawUuid))
106
-
content ="Username: `${username}`. UUID: `$uuid`"
105
+
when {
106
+
response.isError -> content ="Error retrieving game profile for Minecraft user ${username}: ${response.errorString()}"
107
+
response.status.isSuccess() -> {
108
+
val json:JsonObject=Json.parseToJsonElement(response.body()).jsonObject
109
+
val rawUuid:String?= json["id"]?.jsonPrimitive?.content
110
+
val name:String?= json["name"]?.jsonPrimitive?.content
111
+
if (rawUuid ==null|| name ==null) {
112
+
content ="Error deserializing API json response!"
113
+
} else {
114
+
val uuid:UUID=UUID.fromString(addDashesToUuid(rawUuid))
115
+
content ="Username: `${name}`. UUID: `${uuid}`"
116
+
}
117
+
}
118
+
else-> {
119
+
content ="Error retrieving game"
107
120
}
108
-
} elseif (response.isError) {
109
-
content ="Error fetching game profile: ${response.errorString()}"
110
-
} else {
111
-
content ="Error fetching game profile: ${response.status}"
112
121
}
113
122
}
114
123
}
@@ -125,36 +134,37 @@ class AutoApprovalExtension() : Extension() {
125
134
returnfalse
126
135
}
127
136
val reactor:Member= user.asMember(CompSMPDiscordBot.guildSnowFlake)
128
-
if (!reactor.roleIds.any { roleId -> roleId.value.toLong() == adminRoleId() }) {
137
+
if (!reactor.roleIds.any { roleId -> roleId.value.toLong() == adminRoleId }) {
129
138
returnfalse
130
139
}
131
-
if (message.channelId.value.toLong() != applicationChannelId()) {
140
+
if (message.channelId.value.toLong() != applicationChannelId) {
132
141
returnfalse
133
142
}
134
-
if (eventEmoji.id.value.toLong() != approvalEmojiId()) {
143
+
if (eventEmoji.id.value.toLong() != approvalEmojiId) {
135
144
returnfalse
136
145
}
137
146
returntrue
138
147
}
139
148
140
-
privatefunaddDashesToUuid(uuid:String): String {
141
-
val buffer:StringBuffer=StringBuffer(uuid)
142
-
buffer.insert(20, '-')
143
-
buffer.insert(16, '-')
144
-
buffer.insert(12, '-')
145
-
buffer.insert(8, '-')
146
-
return buffer.toString()
147
-
}
148
-
149
149
innerclassFetchProfileArguments() : Arguments() {
150
150
val username by string {
151
-
name =Key("username")
152
-
description =Key("The username of the person you wish to see the Minecraft game profile of.")
151
+
name ="username".toKey()
152
+
description ="The username of the person you wish to see the Minecraft game profile of.".toKey()
0 commit comments