Compare commits

..

No commits in common. "b77271517d4aab3bdd3a4da5cba842c8a95632e3" and "fdf63c4605d8d7579be43b20b270f542dc3afd82" have entirely different histories.

11 changed files with 45 additions and 69 deletions

View file

@ -75,11 +75,11 @@ class AcceptEditButton() : IEditButton {
if (!found || mpdd == null) { if (!found || mpdd == null) {
return return
} }
val role = guild.getRoleOrNull(Snowflake(mpdd.roleID)) ?: return val role = guild.getRoleOrNull(Snowflake(mpdd.roleid)) ?: return
val member = interaction.user.asMember(guild.id) ?: return val member = interaction.user.asMember(guild.id) ?: return
// do the checks and update // do the checks and update
if (m.embeds[0].fields[0].value.contains(user.id.value.toString())) { if (m.embeds[0].fields[0].value.contains(user.id.value.toString())) {
if (member.roleIds.contains(Snowflake(mpdd.roleID))) { if (member.roleIds.contains(Snowflake(mpdd.roleid))) {
Logger.out("Removing role from ${member.username}") Logger.out("Removing role from ${member.username}")
member.removeRole(role.id) member.removeRole(role.id)
} }
@ -94,7 +94,7 @@ class AcceptEditButton() : IEditButton {
shouldEditButton = true shouldEditButton = true
} }
if (!m.embeds[0].fields[0].value.contains(user.id.value.toString())) { if (!m.embeds[0].fields[0].value.contains(user.id.value.toString())) {
if (!member.roleIds.contains(Snowflake(mpdd.roleID))) { if (!member.roleIds.contains(Snowflake(mpdd.roleid))) {
Logger.out("Adding role to ${member.username}") Logger.out("Adding role to ${member.username}")
member.addRole(role.id) member.addRole(role.id)
} }

View file

@ -72,9 +72,9 @@ class CancelEditButton : IEditButton {
if (!found || mpdd == null) { if (!found || mpdd == null) {
return return
} }
val role = guild.getRoleOrNull(Snowflake(mpdd.roleID)) ?: return val role = guild.getRoleOrNull(Snowflake(mpdd.roleid)) ?: return
val member = interaction.user.asMember(guild.id) val member = interaction.user.asMember(guild.id)
if (member.roleIds.contains(Snowflake(mpdd.roleID))) { if (member.roleIds.contains(Snowflake(mpdd.roleid))) {
member.removeRole(role.id) member.removeRole(role.id)
} }
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit { Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {

View file

@ -75,10 +75,10 @@ class DeclineEditButton : IEditButton {
if (!found || mpdd == null) { if (!found || mpdd == null) {
return return
} }
val role = guild.getRoleOrNull(Snowflake(mpdd.roleID)) ?: return val role = guild.getRoleOrNull(Snowflake(mpdd.roleid)) ?: return
val member = interaction.user.asMember(guild.id) ?: return val member = interaction.user.asMember(guild.id) ?: return
if (m.embeds[0].fields[0].value.contains(user.id.value.toString())) { if (m.embeds[0].fields[0].value.contains(user.id.value.toString())) {
if (member.roleIds.contains(Snowflake(mpdd.roleID))) { if (member.roleIds.contains(Snowflake(mpdd.roleid))) {
Logger.out("Removing role from ${member.username}") Logger.out("Removing role from ${member.username}")
member.removeRole(role.id) member.removeRole(role.id)
} }
@ -88,7 +88,7 @@ class DeclineEditButton : IEditButton {
shouldEditButton = true shouldEditButton = true
} }
if (!m.embeds[0].fields[1].value.contains(user.id.value.toString())) { if (!m.embeds[0].fields[1].value.contains(user.id.value.toString())) {
if (member.roleIds.contains(Snowflake(mpdd.roleID))) { if (member.roleIds.contains(Snowflake(mpdd.roleid))) {
Logger.out("Removing role from ${member.username}") Logger.out("Removing role from ${member.username}")
member.removeRole(role.id) member.removeRole(role.id)
} }

View file

@ -20,13 +20,13 @@ package net.moonleay.lilJudd.data.entry
data class MatchPlanningDataData( data class MatchPlanningDataData(
val id: Int, val id: Int,
val serverID: Long, val serverid: Long,
val channelID: Long, val channelid: Long,
val matchType: String, val matchtype: String,
val registererID: Long, val registererid: Long,
val roleID: Long, val roleid: Long,
val opponentName: String, val opponentname: String,
val messageID: Long, val messageid: Long,
val timestamp: Long, val timestamp: Long,
val jobString: String val jobstr: String
) )

View file

@ -20,7 +20,7 @@ package net.moonleay.lilJudd.data.entry
data class PlanningNotifierRolesData( data class PlanningNotifierRolesData(
val serverID: Long, // The id of the server val serverID: Long, // The id of the server
val channelID: Long, // The id of the channel val channelId: Long, // The id of the channel
val hasTimeRoleID: Long, // The id of the role that has time today val hastimeroleid: Long, // The id of the role that has time today
val wantsToBeNotifiedID: Long // The id of the role that wants to be notified val wantstobenotifid: Long // The id of the role that wants to be notified
) )

View file

@ -1,24 +0,0 @@
/*
* lilJudd
* Copyright (C) 2023 moonleay
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.moonleay.lilJudd.data.entry
data class TimePlanningChannelsData(
val serverID: Long,
val channelID: Long,
)

View file

@ -19,8 +19,8 @@
package net.moonleay.lilJudd.data.entry package net.moonleay.lilJudd.data.entry
data class TimePlanningMessagesData( data class TimePlanningMessagesData(
val serverID: Long, // The discord server id val serverid: Long, // The discord server id
val channelID: Long, // The discord channel id val channelid: Long, // The discord channel id
val weekstamp: Long, // The timestamp of the monday of the week at 4am UTC val weekstamp: Long, // The timestamp of the monday of the week at 4am UTC
val messageIDs: String // IDs are in the following format: "{weekdayNr}:{id};{weekdayNr}:{id};[etc.]" val messageids: String // IDs are in the following format: "{weekdayNr}:{id};{weekdayNr}:{id};[etc.]"
) )

View file

@ -80,15 +80,15 @@ object AvailabilityManager : IFeature {
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.
if (roleMap.isEmpty()) { if (roleMap.isEmpty()) {
Logger.out("No saved roles. Canceling.") Logger.out("No saved roles. Canceling.")
return return
} }
val roleData = roleMap[data.channelID] // Get the role data val roleData = roleMap[data.channelid] // Get the role data
if (roleData == null) { if (roleData == null) {
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) this.updateInChannel(snf, data, roleData)
@ -130,10 +130,10 @@ object AvailabilityManager : IFeature {
Logger.out("Could not find data for channel ${snf.value}") Logger.out("Could not find data for channel ${snf.value}")
return return
} }
if (Bot.bot.kordRef.getChannel(Snowflake(data.channelID)) == null) if (Bot.bot.kordRef.getChannel(Snowflake(data.channelid)) == null)
return // This channel does not exist anymore. return // This channel does not exist anymore.
if (roleData == null) { if (roleData == null) {
Logger.out("Role for channel ${data.channelID} does not exist") Logger.out("Role for channel ${data.channelid} does not exist")
return // this took way to long to find out that this was the issue return // this took way to long to find out that this was the issue
} }
updateInChannel(snf, data, roleData) updateInChannel(snf, data, roleData)
@ -141,18 +141,18 @@ object AvailabilityManager : IFeature {
@OptIn(PrivilegedIntent::class) @OptIn(PrivilegedIntent::class)
suspend fun updateInChannel(snf: Snowflake, tpmd: TimePlanningMessagesData, pnrd: PlanningNotifierRolesData) { suspend fun updateInChannel(snf: Snowflake, tpmd: TimePlanningMessagesData, pnrd: PlanningNotifierRolesData) {
if (Bot.bot.kordRef.getChannel(Snowflake(tpmd.channelID)) == null) if (Bot.bot.kordRef.getChannel(Snowflake(tpmd.channelid)) == null)
return // This channel does not exist anymore. return // This channel does not exist anymore.
val c = val c =
Bot.bot.kordRef.getChannelOf<MessageChannel>(Snowflake(tpmd.channelID))!! // Get the channel as MessageChannel Bot.bot.kordRef.getChannelOf<MessageChannel>(Snowflake(tpmd.channelid))!! // Get the channel as MessageChannel
if (Bot.bot.kordRef.getGuildOrNull(Snowflake(tpmd.serverID)) == null) { if (Bot.bot.kordRef.getGuildOrNull(Snowflake(tpmd.serverid)) == null) {
Logger.out("Guild not found.") Logger.out("Guild not found.")
return return
} }
val weekday = ZonedDateTime.now().dayOfWeek // The current week day val weekday = ZonedDateTime.now().dayOfWeek // The current week day
val weekStamp = TimeUtil.getWeekStamp().toEpochSecond() * 1000 // The current week time stamp 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.") Logger.out("It is week ${weekStamp} and day ${weekday}/${TimeUtil.getDayOfMonthInt(weekday)} of the week.")
val g = Bot.bot.kordRef.getGuildOrThrow(Snowflake(tpmd.serverID)) 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()
@ -161,8 +161,8 @@ object AvailabilityManager : IFeature {
memberchunkevent.members.forEach { memberchunkevent.members.forEach {
if (!it.isNullOrBot()) { // Check if the member is a bot if (!it.isNullOrBot()) { // Check if the member is a bot
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(pnrd.hastimeroleid))) {
it.removeRole(Snowflake(pnrd.hasTimeRoleID)) it.removeRole(Snowflake(pnrd.hastimeroleid))
Logger.out("Removed role from ${it.username}") // Removed the role Logger.out("Removed role from ${it.username}") // Removed the role
} }
} }
@ -174,7 +174,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 = tpmd.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))
@ -192,15 +192,15 @@ object AvailabilityManager : IFeature {
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(tpmd.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(tpmd.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(pnrd.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(pnrd.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...")

View file

@ -57,9 +57,9 @@ object MatchManager {
Logger.out("Checking match role ${data.id}...") Logger.out("Checking match role ${data.id}...")
if (data.timestamp.toLong() < System.currentTimeMillis()) { if (data.timestamp.toLong() < System.currentTimeMillis()) {
Logger.out("Match role ${data.id} is expired, removing...") Logger.out("Match role ${data.id} is expired, removing...")
this.removeRoleFromGuild(data.serverID, data.roleID) this.removeRoleFromGuild(data.serverid, data.roleid)
transaction { transaction {
MatchPlanningData.deleteWhere { MatchPlanningData.messageid eq data.messageID } MatchPlanningData.deleteWhere { MatchPlanningData.messageid eq data.messageid }
} }
continue continue
} }
@ -71,9 +71,9 @@ object MatchManager {
private fun registerJob(data: MatchPlanningDataData) { private fun registerJob(data: MatchPlanningDataData) {
JobManager.addJob( JobManager.addJob(
MatchJob( MatchJob(
data.jobString, data.jobstr,
data.id, data.id,
"fromdb-${data.matchType}_Vs_${data.opponentName}_[${data.id}]-${data.serverID}_${data.channelID}" "fromdb-${data.matchtype}_Vs_${data.opponentname}_[${data.id}]-${data.serverid}_${data.channelid}"
) )
) )
Logger.out("Registered job for match ${data.id}...") Logger.out("Registered job for match ${data.id}...")

View file

@ -94,7 +94,7 @@ object TimeManager : IFeature {
if (roleMap != null && roleMap.keys.contains(ch) && roleMap[ch] != null) { if (roleMap != null && roleMap.keys.contains(ch) && roleMap[ch] != null) {
c.createMessage { c.createMessage {
this.content = this.content =
"The weekly planning starts now <@&${Snowflake(roleMap[ch]?.wantsToBeNotifiedID!!)}>" "The weekly planning starts now <@&${Snowflake(roleMap[ch]?.wantstobenotifid!!)}>"
this.embeds.add( this.embeds.add(
MessageUtil.getEmbed( MessageUtil.getEmbed(
EmbedColor.INFO, EmbedColor.INFO,

View file

@ -67,12 +67,12 @@ class MatchJob(
) )
} }
} }
val guild = Bot.bot.kordRef.getGuildOrNull(Snowflake(mpdd.serverID)) val guild = Bot.bot.kordRef.getGuildOrNull(Snowflake(mpdd.serverid))
if (guild == null) { if (guild == null) {
Logger.out("Guild not found.") Logger.out("Guild not found.")
return return
} }
val r = guild.getRoleOrNull(Snowflake(mpdd.roleID)) val r = guild.getRoleOrNull(Snowflake(mpdd.roleid))
if (r == null) { if (r == null) {
Logger.out("Role not found.") Logger.out("Role not found.")
return return