Skip to content

Commit f7ad9c4

Browse files
committed
Add participated role
1 parent 266ece1 commit f7ad9c4

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

botfest/src/main/kotlin/net/modfest/botfest/App.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,21 @@ val PLATFORM_SHARED_SECRET = env("PLATFORM_SECRET")
2121
val MAIN_GUILD_ID = Snowflake(
2222
env("MAIN_GUILD").toLong() // Get the test server ID from the env vars or a .env file
2323
)
24+
25+
/**
26+
* The role people get when they've got a registered modfest account
27+
*/
2428
val REGISTERED_ROLE = envOrNull("REGISTERED_ROLE")?.let {
2529
if (it.isBlank()) { null } else { Snowflake(it.toLong()) }
2630
}
2731

32+
/**
33+
* The role people get when they've been a participant in at least one fest
34+
*/
35+
val PARTICIPATED_ROLE = envOrNull("PARTICIPATED_ROLE")?.let {
36+
if (it.isBlank()) { null } else { Snowflake(it.toLong()) }
37+
}
38+
2839
private val TOKEN = env("TOKEN") // Get the bot's token from the env vars or a .env file
2940

3041
suspend fun main() {

botfest/src/main/kotlin/net/modfest/botfest/extensions/RoleManager.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import io.github.oshai.kotlinlogging.KotlinLogging
1616
import kotlinx.coroutines.*
1717
import kotlinx.coroutines.flow.*
1818
import net.modfest.botfest.MAIN_GUILD_ID
19+
import net.modfest.botfest.PARTICIPATED_ROLE
1920
import net.modfest.botfest.Platform
2021
import net.modfest.botfest.REGISTERED_ROLE
2122
import net.modfest.botfest.i18n.Translations
@@ -253,6 +254,7 @@ class RoleManager : Extension(), KordExKoinComponent {
253254
/**
254255
* For when we resync with platform. This method will not fetch anything from discord,
255256
* it presumes the cached discord data is correct.
257+
* TODO needs to be called when event phase changes
256258
*/
257259
suspend fun fixAllUsers() {
258260
val users = platform.authenticatedAsBotFest().getUsers()
@@ -345,6 +347,9 @@ class RoleManager : Extension(), KordExKoinComponent {
345347
if (REGISTERED_ROLE != null) {
346348
roles.add(REGISTERED_ROLE)
347349
}
350+
if (PARTICIPATED_ROLE != null) {
351+
roles.add(PARTICIPATED_ROLE)
352+
}
348353

349354
platform.getEvents().forEach { event ->
350355
roles.add(Snowflake(event.discordRoles.participant))
@@ -368,10 +373,20 @@ class RoleManager : Extension(), KordExKoinComponent {
368373
roles.add(REGISTERED_ROLE)
369374
}
370375

376+
var hasParticipated = false
377+
371378
platformData.registered.forEach { event ->
372-
val eventRoles = platform.getEvent(event).discordRoles
373-
roles.add(Snowflake(eventRoles.participant))
379+
val eventData = platform.getEvent(event)
380+
roles.add(Snowflake(eventData.discordRoles.participant))
381+
if (eventData.phase.grantsParticipatedRole()) {
382+
hasParticipated = true
383+
}
374384
}
385+
386+
if (hasParticipated && PARTICIPATED_ROLE != null) {
387+
roles.add(PARTICIPATED_ROLE)
388+
}
389+
375390
return roles
376391
}
377392

common/src/main/java/net/modfest/platform/pojo/EventData.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ public boolean canSubmit() {
5353
public boolean canUpdateSubmission() {
5454
return updates;
5555
}
56+
57+
/**
58+
* Determines if an event in this phase grants the participated role (for
59+
* access to the #participant channel and the likes). At the moment, people
60+
* are only eligible for that channel at the end of the event. So if they're
61+
* participating in an event that's still ongoing they're not eligible for that
62+
* channel. But if they participated in an event where this function returns true,
63+
* they are eligible for the channel.
64+
*/
65+
public boolean grantsParticipatedRole() {
66+
return this == Phase.SHOWCASE || this == Phase.COMPLETE;
67+
}
5668
}
5769

5870
public record Images(String full, String transparent, String wordmark, String background) {

0 commit comments

Comments
 (0)