Compare commits

..

No commits in common. "4f8924fb1ab1f88dff91797afca76a38f1c70b67" and "d97511eb8b8dc842a9bf875e78985c6bb169c30e" have entirely different histories.

20 changed files with 89 additions and 117 deletions

View file

@ -76,9 +76,6 @@ object Bot {
CredentialManager.dbPassword CredentialManager.dbPassword
) )
// Make sure the database is up-to-date
DB.register()
// Register all the jobs // Register all the jobs
jobs.addAll( jobs.addAll(
listOf( listOf(

View file

@ -53,12 +53,12 @@ class AcceptEditButton() : IEditButton {
var found = false var found = false
transaction { transaction {
for (pnr in MatchPlanningData.select { for (pnr in MatchPlanningData.select {
MatchPlanningData.messageid eq (interaction.message.id.value.toLong()) and ( MatchPlanningData.messageid eq (interaction.message.id.value.toString()) and (
MatchPlanningData.serverid eq (guild.id.value.toLong())) and ( MatchPlanningData.serverid eq (guild.id.value.toString())) and (
MatchPlanningData.channelid eq (interaction.channelId.value.toLong())) MatchPlanningData.channelid eq (interaction.channelId.value.toString()))
}) { }) {
mpdd = MatchPlanningDataData( mpdd = MatchPlanningDataData(
pnr[MatchPlanningData.id], pnr[MatchPlanningData.id].value,
pnr[MatchPlanningData.serverid], pnr[MatchPlanningData.serverid],
pnr[MatchPlanningData.channelid], pnr[MatchPlanningData.channelid],
pnr[MatchPlanningData.matchtype], pnr[MatchPlanningData.matchtype],

View file

@ -50,12 +50,12 @@ class CancelEditButton : IEditButton {
var found = false var found = false
transaction { transaction {
for (pnr in MatchPlanningData.select { for (pnr in MatchPlanningData.select {
MatchPlanningData.messageid eq (interaction.message.id.value.toLong()) and ( MatchPlanningData.messageid eq (interaction.message.id.value.toString()) and (
MatchPlanningData.serverid eq (guild.id.value.toLong())) and ( MatchPlanningData.serverid eq (guild.id.value.toString())) and (
MatchPlanningData.channelid eq (interaction.channelId.value.toLong())) MatchPlanningData.channelid eq (interaction.channelId.value.toString()))
}) { }) {
mpdd = MatchPlanningDataData( mpdd = MatchPlanningDataData(
pnr[MatchPlanningData.id], pnr[MatchPlanningData.id].value,
pnr[MatchPlanningData.serverid], pnr[MatchPlanningData.serverid],
pnr[MatchPlanningData.channelid], pnr[MatchPlanningData.channelid],
pnr[MatchPlanningData.matchtype], pnr[MatchPlanningData.matchtype],

View file

@ -53,12 +53,12 @@ class DeclineEditButton : IEditButton {
var found = false var found = false
transaction { transaction {
for (pnr in MatchPlanningData.select { for (pnr in MatchPlanningData.select {
MatchPlanningData.messageid eq (interaction.message.id.value.toLong()) and ( MatchPlanningData.messageid eq (interaction.message.id.value.toString()) and (
MatchPlanningData.serverid eq (guild.id.value.toLong())) and ( MatchPlanningData.serverid eq (guild.id.value.toString())) and (
MatchPlanningData.channelid eq (interaction.channelId.value.toLong())) MatchPlanningData.channelid eq (interaction.channelId.value.toString()))
}) { }) {
mpdd = MatchPlanningDataData( mpdd = MatchPlanningDataData(
pnr[MatchPlanningData.id], pnr[MatchPlanningData.id].value,
pnr[MatchPlanningData.serverid], pnr[MatchPlanningData.serverid],
pnr[MatchPlanningData.channelid], pnr[MatchPlanningData.channelid],
pnr[MatchPlanningData.matchtype], pnr[MatchPlanningData.matchtype],

View file

@ -19,16 +19,9 @@
package net.moonleay.lilJudd.data package net.moonleay.lilJudd.data
import net.moonleay.lilJudd.data.tables.MatchPlanningData
import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles
import net.moonleay.lilJudd.data.tables.TimePlanningChannels
import net.moonleay.lilJudd.data.tables.TimePlanningMessages
import org.jetbrains.exposed.sql.Database import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.SchemaUtils
import org.jetbrains.exposed.sql.transactions.transaction
object DB { object DB {
private var connected = false
//Connect to the provided DB; trows errors, if the DB is not avalible. //Connect to the provided DB; trows errors, if the DB is not avalible.
fun connect(dbDomain: String, dbName: String, dbUser: String, dbPasswd: String) { fun connect(dbDomain: String, dbName: String, dbUser: String, dbPasswd: String) {
Database.connect( Database.connect(
@ -37,18 +30,5 @@ object DB {
user = dbUser, user = dbUser,
password = dbPasswd password = dbPasswd
) )
connected = true
}
fun register() {
if (!connected)
return
// Register tables here
transaction {
SchemaUtils.create(TimePlanningChannels)
SchemaUtils.create(TimePlanningMessages)
SchemaUtils.create(MatchPlanningData)
SchemaUtils.create(PlanningNotifierRoles)
}
} }
} }

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: String,
val channelid: Long, val channelid: String,
val matchtype: String, val matchtype: String,
val registererid: Long, val registererid: String,
val roleid: Long, val roleid: String,
val opponentname: String, val opponentname: String,
val messageid: Long, val messageid: String,
val timestamp: Long, val timestamp: String,
val jobstr: String val jobstr: String
) )

View file

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

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: String, // The discord server id
val channelid: Long, // The discord channel id val channelid: String, // The discord channel id
val weekstamp: Long, // The timestamp of the monday of the week at 4am UTC val weekstamp: String, // 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

@ -18,17 +18,16 @@
package net.moonleay.lilJudd.data.tables package net.moonleay.lilJudd.data.tables
import org.jetbrains.exposed.sql.Table import org.jetbrains.exposed.dao.id.IntIdTable
object MatchPlanningData : Table(name = "new_matchplanning_data") { object MatchPlanningData : IntIdTable() {
var id = integer("id").autoIncrement() var serverid = varchar("serverid", 50)
var serverid = long("serverid") var channelid = varchar("channelid", 50)
var channelid = long("channelid")
var matchtype = varchar("matchtype", 50) var matchtype = varchar("matchtype", 50)
var registererid = long("registererid") var registererid = varchar("registererid", 50)
var roleid = long("roleid") var roleid = varchar("roleid", 50)
var opponentName = varchar("opponentname", 100) var opponentName = varchar("opponentname", 100)
var messageid = long("messageid") var messageid = varchar("messageid", 50)
var timestamp = long("timestamp") var timestamp = varchar("timestamp", 50)
var jobstr = varchar("jobstr", 50) var jobstr = varchar("jobstr", 50)
} }

View file

@ -18,12 +18,11 @@
package net.moonleay.lilJudd.data.tables package net.moonleay.lilJudd.data.tables
import org.jetbrains.exposed.sql.Table import org.jetbrains.exposed.dao.id.IntIdTable
object PlanningNotifierRoles : Table(name = "new_planningnotifier_roles") { object PlanningNotifierRoles : IntIdTable() {
var id = integer("id").autoIncrement() var serverid = varchar("serverid", 50)
var serverid = long("serverid") var channelid = varchar("channelid", 50)
var channelid = long("channelid") var hastimeroleid = varchar("hastimeroleid", 50)
var hastimeroleid = long("hastimeroleid") var wantstobenotifiedid = varchar("wantstobenotifiedid", 50)
var wantstobenotifiedid = long("wantstobenotifiedid")
} }

View file

@ -18,11 +18,9 @@
package net.moonleay.lilJudd.data.tables package net.moonleay.lilJudd.data.tables
import org.jetbrains.exposed.sql.Table import org.jetbrains.exposed.dao.id.IntIdTable
object TimePlanningChannels : IntIdTable() {
object TimePlanningChannels : Table(name = "new_timeplanning_channels") { var serverid = varchar("serverid", 50)
var id = integer("id").autoIncrement() val channelid = varchar("channelid", 50)
var serverid = long("serverid")
val channelid = long("channelid")
} }

View file

@ -18,12 +18,11 @@
package net.moonleay.lilJudd.data.tables package net.moonleay.lilJudd.data.tables
import org.jetbrains.exposed.sql.Table import org.jetbrains.exposed.dao.id.IntIdTable
object TimePlanningMessages : Table(name = "new_timeplanning_messages") { object TimePlanningMessages : IntIdTable() {
var id = integer("id").autoIncrement() var serverid = varchar("serverid", 50)
var serverid = long("serverid") var channelid = varchar("channelid", 50)
var channelid = long("channelid") var weekstamp = varchar("weekstamp", 50)
var weekstamp = long("weekstamp")
var messageids = varchar("messageids", 200) var messageids = varchar("messageids", 200)
} }

View file

@ -60,8 +60,8 @@ class FeatureManageExtension : Extension() {
} }
return@action return@action
} }
val gID = this.guild!!.id.value.toLong() val gID = this.guild!!.id.toString()
val cID = this.arguments.channel.id.value.toLong() val cID = this.arguments.channel.id.toString()
val channel = this.arguments.channel val channel = this.arguments.channel
val args = this.arguments val args = this.arguments
Logger.out("${args.feature.readableName} ${args.setStatus.readableName} ${channel.data.name.value}") Logger.out("${args.feature.readableName} ${args.setStatus.readableName} ${channel.data.name.value}")

View file

@ -36,9 +36,9 @@ import net.moonleay.lilJudd.jobs.component.JobManager
import net.moonleay.lilJudd.util.EmbedUtil import net.moonleay.lilJudd.util.EmbedUtil
import net.moonleay.lilJudd.util.MessageUtil import net.moonleay.lilJudd.util.MessageUtil
import net.moonleay.lilJudd.util.TimeUtil import net.moonleay.lilJudd.util.TimeUtil
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
import kotlin.properties.Delegates
class MatchExtension : Extension() { class MatchExtension : Extension() {
@ -54,8 +54,8 @@ class MatchExtension : Extension() {
this.action { this.action {
val args = this.arguments val args = this.arguments
val m = this.member!! val m = this.member!!
val gID = this.guild!!.id.value val gID = this.guild!!.id.value.toString()
val cID = this.channel.id.value val cID = this.channel.id.value.toString()
val opponent = args.opponent ?: "?" val opponent = args.opponent ?: "?"
val msg = this.respond { val msg = this.respond {
this.embeds.add( this.embeds.add(
@ -100,17 +100,17 @@ class MatchExtension : Extension() {
} }
return@action return@action
} }
var tableID by Delegates.notNull<Int>() lateinit var tableID: EntityID<Int>
transaction { transaction {
tableID = MatchPlanningData.insert { tableID = MatchPlanningData.insert {
it[MatchPlanningData.serverid] = gID.toLong() it[MatchPlanningData.serverid] = gID
it[MatchPlanningData.channelid] = cID.toLong() it[MatchPlanningData.channelid] = cID
it[MatchPlanningData.messageid] = msg.id.value.toLong() it[MatchPlanningData.messageid] = msg.id.value.toString()
it[MatchPlanningData.matchtype] = args.matchType.readableName it[MatchPlanningData.matchtype] = args.matchType.readableName
it[MatchPlanningData.roleid] = role.id.value.toLong() it[MatchPlanningData.roleid] = role.id.value.toString()
it[MatchPlanningData.registererid] = m.id.value.toLong() it[MatchPlanningData.registererid] = m.id.value.toString()
it[MatchPlanningData.opponentName] = opponent it[MatchPlanningData.opponentName] = opponent
it[MatchPlanningData.timestamp] = (zdt.toEpochSecond() * 1000) it[MatchPlanningData.timestamp] = (zdt.toEpochSecond() * 1000).toString()
it[MatchPlanningData.jobstr] = jobString it[MatchPlanningData.jobstr] = jobString
} get MatchPlanningData.id } get MatchPlanningData.id
} }
@ -120,8 +120,8 @@ class MatchExtension : Extension() {
JobManager.addJob( JobManager.addJob(
MatchJob( MatchJob(
jobString, jobString,
tableID, tableID.value,
"${args.matchType.readableName}_Vs_${opponent}_[${tableID}]-${gID}_${cID}", "${args.matchType.readableName}_Vs_${opponent}_[${tableID.value}]-${gID}_${cID}",
) )
) )
} }

View file

@ -107,9 +107,9 @@ class SendPlannerExtension : Extension() {
// Save the message ids // Save the message ids
transaction { transaction {
TimePlanningMessages.insert { TimePlanningMessages.insert {
it[TimePlanningMessages.serverid] = c.data.guildId.value?.value!!.toLong() it[TimePlanningMessages.serverid] = c.data.guildId.value.toString()
it[TimePlanningMessages.channelid] = c.id.value.toLong() it[TimePlanningMessages.channelid] = c.id.value.toString()
it[TimePlanningMessages.weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000) it[TimePlanningMessages.weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000).toString()
it[TimePlanningMessages.messageids] = msgStr it[TimePlanningMessages.messageids] = msgStr
} get TimePlanningMessages.id } get TimePlanningMessages.id
} }

View file

@ -56,11 +56,11 @@ object AvailabilityManager : IFeature {
// ChannelID, Data // ChannelID, Data
val messageMap = mutableMapOf<Snowflake, TimePlanningMessagesData>() val messageMap = mutableMapOf<Snowflake, TimePlanningMessagesData>()
// ChannelID, Data // ChannelID, Data
val roleMap = mutableMapOf<Long, PlanningNotifierRolesData>() val roleMap = mutableMapOf<String, PlanningNotifierRolesData>()
transaction { transaction {
for (pnr in TimePlanningMessages.select { for (pnr in TimePlanningMessages.select {
TimePlanningMessages.weekstamp eq (TimeUtil.getWeekStamp().toEpochSecond() * 1000) TimePlanningMessages.weekstamp eq (TimeUtil.getWeekStamp().toEpochSecond() * 1000).toString()
}) { }) {
messageMap[Snowflake(pnr[TimePlanningMessages.channelid])] = messageMap[Snowflake(pnr[TimePlanningMessages.channelid])] =
TimePlanningMessagesData( TimePlanningMessagesData(
@ -169,8 +169,8 @@ object AvailabilityManager : IFeature {
override suspend fun enable( override suspend fun enable(
u: UserBehavior, u: UserBehavior,
gID: Long, gID: String,
cID: Long, cID: String,
ch: Channel, ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder { ): EmbedBuilder {
@ -187,13 +187,13 @@ object AvailabilityManager : IFeature {
this.name = "available [${ch.data.name.value}]" this.name = "available [${ch.data.name.value}]"
this.mentionable = true this.mentionable = true
} }
val htr = hasTimeRole.id.value.toLong() val htr = hasTimeRole.id.toString()
val wantsNotifsRole = Bot.bot.kordRef.getGuildOrThrow(Snowflake(gID)).createRole { val wantsNotifsRole = Bot.bot.kordRef.getGuildOrThrow(Snowflake(gID)).createRole {
this.name = "notifications [${ch.data.name.value}]" this.name = "notifications [${ch.data.name.value}]"
this.mentionable = true this.mentionable = true
} }
val wnr = wantsNotifsRole.id.value.toLong() val wnr = wantsNotifsRole.id.toString()
// Save the role ids to db // Save the role ids to db
transaction { transaction {
@ -224,8 +224,8 @@ object AvailabilityManager : IFeature {
override suspend fun disable( override suspend fun disable(
u: UserBehavior, u: UserBehavior,
gID: Long, gID: String,
cID: Long, cID: String,
ch: Channel, ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder { ): EmbedBuilder {

View file

@ -38,7 +38,7 @@ object MatchManager {
MatchPlanningData.selectAll().forEach { MatchPlanningData.selectAll().forEach {
dataList.add( dataList.add(
MatchPlanningDataData( MatchPlanningDataData(
it[MatchPlanningData.id], it[MatchPlanningData.id].value,
it[MatchPlanningData.serverid], it[MatchPlanningData.serverid],
it[MatchPlanningData.channelid], it[MatchPlanningData.channelid],
it[MatchPlanningData.matchtype], it[MatchPlanningData.matchtype],
@ -79,9 +79,9 @@ object MatchManager {
Logger.out("Registered job for match ${data.id}...") Logger.out("Registered job for match ${data.id}...")
} }
private suspend fun removeRoleFromGuild(gid: Long, rid: Long): Boolean { private suspend fun removeRoleFromGuild(gid: String, rid: String): Boolean {
val guild = Bot.bot.kordRef.getGuildOrNull(Snowflake(gid)) ?: return false val guild = Bot.bot.kordRef.getGuildOrNull(Snowflake(gid.toLong())) ?: return false
val role = guild.getRoleOrNull(Snowflake(rid)) ?: return false val role = guild.getRoleOrNull(Snowflake(rid.toLong())) ?: return false
role.delete() role.delete()
return true return true
} }

View file

@ -151,9 +151,9 @@ object TimeManager : IFeature {
// Save the message ids // Save the message ids
transaction { transaction {
TimePlanningMessages.insert { TimePlanningMessages.insert {
it[TimePlanningMessages.serverid] = c.data.guildId.value?.value!!.toLong() it[TimePlanningMessages.serverid] = c.data.guildId.value.toString()
it[TimePlanningMessages.channelid] = c.id.value.toLong() it[TimePlanningMessages.channelid] = c.id.value.toString()
it[TimePlanningMessages.weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000) it[TimePlanningMessages.weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000).toString()
it[TimePlanningMessages.messageids] = msgStr it[TimePlanningMessages.messageids] = msgStr
} get TimePlanningMessages.id } get TimePlanningMessages.id
} }
@ -164,8 +164,8 @@ object TimeManager : IFeature {
override suspend fun enable( override suspend fun enable(
u: UserBehavior, u: UserBehavior,
gID: Long, gID: String,
cID: Long, cID: String,
ch: Channel, ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder { ): EmbedBuilder {
@ -200,8 +200,8 @@ object TimeManager : IFeature {
override suspend fun disable( override suspend fun disable(
u: UserBehavior, u: UserBehavior,
gID: Long, gID: String,
cID: Long, cID: String,
ch: Channel, ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder { ): EmbedBuilder {

View file

@ -29,16 +29,16 @@ interface IFeature {
suspend fun enable( suspend fun enable(
u: UserBehavior, u: UserBehavior,
gID: Long, gID: String,
cID: Long, cID: String,
ch: Channel, ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder ): EmbedBuilder
suspend fun disable( suspend fun disable(
u: UserBehavior, u: UserBehavior,
gID: Long, gID: String,
cID: Long, cID: String,
ch: Channel, ch: Channel,
args: FeatureManageExtension.FeatureManagerArgs args: FeatureManageExtension.FeatureManagerArgs
): EmbedBuilder ): EmbedBuilder

View file

@ -54,7 +54,7 @@ class MatchJob(
MatchPlanningData.id eq (tableId) MatchPlanningData.id eq (tableId)
}) { }) {
mpdd = MatchPlanningDataData( mpdd = MatchPlanningDataData(
pnr[MatchPlanningData.id], pnr[MatchPlanningData.id].value,
pnr[MatchPlanningData.serverid], pnr[MatchPlanningData.serverid],
pnr[MatchPlanningData.channelid], pnr[MatchPlanningData.channelid],
pnr[MatchPlanningData.matchtype], pnr[MatchPlanningData.matchtype],