Skip to content

Commit

Permalink
Change Event Log dashboard page, allow sending a specific event log t…
Browse files Browse the repository at this point in the history
…ype to a different channel
  • Loading branch information
MrPowerGamerBR committed May 18, 2024
1 parent 74d0577 commit a7576fc
Show file tree
Hide file tree
Showing 65 changed files with 2,454 additions and 1,292 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,15 @@ class EventLogConfig(id: EntityID<Long>) : Entity<Long>(id) {
var voiceChannelJoins by EventLogConfigs.voiceChannelJoins
var voiceChannelLeaves by EventLogConfigs.voiceChannelLeaves
var avatarChanges by EventLogConfigs.avatarChanges

var memberBannedLogChannelId by EventLogConfigs.memberBannedLogChannelId
var memberUnbannedLogChannelId by EventLogConfigs.memberUnbannedLogChannelId
var messageEditedLogChannelId by EventLogConfigs.messageEditedLogChannelId
var messageDeletedLogChannelId by EventLogConfigs.messageDeletedLogChannelId
var nicknameChangesLogChannelId by EventLogConfigs.nicknameChangesLogChannelId
var voiceChannelJoinsLogChannelId by EventLogConfigs.voiceChannelJoinsLogChannelId
var voiceChannelLeavesLogChannelId by EventLogConfigs.voiceChannelLeavesLogChannelId
var avatarChangesLogChannelId by EventLogConfigs.avatarChangesLogChannelId

var updatedAt by EventLogConfigs.updatedAt
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ object DefaultRoutes {
ConfigureDailyMultiplierRoute(loritta),
ConfigureEconomyRoute(loritta),
ConfigureEventLogRoute(loritta),
PostConfigureEventLogRoute(loritta),
ConfigureInviteBlockerRoute(loritta),
ConfigureLevelUpRoute(loritta),
ConfigureTwitchRoute(loritta),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import mu.KotlinLogging
import net.perfectdreams.loritta.morenitta.LorittaBot
import net.perfectdreams.loritta.morenitta.website.routes.LocalizedRoute
import net.perfectdreams.loritta.morenitta.website.rpc.processors.Processors
import net.perfectdreams.loritta.morenitta.website.utils.SVGIconManager
import net.perfectdreams.loritta.morenitta.website.utils.WebsiteUtils
import net.perfectdreams.loritta.morenitta.website.utils.config.types.*
import net.perfectdreams.loritta.morenitta.website.utils.extensions.*
Expand Down Expand Up @@ -106,6 +107,7 @@ class LorittaWebsite(

val pathCache = ConcurrentHashMap<File, Any>()
var config = WebsiteConfig(loritta)
val svgIconManager = SVGIconManager(this)
lateinit var server: CIOApplicationEngine
private val typesToCache = listOf(
ContentType.Text.CSS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package net.perfectdreams.loritta.morenitta.website.components

import kotlinx.html.*
import kotlinx.html.stream.createHTML
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import net.dv8tion.jda.api.entities.channel.ChannelType
import net.dv8tion.jda.api.entities.channel.attribute.ICategorizableChannel
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel
import net.perfectdreams.i18nhelper.core.I18nContext
import net.perfectdreams.loritta.i18n.I18nKeysData
import net.perfectdreams.loritta.morenitta.website.LorittaWebsite
import net.perfectdreams.loritta.morenitta.website.components.SVGIcon.svgIcon
import net.perfectdreams.loritta.morenitta.website.utils.EmbeddedSpicyModalUtils
import net.perfectdreams.loritta.morenitta.website.utils.EmbeddedSpicyModalUtils.defaultModalCloseButton
import net.perfectdreams.loritta.serializable.EmbeddedSpicyModal

object DiscordChannelSelectMenu {
fun FlowContent.discordChannelSelectMenu(
lorittaWebsite: LorittaWebsite,
i18nContext: I18nContext,
name: String,
channels: List<GuildChannel>,
selectedChannelId: Long?,
nullOption: (SPAN.() -> (Unit))?
) {
select {
this.name = name
attributes["loritta-select-menu"] = "true"
style = "width: 100%;"

if (nullOption != null) {
option {
value = ""
attributes["loritta-select-menu-text"] = createHTML()
.span {
nullOption.invoke(this)
}

if (selectedChannelId == null)
selected = true

text("")
}
}

for (channel in channels) {
val hasPermissionToTalk = if (channel is GuildMessageChannel)
channel.canTalk()
else
false

option {
if (!hasPermissionToTalk) {
// Can't talk on this channel! Disable the option and show a modal when selecting the channel
disabled = true
attributes["loritta-select-menu-open-embedded-modal-on-select"] =
EmbeddedSpicyModalUtils.encodeURIComponent(
Json.encodeToString(
EmbeddedSpicyModal(
i18nContext.get(I18nKeysData.Website.Dashboard.ChannelNoTalkPermissionModal.Title),
true,
createHTML()
.div {
for (line in i18nContext.get(I18nKeysData.Website.Dashboard.ChannelNoTalkPermissionModal.Description)) {
p {
text(line)
}
}
},
listOf(
createHTML()
.button(classes = "discord-button") {
defaultModalCloseButton(i18nContext)
}
)
)
)
)
}

attributes["loritta-select-menu-text"] = createHTML()
.div(classes = "text-with-icon-wrapper") {
when (channel.type) {
ChannelType.TEXT -> svgIcon(lorittaWebsite.svgIconManager.discordTextChannel, "text-icon")
ChannelType.NEWS -> svgIcon(lorittaWebsite.svgIconManager.discordNewsChannel, "text-icon")
else -> svgIcon(lorittaWebsite.svgIconManager.discordTextChannel, "text-icon")
}
div {
text(channel.name)

if (channel is ICategorizableChannel) {
val parentCategory = channel.parentCategory
if (parentCategory != null) {
text(" ")
span {
style = "font-size: 0.8em; font-weight: bold;"
text(parentCategory.name.uppercase())
}
}
}

if (!hasPermissionToTalk) {
text(" ")
span(classes = "tag warn") {
text(i18nContext.get(I18nKeysData.Website.Dashboard.ChannelNoTalkPermissionModal.Title))
}
}
}
}

value = channel.idLong.toString()
if (channel.idLong == selectedChannelId) {
selected = true
}
text("#${channel.name} (${channel.idLong})")
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package net.perfectdreams.loritta.morenitta.website.components

import kotlinx.html.*
import java.util.*

object DiscordLikeToggles {
fun FlowContent.discordToggle(
checkboxName: String,
title: String,
description: String?,
checked: Boolean,
inputBehavior: INPUT.() -> (Unit)
) {
discordToggle(
"${UUID.randomUUID()}-toggle",
checkboxName,
title,
description,
checked,
inputBehavior
)
}

fun FlowContent.discordToggle(
checkboxId: String,
checkboxName: String,
title: String,
description: String?,
checked: Boolean,
inputBehavior: INPUT.() -> (Unit)
) {
label(classes = "toggle-wrapper") {
htmlFor = checkboxId
div(classes = "toggle-information") {
div(classes = "toggle-title") {
text(title)
}

if (description != null) {
div(classes = "toggle-description") {
text(description)
}
}
}
div {
input {
id = checkboxId
name = checkboxName
type = InputType.checkBox
this.checked = checked
inputBehavior.invoke(this)
}

div(classes = "switch-slider round") {}
}
}
}

fun FlowContent.toggleableSection(
checkboxName: String,
title: String,
description: String?,
checked: Boolean,
content: DIV.() -> (Unit)
) {
toggleableSection(
"${UUID.randomUUID()}-toggle",
checkboxName,
title,
description,
checked,
content
)
}

fun FlowContent.toggleableSection(
checkboxId: String,
checkboxName: String,
title: String,
description: String?,
checked: Boolean,
content: DIV.() -> (Unit)
) {
div(classes = "toggleable-section") {
if (checked)
classes += "is-open"

div(classes = "toggleable-selection") {
discordToggle(
checkboxId,
checkboxName,
title,
description,
checked
) {
// TODO - htmx-adventures: Cancel toggle until the page is fully loaded? (after hyperscript is loaded)
// or maybe use a init block
attributes["_"] = """
init
if me.checked
add .is-open to the closest .toggleable-section
else
remove .is-open from the closest .toggleable-section
end
end
on change
if me.checked
add .is-open to the closest .toggleable-section
else
remove .is-open from the closest .toggleable-section
end
end
""".trimIndent()
}
}

div(classes = "toggleable-content") {
content.invoke(this)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.perfectdreams.loritta.morenitta.website.components

import kotlinx.html.FlowContent
import kotlinx.html.classes
import kotlinx.html.svg
import kotlinx.html.unsafe
import net.perfectdreams.loritta.morenitta.website.utils.SVGIconManager

object SVGIcon {
fun FlowContent.svgIcon(icon: SVGIconManager.SVGIcon, classes: String) {
val svgElement = icon.html.select("svg").first()

svg {
for (svgAttributes in svgElement.attributes()) {
// kotlinx.html complains when adding a xmlns to a element
if (svgAttributes.key != "xmlns") {
attributes[svgAttributes.key] = svgAttributes.value
}
}

for (clazz in classes.split(" "))
this.classes += clazz

unsafe {
raw(svgElement.html())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import net.perfectdreams.loritta.common.utils.ActionType
import net.perfectdreams.loritta.common.utils.LorittaPermission
import net.perfectdreams.loritta.morenitta.LorittaBot
import net.perfectdreams.loritta.morenitta.dao.ServerConfig
import net.perfectdreams.loritta.morenitta.dao.servers.moduleconfigs.EventLogConfig
import net.perfectdreams.loritta.morenitta.dao.servers.moduleconfigs.InviteBlockerConfig
import net.perfectdreams.loritta.morenitta.dao.servers.moduleconfigs.StarboardConfig
import net.perfectdreams.loritta.morenitta.utils.auditlog.WebAuditLogUtils
Expand Down Expand Up @@ -67,43 +66,6 @@ class PostObsoleteServerConfigRoute(loritta: LorittaBot) : RequiresAPIGuildAuthR
serverConfig.starboardConfig = newConfig
}
}
} else if (type == "event_log") {
val isEnabled = receivedPayload["isEnabled"].bool
val eventLogChannelId = receivedPayload["eventLogChannelId"].long
val memberBanned = receivedPayload["memberBanned"].bool
val memberUnbanned = receivedPayload["memberUnbanned"].bool
val messageEdited = receivedPayload["messageEdit"].bool
val messageDeleted = receivedPayload["messageDeleted"].bool
val nicknameChanges = receivedPayload["nicknameChanges"].bool
val avatarChanges = receivedPayload["avatarChanges"].bool
val voiceChannelJoins = receivedPayload["voiceChannelJoins"].bool
val voiceChannelLeaves = receivedPayload["voiceChannelLeaves"].bool

loritta.newSuspendedTransaction {
val eventLogConfig = serverConfig.eventLogConfig

if (!isEnabled) {
serverConfig.eventLogConfig = null
eventLogConfig?.delete()
} else {
val newConfig = eventLogConfig ?: EventLogConfig.new {
this.eventLogChannelId = -1
}

newConfig.enabled = isEnabled
newConfig.eventLogChannelId = eventLogChannelId
newConfig.memberBanned = memberBanned
newConfig.memberUnbanned = memberUnbanned
newConfig.messageEdited = messageEdited
newConfig.messageDeleted = messageDeleted
newConfig.nicknameChanges = nicknameChanges
newConfig.avatarChanges = avatarChanges
newConfig.voiceChannelJoins = voiceChannelJoins
newConfig.voiceChannelLeaves = voiceChannelLeaves

serverConfig.eventLogConfig = newConfig
}
}
} else if (type == "invite_blocker") {
val isEnabled = receivedPayload["isEnabled"].bool
val whitelistServerInvites = receivedPayload["whitelistServerInvites"].bool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import net.perfectdreams.loritta.morenitta.LorittaBot
import net.perfectdreams.loritta.morenitta.website.LorittaWebsite
import net.perfectdreams.loritta.morenitta.website.routes.RequiresDiscordLoginLocalizedDashboardRoute
import net.perfectdreams.loritta.morenitta.website.utils.extensions.respondHtml
import net.perfectdreams.loritta.morenitta.website.views.SelectGuildProfileDashboardView
import net.perfectdreams.loritta.morenitta.website.views.dashboard.user.SelectGuildProfileDashboardView
import net.perfectdreams.loritta.serializable.ColorTheme
import net.perfectdreams.loritta.temmiewebsession.LorittaJsonWebSession
import net.perfectdreams.temmiediscordauth.TemmieDiscordAuth
Expand All @@ -36,7 +36,7 @@ class DashboardRoute(loritta: LorittaBot) : RequiresDiscordLoginLocalizedDashboa
call.response.header("Vary", "HX-Trigger")

val view = SelectGuildProfileDashboardView(
loritta,
loritta.newWebsite!!,
i18nContext,
locale,
getPathWithoutLocale(call),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import net.perfectdreams.loritta.morenitta.LorittaBot
import net.perfectdreams.loritta.morenitta.website.routes.RequiresDiscordLoginLocalizedRoute
import net.perfectdreams.loritta.morenitta.website.utils.EmbeddedSpicyModalUtils
import net.perfectdreams.loritta.morenitta.website.utils.extensions.respondHtml
import net.perfectdreams.loritta.morenitta.website.views.SelectGuildProfileDashboardView.Companion.favoriteGuild
import net.perfectdreams.loritta.morenitta.website.views.dashboard.user.SelectGuildProfileDashboardView.Companion.favoriteGuild
import net.perfectdreams.loritta.serializable.EmbeddedSpicyToast
import net.perfectdreams.loritta.temmiewebsession.LorittaJsonWebSession
import net.perfectdreams.temmiediscordauth.TemmieDiscordAuth
Expand Down
Loading

0 comments on commit a7576fc

Please sign in to comment.