Compare commits
2 commits
d97511eb8b
...
4f8924fb1a
Author | SHA1 | Date | |
---|---|---|---|
4f8924fb1a | |||
1424e31e2a |
20 changed files with 117 additions and 89 deletions
|
@ -76,6 +76,9 @@ object Bot {
|
|||
CredentialManager.dbPassword
|
||||
)
|
||||
|
||||
// Make sure the database is up-to-date
|
||||
DB.register()
|
||||
|
||||
// Register all the jobs
|
||||
jobs.addAll(
|
||||
listOf(
|
||||
|
|
|
@ -53,12 +53,12 @@ class AcceptEditButton() : IEditButton {
|
|||
var found = false
|
||||
transaction {
|
||||
for (pnr in MatchPlanningData.select {
|
||||
MatchPlanningData.messageid eq (interaction.message.id.value.toString()) and (
|
||||
MatchPlanningData.serverid eq (guild.id.value.toString())) and (
|
||||
MatchPlanningData.channelid eq (interaction.channelId.value.toString()))
|
||||
MatchPlanningData.messageid eq (interaction.message.id.value.toLong()) and (
|
||||
MatchPlanningData.serverid eq (guild.id.value.toLong())) and (
|
||||
MatchPlanningData.channelid eq (interaction.channelId.value.toLong()))
|
||||
}) {
|
||||
mpdd = MatchPlanningDataData(
|
||||
pnr[MatchPlanningData.id].value,
|
||||
pnr[MatchPlanningData.id],
|
||||
pnr[MatchPlanningData.serverid],
|
||||
pnr[MatchPlanningData.channelid],
|
||||
pnr[MatchPlanningData.matchtype],
|
||||
|
|
|
@ -50,12 +50,12 @@ class CancelEditButton : IEditButton {
|
|||
var found = false
|
||||
transaction {
|
||||
for (pnr in MatchPlanningData.select {
|
||||
MatchPlanningData.messageid eq (interaction.message.id.value.toString()) and (
|
||||
MatchPlanningData.serverid eq (guild.id.value.toString())) and (
|
||||
MatchPlanningData.channelid eq (interaction.channelId.value.toString()))
|
||||
MatchPlanningData.messageid eq (interaction.message.id.value.toLong()) and (
|
||||
MatchPlanningData.serverid eq (guild.id.value.toLong())) and (
|
||||
MatchPlanningData.channelid eq (interaction.channelId.value.toLong()))
|
||||
}) {
|
||||
mpdd = MatchPlanningDataData(
|
||||
pnr[MatchPlanningData.id].value,
|
||||
pnr[MatchPlanningData.id],
|
||||
pnr[MatchPlanningData.serverid],
|
||||
pnr[MatchPlanningData.channelid],
|
||||
pnr[MatchPlanningData.matchtype],
|
||||
|
|
|
@ -53,12 +53,12 @@ class DeclineEditButton : IEditButton {
|
|||
var found = false
|
||||
transaction {
|
||||
for (pnr in MatchPlanningData.select {
|
||||
MatchPlanningData.messageid eq (interaction.message.id.value.toString()) and (
|
||||
MatchPlanningData.serverid eq (guild.id.value.toString())) and (
|
||||
MatchPlanningData.channelid eq (interaction.channelId.value.toString()))
|
||||
MatchPlanningData.messageid eq (interaction.message.id.value.toLong()) and (
|
||||
MatchPlanningData.serverid eq (guild.id.value.toLong())) and (
|
||||
MatchPlanningData.channelid eq (interaction.channelId.value.toLong()))
|
||||
}) {
|
||||
mpdd = MatchPlanningDataData(
|
||||
pnr[MatchPlanningData.id].value,
|
||||
pnr[MatchPlanningData.id],
|
||||
pnr[MatchPlanningData.serverid],
|
||||
pnr[MatchPlanningData.channelid],
|
||||
pnr[MatchPlanningData.matchtype],
|
||||
|
|
|
@ -19,9 +19,16 @@
|
|||
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.SchemaUtils
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
object DB {
|
||||
private var connected = false
|
||||
//Connect to the provided DB; trows errors, if the DB is not avalible.
|
||||
fun connect(dbDomain: String, dbName: String, dbUser: String, dbPasswd: String) {
|
||||
Database.connect(
|
||||
|
@ -30,5 +37,18 @@ object DB {
|
|||
user = dbUser,
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,13 +20,13 @@ package net.moonleay.lilJudd.data.entry
|
|||
|
||||
data class MatchPlanningDataData(
|
||||
val id: Int,
|
||||
val serverid: String,
|
||||
val channelid: String,
|
||||
val serverid: Long,
|
||||
val channelid: Long,
|
||||
val matchtype: String,
|
||||
val registererid: String,
|
||||
val roleid: String,
|
||||
val registererid: Long,
|
||||
val roleid: Long,
|
||||
val opponentname: String,
|
||||
val messageid: String,
|
||||
val timestamp: String,
|
||||
val messageid: Long,
|
||||
val timestamp: Long,
|
||||
val jobstr: String
|
||||
)
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
package net.moonleay.lilJudd.data.entry
|
||||
|
||||
data class PlanningNotifierRolesData(
|
||||
val serverID: String, // The id of the server
|
||||
val channelId: String, // The id of the channel
|
||||
val hastimeroleid: String, // The id of the role that has time today
|
||||
val wantstobenotifid: String // The id of the role that wants to be notified
|
||||
val serverID: Long, // The id of the server
|
||||
val channelId: Long, // The id of the channel
|
||||
val hastimeroleid: Long, // The id of the role that has time today
|
||||
val wantstobenotifid: Long // The id of the role that wants to be notified
|
||||
)
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
package net.moonleay.lilJudd.data.entry
|
||||
|
||||
data class TimePlanningMessagesData(
|
||||
val serverid: String, // The discord server id
|
||||
val channelid: String, // The discord channel id
|
||||
val weekstamp: String, // The timestamp of the monday of the week at 4am UTC
|
||||
val serverid: Long, // The discord server id
|
||||
val channelid: Long, // The discord channel id
|
||||
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.]"
|
||||
)
|
||||
|
|
|
@ -18,16 +18,17 @@
|
|||
|
||||
package net.moonleay.lilJudd.data.tables
|
||||
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.sql.Table
|
||||
|
||||
object MatchPlanningData : IntIdTable() {
|
||||
var serverid = varchar("serverid", 50)
|
||||
var channelid = varchar("channelid", 50)
|
||||
object MatchPlanningData : Table(name = "new_matchplanning_data") {
|
||||
var id = integer("id").autoIncrement()
|
||||
var serverid = long("serverid")
|
||||
var channelid = long("channelid")
|
||||
var matchtype = varchar("matchtype", 50)
|
||||
var registererid = varchar("registererid", 50)
|
||||
var roleid = varchar("roleid", 50)
|
||||
var registererid = long("registererid")
|
||||
var roleid = long("roleid")
|
||||
var opponentName = varchar("opponentname", 100)
|
||||
var messageid = varchar("messageid", 50)
|
||||
var timestamp = varchar("timestamp", 50)
|
||||
var messageid = long("messageid")
|
||||
var timestamp = long("timestamp")
|
||||
var jobstr = varchar("jobstr", 50)
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
|
||||
package net.moonleay.lilJudd.data.tables
|
||||
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.sql.Table
|
||||
|
||||
object PlanningNotifierRoles : IntIdTable() {
|
||||
var serverid = varchar("serverid", 50)
|
||||
var channelid = varchar("channelid", 50)
|
||||
var hastimeroleid = varchar("hastimeroleid", 50)
|
||||
var wantstobenotifiedid = varchar("wantstobenotifiedid", 50)
|
||||
object PlanningNotifierRoles : Table(name = "new_planningnotifier_roles") {
|
||||
var id = integer("id").autoIncrement()
|
||||
var serverid = long("serverid")
|
||||
var channelid = long("channelid")
|
||||
var hastimeroleid = long("hastimeroleid")
|
||||
var wantstobenotifiedid = long("wantstobenotifiedid")
|
||||
}
|
||||
|
|
|
@ -18,9 +18,11 @@
|
|||
|
||||
package net.moonleay.lilJudd.data.tables
|
||||
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.sql.Table
|
||||
|
||||
object TimePlanningChannels : IntIdTable() {
|
||||
var serverid = varchar("serverid", 50)
|
||||
val channelid = varchar("channelid", 50)
|
||||
|
||||
object TimePlanningChannels : Table(name = "new_timeplanning_channels") {
|
||||
var id = integer("id").autoIncrement()
|
||||
var serverid = long("serverid")
|
||||
val channelid = long("channelid")
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
|
||||
package net.moonleay.lilJudd.data.tables
|
||||
|
||||
import org.jetbrains.exposed.dao.id.IntIdTable
|
||||
import org.jetbrains.exposed.sql.Table
|
||||
|
||||
object TimePlanningMessages : IntIdTable() {
|
||||
var serverid = varchar("serverid", 50)
|
||||
var channelid = varchar("channelid", 50)
|
||||
var weekstamp = varchar("weekstamp", 50)
|
||||
object TimePlanningMessages : Table(name = "new_timeplanning_messages") {
|
||||
var id = integer("id").autoIncrement()
|
||||
var serverid = long("serverid")
|
||||
var channelid = long("channelid")
|
||||
var weekstamp = long("weekstamp")
|
||||
var messageids = varchar("messageids", 200)
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ class FeatureManageExtension : Extension() {
|
|||
}
|
||||
return@action
|
||||
}
|
||||
val gID = this.guild!!.id.toString()
|
||||
val cID = this.arguments.channel.id.toString()
|
||||
val gID = this.guild!!.id.value.toLong()
|
||||
val cID = this.arguments.channel.id.value.toLong()
|
||||
val channel = this.arguments.channel
|
||||
val args = this.arguments
|
||||
Logger.out("${args.feature.readableName} ${args.setStatus.readableName} ${channel.data.name.value}")
|
||||
|
|
|
@ -36,9 +36,9 @@ import net.moonleay.lilJudd.jobs.component.JobManager
|
|||
import net.moonleay.lilJudd.util.EmbedUtil
|
||||
import net.moonleay.lilJudd.util.MessageUtil
|
||||
import net.moonleay.lilJudd.util.TimeUtil
|
||||
import org.jetbrains.exposed.dao.id.EntityID
|
||||
import org.jetbrains.exposed.sql.insert
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class MatchExtension : Extension() {
|
||||
|
||||
|
@ -54,8 +54,8 @@ class MatchExtension : Extension() {
|
|||
this.action {
|
||||
val args = this.arguments
|
||||
val m = this.member!!
|
||||
val gID = this.guild!!.id.value.toString()
|
||||
val cID = this.channel.id.value.toString()
|
||||
val gID = this.guild!!.id.value
|
||||
val cID = this.channel.id.value
|
||||
val opponent = args.opponent ?: "?"
|
||||
val msg = this.respond {
|
||||
this.embeds.add(
|
||||
|
@ -100,17 +100,17 @@ class MatchExtension : Extension() {
|
|||
}
|
||||
return@action
|
||||
}
|
||||
lateinit var tableID: EntityID<Int>
|
||||
var tableID by Delegates.notNull<Int>()
|
||||
transaction {
|
||||
tableID = MatchPlanningData.insert {
|
||||
it[MatchPlanningData.serverid] = gID
|
||||
it[MatchPlanningData.channelid] = cID
|
||||
it[MatchPlanningData.messageid] = msg.id.value.toString()
|
||||
it[MatchPlanningData.serverid] = gID.toLong()
|
||||
it[MatchPlanningData.channelid] = cID.toLong()
|
||||
it[MatchPlanningData.messageid] = msg.id.value.toLong()
|
||||
it[MatchPlanningData.matchtype] = args.matchType.readableName
|
||||
it[MatchPlanningData.roleid] = role.id.value.toString()
|
||||
it[MatchPlanningData.registererid] = m.id.value.toString()
|
||||
it[MatchPlanningData.roleid] = role.id.value.toLong()
|
||||
it[MatchPlanningData.registererid] = m.id.value.toLong()
|
||||
it[MatchPlanningData.opponentName] = opponent
|
||||
it[MatchPlanningData.timestamp] = (zdt.toEpochSecond() * 1000).toString()
|
||||
it[MatchPlanningData.timestamp] = (zdt.toEpochSecond() * 1000)
|
||||
it[MatchPlanningData.jobstr] = jobString
|
||||
} get MatchPlanningData.id
|
||||
}
|
||||
|
@ -120,8 +120,8 @@ class MatchExtension : Extension() {
|
|||
JobManager.addJob(
|
||||
MatchJob(
|
||||
jobString,
|
||||
tableID.value,
|
||||
"${args.matchType.readableName}_Vs_${opponent}_[${tableID.value}]-${gID}_${cID}",
|
||||
tableID,
|
||||
"${args.matchType.readableName}_Vs_${opponent}_[${tableID}]-${gID}_${cID}",
|
||||
)
|
||||
)
|
||||
}
|
||||
|
|
|
@ -107,9 +107,9 @@ class SendPlannerExtension : Extension() {
|
|||
// Save the message ids
|
||||
transaction {
|
||||
TimePlanningMessages.insert {
|
||||
it[TimePlanningMessages.serverid] = c.data.guildId.value.toString()
|
||||
it[TimePlanningMessages.channelid] = c.id.value.toString()
|
||||
it[TimePlanningMessages.weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000).toString()
|
||||
it[TimePlanningMessages.serverid] = c.data.guildId.value?.value!!.toLong()
|
||||
it[TimePlanningMessages.channelid] = c.id.value.toLong()
|
||||
it[TimePlanningMessages.weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000)
|
||||
it[TimePlanningMessages.messageids] = msgStr
|
||||
} get TimePlanningMessages.id
|
||||
}
|
||||
|
|
|
@ -56,11 +56,11 @@ object AvailabilityManager : IFeature {
|
|||
// ChannelID, Data
|
||||
val messageMap = mutableMapOf<Snowflake, TimePlanningMessagesData>()
|
||||
// ChannelID, Data
|
||||
val roleMap = mutableMapOf<String, PlanningNotifierRolesData>()
|
||||
val roleMap = mutableMapOf<Long, PlanningNotifierRolesData>()
|
||||
|
||||
transaction {
|
||||
for (pnr in TimePlanningMessages.select {
|
||||
TimePlanningMessages.weekstamp eq (TimeUtil.getWeekStamp().toEpochSecond() * 1000).toString()
|
||||
TimePlanningMessages.weekstamp eq (TimeUtil.getWeekStamp().toEpochSecond() * 1000)
|
||||
}) {
|
||||
messageMap[Snowflake(pnr[TimePlanningMessages.channelid])] =
|
||||
TimePlanningMessagesData(
|
||||
|
@ -169,8 +169,8 @@ object AvailabilityManager : IFeature {
|
|||
|
||||
override suspend fun enable(
|
||||
u: UserBehavior,
|
||||
gID: String,
|
||||
cID: String,
|
||||
gID: Long,
|
||||
cID: Long,
|
||||
ch: Channel,
|
||||
args: FeatureManageExtension.FeatureManagerArgs
|
||||
): EmbedBuilder {
|
||||
|
@ -187,13 +187,13 @@ object AvailabilityManager : IFeature {
|
|||
this.name = "available [${ch.data.name.value}]"
|
||||
this.mentionable = true
|
||||
}
|
||||
val htr = hasTimeRole.id.toString()
|
||||
val htr = hasTimeRole.id.value.toLong()
|
||||
|
||||
val wantsNotifsRole = Bot.bot.kordRef.getGuildOrThrow(Snowflake(gID)).createRole {
|
||||
this.name = "notifications [${ch.data.name.value}]"
|
||||
this.mentionable = true
|
||||
}
|
||||
val wnr = wantsNotifsRole.id.toString()
|
||||
val wnr = wantsNotifsRole.id.value.toLong()
|
||||
|
||||
// Save the role ids to db
|
||||
transaction {
|
||||
|
@ -224,8 +224,8 @@ object AvailabilityManager : IFeature {
|
|||
|
||||
override suspend fun disable(
|
||||
u: UserBehavior,
|
||||
gID: String,
|
||||
cID: String,
|
||||
gID: Long,
|
||||
cID: Long,
|
||||
ch: Channel,
|
||||
args: FeatureManageExtension.FeatureManagerArgs
|
||||
): EmbedBuilder {
|
||||
|
|
|
@ -38,7 +38,7 @@ object MatchManager {
|
|||
MatchPlanningData.selectAll().forEach {
|
||||
dataList.add(
|
||||
MatchPlanningDataData(
|
||||
it[MatchPlanningData.id].value,
|
||||
it[MatchPlanningData.id],
|
||||
it[MatchPlanningData.serverid],
|
||||
it[MatchPlanningData.channelid],
|
||||
it[MatchPlanningData.matchtype],
|
||||
|
@ -79,9 +79,9 @@ object MatchManager {
|
|||
Logger.out("Registered job for match ${data.id}...")
|
||||
}
|
||||
|
||||
private suspend fun removeRoleFromGuild(gid: String, rid: String): Boolean {
|
||||
val guild = Bot.bot.kordRef.getGuildOrNull(Snowflake(gid.toLong())) ?: return false
|
||||
val role = guild.getRoleOrNull(Snowflake(rid.toLong())) ?: return false
|
||||
private suspend fun removeRoleFromGuild(gid: Long, rid: Long): Boolean {
|
||||
val guild = Bot.bot.kordRef.getGuildOrNull(Snowflake(gid)) ?: return false
|
||||
val role = guild.getRoleOrNull(Snowflake(rid)) ?: return false
|
||||
role.delete()
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -151,9 +151,9 @@ object TimeManager : IFeature {
|
|||
// Save the message ids
|
||||
transaction {
|
||||
TimePlanningMessages.insert {
|
||||
it[TimePlanningMessages.serverid] = c.data.guildId.value.toString()
|
||||
it[TimePlanningMessages.channelid] = c.id.value.toString()
|
||||
it[TimePlanningMessages.weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000).toString()
|
||||
it[TimePlanningMessages.serverid] = c.data.guildId.value?.value!!.toLong()
|
||||
it[TimePlanningMessages.channelid] = c.id.value.toLong()
|
||||
it[TimePlanningMessages.weekstamp] = (TimeUtil.getWeekStamp().toEpochSecond() * 1000)
|
||||
it[TimePlanningMessages.messageids] = msgStr
|
||||
} get TimePlanningMessages.id
|
||||
}
|
||||
|
@ -164,8 +164,8 @@ object TimeManager : IFeature {
|
|||
|
||||
override suspend fun enable(
|
||||
u: UserBehavior,
|
||||
gID: String,
|
||||
cID: String,
|
||||
gID: Long,
|
||||
cID: Long,
|
||||
ch: Channel,
|
||||
args: FeatureManageExtension.FeatureManagerArgs
|
||||
): EmbedBuilder {
|
||||
|
@ -200,8 +200,8 @@ object TimeManager : IFeature {
|
|||
|
||||
override suspend fun disable(
|
||||
u: UserBehavior,
|
||||
gID: String,
|
||||
cID: String,
|
||||
gID: Long,
|
||||
cID: Long,
|
||||
ch: Channel,
|
||||
args: FeatureManageExtension.FeatureManagerArgs
|
||||
): EmbedBuilder {
|
||||
|
|
|
@ -29,16 +29,16 @@ interface IFeature {
|
|||
|
||||
suspend fun enable(
|
||||
u: UserBehavior,
|
||||
gID: String,
|
||||
cID: String,
|
||||
gID: Long,
|
||||
cID: Long,
|
||||
ch: Channel,
|
||||
args: FeatureManageExtension.FeatureManagerArgs
|
||||
): EmbedBuilder
|
||||
|
||||
suspend fun disable(
|
||||
u: UserBehavior,
|
||||
gID: String,
|
||||
cID: String,
|
||||
gID: Long,
|
||||
cID: Long,
|
||||
ch: Channel,
|
||||
args: FeatureManageExtension.FeatureManagerArgs
|
||||
): EmbedBuilder
|
||||
|
|
|
@ -54,7 +54,7 @@ class MatchJob(
|
|||
MatchPlanningData.id eq (tableId)
|
||||
}) {
|
||||
mpdd = MatchPlanningDataData(
|
||||
pnr[MatchPlanningData.id].value,
|
||||
pnr[MatchPlanningData.id],
|
||||
pnr[MatchPlanningData.serverid],
|
||||
pnr[MatchPlanningData.channelid],
|
||||
pnr[MatchPlanningData.matchtype],
|
||||
|
|
Loading…
Reference in a new issue