Skip to content

Commit 0aa1a8a

Browse files
committed
Add a method to get a region group from a string
1 parent 2795849 commit 0aa1a8a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/kotlin/dev/arbjerg/lavalink/client/loadbalancing/regionFiltering.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ object RegionGroup {
4545
return if (region in regions) RegionFilterVerdict.PASS else RegionFilterVerdict.SOFT_BLOCK
4646
}
4747
}
48+
49+
/**
50+
* Gets a [RegionGroup] from a string. This method is case-insensitive.
51+
*
52+
* @param region The region to get the [RegionGroup] for. Valid values are [ASIA], [EUROPE], and [US].
53+
*/
54+
fun valueOf(region: String) = when (region.uppercase()) {
55+
"ASIA" -> ASIA
56+
"EUROPE" -> EUROPE
57+
"US" -> US
58+
else -> throw IllegalArgumentException("No region constant: $region")
59+
}
4860
}
4961

5062
// TODO In case no exact server match, should it look for the closest node in that same region?

0 commit comments

Comments
 (0)