Compare commits
No commits in common. "3d1f2c7d8f46d55bfbf157701b3b5d0f162e969b" and "de1d8cd3a675e2484127caf38e8de7b45f243249" have entirely different histories.
3d1f2c7d8f
...
de1d8cd3a6
5 changed files with 58 additions and 112 deletions
|
@ -32,7 +32,7 @@ val ownerID = 372703841151614976L
|
||||||
group = "net.moonleay.liljudd"
|
group = "net.moonleay.liljudd"
|
||||||
version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" }
|
version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_SHORT_SHA")}-prod" }
|
||||||
?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" }
|
?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" }
|
||||||
?: "2.5.3"
|
?: "2.5.1"
|
||||||
|
|
||||||
val kordver = "1.5.6"
|
val kordver = "1.5.6"
|
||||||
val coroutinesver = "1.1.0"
|
val coroutinesver = "1.1.0"
|
||||||
|
|
|
@ -63,6 +63,6 @@ class IsAvailableEditButton : IEditButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AvailabilityManager.updateInChannel(interaction.channelId)
|
AvailabilityManager.runThread()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,6 @@ class MaybeAvailableEditButton : IEditButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AvailabilityManager.updateInChannel(interaction.channelId)
|
AvailabilityManager.runThread()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,6 @@ class NotAvailableEditButton : IEditButton {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
AvailabilityManager.updateInChannel(interaction.channelId)
|
AvailabilityManager.runThread()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,10 +81,15 @@ object AvailabilityManager : IFeature {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val weekday = ZonedDateTime.now().dayOfWeek // The current week day
|
||||||
|
val weekStamp = TimeUtil.getWeekStamp().toEpochSecond() * 1000 // The current week time stamp
|
||||||
|
Logger.out("It is week ${weekStamp} and day ${weekday}/${TimeUtil.getDayOfMonthInt(weekday)} of the week.")
|
||||||
for (snf in messageMap.keys) { // snf = Snowflake
|
for (snf in messageMap.keys) { // snf = Snowflake
|
||||||
val data = messageMap[snf]!! // this is the data of the table
|
val data = messageMap[snf]!! // this is the data of the table
|
||||||
if (Bot.bot.kordRef.getChannel(Snowflake(data.channelid)) == null)
|
if (Bot.bot.kordRef.getChannel(Snowflake(data.channelid)) == null)
|
||||||
continue // This channel does not exist anymore.
|
continue // This channel does not exist anymore.
|
||||||
|
val c =
|
||||||
|
Bot.bot.kordRef.getChannelOf<MessageChannel>(Snowflake(data.channelid))!! // Get the channel as MessageChannel
|
||||||
if (roleMap.isEmpty()) {
|
if (roleMap.isEmpty()) {
|
||||||
Logger.out("No saved roles. Canceling.")
|
Logger.out("No saved roles. Canceling.")
|
||||||
return
|
return
|
||||||
|
@ -94,68 +99,7 @@ object AvailabilityManager : IFeature {
|
||||||
Logger.out("Role for channel ${data.channelid} does not exist")
|
Logger.out("Role for channel ${data.channelid} does not exist")
|
||||||
continue // this took way to long to find out that this was the issue
|
continue // this took way to long to find out that this was the issue
|
||||||
}
|
}
|
||||||
this.updateInChannel(snf, data, roleData)
|
val g = Bot.bot.kordRef.getGuildOrThrow(Snowflake(data.serverid))
|
||||||
}
|
|
||||||
Logger.out("Done! Until tomorrow! <3 ")
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun updateInChannel(snf: Snowflake) {
|
|
||||||
lateinit var data: TimePlanningMessagesData
|
|
||||||
lateinit var roleData: PlanningNotifierRolesData
|
|
||||||
var found1 = false
|
|
||||||
var found2 = false
|
|
||||||
for (pnr in TimePlanningMessages.select {
|
|
||||||
TimePlanningMessages.weekstamp eq (TimeUtil.getWeekStamp()
|
|
||||||
.toEpochSecond() * 1000) and (TimePlanningMessages.channelid eq (snf.value.toLong()))
|
|
||||||
}) {
|
|
||||||
data =
|
|
||||||
TimePlanningMessagesData(
|
|
||||||
pnr[TimePlanningMessages.serverid],
|
|
||||||
pnr[TimePlanningMessages.channelid],
|
|
||||||
pnr[TimePlanningMessages.weekstamp],
|
|
||||||
pnr[TimePlanningMessages.messageids]
|
|
||||||
)
|
|
||||||
found1 = true
|
|
||||||
}
|
|
||||||
for (pnr in PlanningNotifierRoles.select {
|
|
||||||
PlanningNotifierRoles.channelid eq (snf.value.toLong())
|
|
||||||
}) {
|
|
||||||
roleData =
|
|
||||||
PlanningNotifierRolesData(
|
|
||||||
pnr[PlanningNotifierRoles.serverid],
|
|
||||||
pnr[PlanningNotifierRoles.channelid],
|
|
||||||
pnr[PlanningNotifierRoles.hastimeroleid],
|
|
||||||
pnr[PlanningNotifierRoles.wantstobenotifiedid]
|
|
||||||
)
|
|
||||||
found2 = true
|
|
||||||
}
|
|
||||||
if (!found1 || !found2) {
|
|
||||||
Logger.out("Could not find data for channel ${snf.value}")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (Bot.bot.kordRef.getChannel(Snowflake(data.channelid)) == null)
|
|
||||||
return // This channel does not exist anymore.
|
|
||||||
if (roleData == null) {
|
|
||||||
Logger.out("Role for channel ${data.channelid} does not exist")
|
|
||||||
return // this took way to long to find out that this was the issue
|
|
||||||
}
|
|
||||||
updateInChannel(snf, data, roleData)
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(PrivilegedIntent::class)
|
|
||||||
suspend fun updateInChannel(snf: Snowflake, tpmd: TimePlanningMessagesData, pnrd: PlanningNotifierRolesData) {
|
|
||||||
if (Bot.bot.kordRef.getChannel(Snowflake(tpmd.channelid)) == null)
|
|
||||||
return // This channel does not exist anymore.
|
|
||||||
val c =
|
|
||||||
Bot.bot.kordRef.getChannelOf<MessageChannel>(Snowflake(tpmd.channelid))!! // Get the channel as MessageChannel
|
|
||||||
if (Bot.bot.kordRef.getGuildOrNull(Snowflake(tpmd.serverid)) == null) {
|
|
||||||
Logger.out("Guild not found.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val weekday = ZonedDateTime.now().dayOfWeek // The current week day
|
|
||||||
val weekStamp = TimeUtil.getWeekStamp().toEpochSecond() * 1000 // The current week time stamp
|
|
||||||
Logger.out("It is week ${weekStamp} and day ${weekday}/${TimeUtil.getDayOfMonthInt(weekday)} of the week.")
|
|
||||||
val g = Bot.bot.kordRef.getGuildOrThrow(Snowflake(tpmd.serverid))
|
|
||||||
// Get all members with the role
|
// Get all members with the role
|
||||||
val mce = g.requestMembers {
|
val mce = g.requestMembers {
|
||||||
this.requestAllMembers()
|
this.requestAllMembers()
|
||||||
|
@ -163,8 +107,8 @@ object AvailabilityManager : IFeature {
|
||||||
mce.collect { memberchunkevent ->
|
mce.collect { memberchunkevent ->
|
||||||
memberchunkevent.members.forEach {
|
memberchunkevent.members.forEach {
|
||||||
Logger.out("Checking member ${it.id.value} (${it.username})")
|
Logger.out("Checking member ${it.id.value} (${it.username})")
|
||||||
if (it.roleIds.contains(Snowflake(pnrd.hastimeroleid))) {
|
if (it.roleIds.contains(Snowflake(roleData.hastimeroleid))) {
|
||||||
it.removeRole(Snowflake(pnrd.hastimeroleid))
|
it.removeRole(Snowflake(roleData.hastimeroleid))
|
||||||
Logger.out("Removed role from ${it.username}") // Removed the role
|
Logger.out("Removed role from ${it.username}") // Removed the role
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,7 +118,7 @@ object AvailabilityManager : IFeature {
|
||||||
// This stores the ids of the messages.
|
// This stores the ids of the messages.
|
||||||
// The format is weekdaNR:ID
|
// The format is weekdaNR:ID
|
||||||
// The last entry (nr 8) is empty, so we can ignore it
|
// The last entry (nr 8) is empty, so we can ignore it
|
||||||
val messageIdSplit = tpmd.messageids.split(";").subList(0, 7)
|
val messageIdSplit = data.messageids.split(";").subList(0, 7)
|
||||||
for (mid in messageIdSplit) {
|
for (mid in messageIdSplit) {
|
||||||
Logger.out("Checking id $mid")
|
Logger.out("Checking id $mid")
|
||||||
if (!mid.startsWith((TimeUtil.getDayOfMonthInt(weekday) - 1).toString(), true))
|
if (!mid.startsWith((TimeUtil.getDayOfMonthInt(weekday) - 1).toString(), true))
|
||||||
|
@ -183,24 +127,24 @@ object AvailabilityManager : IFeature {
|
||||||
val message = c.getMessageOrNull(Snowflake(idFiltered)) // Get the message from the channel
|
val message = c.getMessageOrNull(Snowflake(idFiltered)) // Get the message from the channel
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
Logger.out("Could not find message.")
|
Logger.out("Could not find message.")
|
||||||
return // This message does not exist anymore. Nothing we can do about that.
|
break // This message does not exist anymore. Nothing we can do about that.
|
||||||
}
|
}
|
||||||
if (message.data.embeds.isEmpty()) {
|
if (message.data.embeds.isEmpty()) {
|
||||||
Logger.out("There are no embeds.")
|
Logger.out("There are no embeds.")
|
||||||
return // There are no embeds or there are not enough embeds
|
break // There are no embeds or there are not enough embeds
|
||||||
}
|
}
|
||||||
val targets = EmbedUtil.getAllUsersInTheFirstXTables(2, message.embeds[0])
|
val targets = EmbedUtil.getAllUsersInTheFirstXTables(2, message.embeds[0])
|
||||||
for (tid in targets) {
|
for (tid in targets) {
|
||||||
Logger.out("Checking id $tid")
|
Logger.out("Checking id $tid")
|
||||||
if (Bot.bot.kordRef.getGuildOrNull(Snowflake(tpmd.serverid))!!
|
if (Bot.bot.kordRef.getGuildOrNull(Snowflake(data.serverid))!!
|
||||||
.getMemberOrNull(Snowflake(tid)) == null
|
.getMemberOrNull(Snowflake(tid)) == null
|
||||||
)
|
)
|
||||||
continue // This member does not exist anymore.
|
continue // This member does not exist anymore.
|
||||||
val member = Bot.bot.kordRef.getGuildOrThrow(Snowflake(tpmd.serverid))
|
val member = Bot.bot.kordRef.getGuildOrThrow(Snowflake(data.serverid))
|
||||||
.getMember(Snowflake(tid)) // Get the member
|
.getMember(Snowflake(tid)) // Get the member
|
||||||
if (member.roleIds.contains(Snowflake(pnrd.hastimeroleid)))
|
if (member.roleIds.contains(Snowflake(roleData.hastimeroleid)))
|
||||||
continue // This member already has the role
|
continue // This member already has the role
|
||||||
member.addRole(Snowflake(pnrd.hastimeroleid)) // Add the role
|
member.addRole(Snowflake(roleData.hastimeroleid)) // Add the role
|
||||||
Logger.out("Added role to ${member.username}")
|
Logger.out("Added role to ${member.username}")
|
||||||
}
|
}
|
||||||
Logger.out("Done with message. Moving on...")
|
Logger.out("Done with message. Moving on...")
|
||||||
|
@ -208,6 +152,8 @@ object AvailabilityManager : IFeature {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Logger.out("Done! Until tomorrow! <3 ")
|
||||||
|
}
|
||||||
|
|
||||||
override val feat: FeatureEnum
|
override val feat: FeatureEnum
|
||||||
get() = FeatureEnum.PLANNINGROLES
|
get() = FeatureEnum.PLANNINGROLES
|
||||||
|
|
Loading…
Reference in a new issue