-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change Event Log dashboard page, allow sending a specific event log t…
…ype to a different channel
- Loading branch information
1 parent
74d0577
commit a7576fc
Showing
65 changed files
with
2,454 additions
and
1,292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 59 additions & 106 deletions
165
...discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/listeners/EventLogListener.kt
Large diffs are not rendered by default.
Oops, something went wrong.
287 changes: 22 additions & 265 deletions
287
...ot-discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/utils/eventlog/EventLog.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...kotlin/net/perfectdreams/loritta/morenitta/website/components/DiscordChannelSelectMenu.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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})") | ||
} | ||
} | ||
} | ||
} | ||
} |
123 changes: 123 additions & 0 deletions
123
.../main/kotlin/net/perfectdreams/loritta/morenitta/website/components/DiscordLikeToggles.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...discord/src/main/kotlin/net/perfectdreams/loritta/morenitta/website/components/SVGIcon.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.