feat: make the bot update the roles on startup

fix: fixed the bot throwing Errors when there is no role for a channel

Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
limited_dev 2023-06-29 09:57:36 +02:00
parent d6bf2e7bc9
commit 196bb378b4
2 changed files with 17 additions and 3 deletions

View file

@ -22,6 +22,7 @@ import com.kotlindiscord.kord.extensions.ExtensibleBot
import dev.kord.common.Color
import dev.kord.common.entity.PresenceStatus
import dev.kord.core.behavior.interaction.response.respond
import dev.kord.core.event.gateway.ReadyEvent
import dev.kord.core.event.interaction.ButtonInteractionCreateEvent
import dev.kord.core.on
import dev.kord.gateway.Intent
@ -151,6 +152,11 @@ object Bot {
}
}
// Update roles
bot.kordRef.on<ReadyEvent> {
AvailabilityManager.runThread()
}
//Start the bot
bot.start()

View file

@ -88,14 +88,22 @@ object AvailabilityManager : IFeature {
continue // This channel does not exist anymore.
val c =
Bot.bot.kordRef.getChannelOf<MessageChannel>(Snowflake(data.channelid))!! // Get the channel as MessageChannel
val roleData = roleMap[data.channelid]!! // Get the role data
if (roleMap.size < 1) {
Logger.out("No saved roles. Canceling.")
return
}
val roleData = roleMap[data.channelid] // Get the role data
if (roleData == null) {
Logger.out("Role for this channel does not exist")
return
}
val g = Bot.bot.kordRef.getGuildOrThrow(Snowflake(data.serverid))
// Get all members with the role
val mce = g.requestMembers {
this.requestAllMembers()
}
mce.collect { it1 ->
it1.members.forEach {
mce.collect { memberchunkevent ->
memberchunkevent.members.forEach {
Logger.out("Checking member ${it.id.value}")
if (it.roleIds.contains(Snowflake(roleData.hastimeroleid)))
it.removeRole(Snowflake(roleData.hastimeroleid))