forked from DiscordBots/lilJudd
feat: (re)added PlanningRolesFeature
fix: fixed being able to register TimePlanningFeature multiple times in the same channel chore: added comments Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
ae0d67f3fd
commit
5c488fa91d
1 changed files with 25 additions and 14 deletions
|
@ -27,16 +27,16 @@ import com.kotlindiscord.kord.extensions.types.respond
|
|||
import com.kotlindiscord.kord.extensions.utils.hasPermission
|
||||
import dev.kord.common.Color
|
||||
import dev.kord.common.entity.Permission
|
||||
import dev.kord.common.entity.Snowflake
|
||||
import dev.kord.core.behavior.createRole
|
||||
import net.moonleay.lilJudd.data.tables.PlanningNotifierRoles
|
||||
import net.moonleay.lilJudd.data.tables.TimePlanningChannels
|
||||
import net.moonleay.lilJudd.extensions.component.EnableOrDisable
|
||||
import net.moonleay.lilJudd.extensions.component.FeatureEnum
|
||||
import net.moonleay.lilJudd.features.component.FeatureEnum
|
||||
import net.moonleay.lilJudd.util.Logger
|
||||
import net.moonleay.lilJudd.util.MessageUtil
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.and
|
||||
import org.jetbrains.exposed.sql.deleteWhere
|
||||
import org.jetbrains.exposed.sql.insert
|
||||
import org.jetbrains.exposed.sql.select
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
class FeatureManageExtension : Extension() {
|
||||
|
@ -80,7 +80,7 @@ class FeatureManageExtension : Extension() {
|
|||
var alreadyExists = false
|
||||
transaction {
|
||||
alreadyExists = TimePlanningChannels.select {
|
||||
(TimePlanningChannels.channelid eq gID) and
|
||||
(TimePlanningChannels.serverid eq gID) and
|
||||
(TimePlanningChannels.channelid eq cID)
|
||||
}.count() > 0
|
||||
}
|
||||
|
@ -116,9 +116,9 @@ class FeatureManageExtension : Extension() {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
FeatureEnum.PLANNINGNOTIFIER -> {
|
||||
FeatureEnum.PLANNINGROLES -> {
|
||||
var alreadyExists = false
|
||||
// Check if the channel and guild already exist in the db
|
||||
transaction {
|
||||
alreadyExists = PlanningNotifierRoles.select {
|
||||
(PlanningNotifierRoles.serverid eq gID) and (PlanningNotifierRoles.channelid eq cID)
|
||||
|
@ -126,6 +126,7 @@ class FeatureManageExtension : Extension() {
|
|||
}
|
||||
if (!alreadyExists) {
|
||||
|
||||
// Create the roles in Discord
|
||||
val hasTimeRole = this.guild!!.createRole {
|
||||
this.name = "available [${channel.data.name.value}]"
|
||||
this.mentionable = true
|
||||
|
@ -138,12 +139,13 @@ class FeatureManageExtension : Extension() {
|
|||
}
|
||||
val wnr = wantsNotifsRole.id.toString()
|
||||
|
||||
// Save the role ids to db
|
||||
transaction {
|
||||
PlanningNotifierRoles.insert {
|
||||
it[PlanningNotifierRoles.serverid] = gID
|
||||
it[PlanningNotifierRoles.channelid] = cID
|
||||
it[PlanningNotifierRoles.hastimeroleid] = htr
|
||||
it[PlanningNotifierRoles.wantstobenotifid] = wnr
|
||||
it[PlanningNotifierRoles.wantstobenotifiedid] = wnr
|
||||
} get PlanningNotifierRoles.id
|
||||
}
|
||||
|
||||
|
@ -159,6 +161,8 @@ class FeatureManageExtension : Extension() {
|
|||
}
|
||||
return@action
|
||||
}
|
||||
|
||||
// They exist, do not add them
|
||||
this.respond {
|
||||
embeds.add(
|
||||
MessageUtil.getEmbed(
|
||||
|
@ -169,13 +173,14 @@ class FeatureManageExtension : Extension() {
|
|||
)
|
||||
)
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
||||
return@action
|
||||
}
|
||||
//Disable
|
||||
when (this.arguments.feature) {
|
||||
FeatureEnum.TIMEPLANNINGFEATURE -> {
|
||||
// Check if entry exists in db
|
||||
var alreadyExists = false
|
||||
transaction {
|
||||
alreadyExists = TimePlanningChannels.select {
|
||||
|
@ -184,6 +189,7 @@ class FeatureManageExtension : Extension() {
|
|||
}.count() > 0
|
||||
}
|
||||
if (alreadyExists) {
|
||||
// delete all entrys for this channel
|
||||
transaction {
|
||||
val matchingEntries = TimePlanningChannels.select {
|
||||
(TimePlanningChannels.serverid eq gID) and
|
||||
|
@ -206,6 +212,7 @@ class FeatureManageExtension : Extension() {
|
|||
}
|
||||
return@action
|
||||
}
|
||||
// Do nothing; not in db
|
||||
this.respond {
|
||||
embeds.add(
|
||||
MessageUtil.getEmbed(
|
||||
|
@ -218,8 +225,9 @@ class FeatureManageExtension : Extension() {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
FeatureEnum.PLANNINGNOTIFIER -> {
|
||||
|
||||
FeatureEnum.PLANNINGROLES -> {
|
||||
// Check if entry exists in db
|
||||
var alreadyExists = false
|
||||
transaction {
|
||||
alreadyExists = PlanningNotifierRoles.select {
|
||||
|
@ -234,12 +242,14 @@ class FeatureManageExtension : Extension() {
|
|||
(PlanningNotifierRoles.channelid eq cID)
|
||||
}.toList()
|
||||
}
|
||||
// delete all entries for this guild and channel combo
|
||||
for (e in matchingEntries) {
|
||||
this.guild!!.getRoleOrNull(Snowflake(e[PlanningNotifierRoles.hastimeroleid]))?.delete()
|
||||
this.guild!!.getRoleOrNull(Snowflake(e[PlanningNotifierRoles.wantstobenotifid]))
|
||||
this.guild!!.getRoleOrNull(Snowflake(e[PlanningNotifierRoles.wantstobenotifiedid]))
|
||||
?.delete()
|
||||
}
|
||||
|
||||
// delete all found entries
|
||||
transaction {
|
||||
matchingEntries.forEach { entry ->
|
||||
PlanningNotifierRoles.deleteWhere { id eq entry[id] }
|
||||
|
@ -257,6 +267,7 @@ class FeatureManageExtension : Extension() {
|
|||
}
|
||||
return@action
|
||||
}
|
||||
// not in db, do nothing
|
||||
this.respond {
|
||||
embeds.add(
|
||||
MessageUtil.getEmbed(
|
||||
|
@ -267,7 +278,7 @@ class FeatureManageExtension : Extension() {
|
|||
)
|
||||
)
|
||||
}
|
||||
} */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue