Skip to content

Remade notice system (originally /ai command) #272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/main/kotlin/com/learnspigot/bot/notice/NoticeCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.learnspigot.bot.notice;

import com.learnspigot.bot.util.embed
import gg.flyte.neptune.annotation.Command;
import gg.flyte.neptune.annotation.Description
import net.dv8tion.jda.api.entities.User
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
import net.dv8tion.jda.api.interactions.components.buttons.Button

public class NoticeCommand {

@Command(
name = "notice",
description = "Notices user about something"
)
fun onNotice(
event: SlashCommandInteractionEvent,
@Description("Notifies selected user") user: User
) {
val userString = "-${user.id}";
val aiNoticeButton = Button.primary("notice-ai${userString}", "AI Notice")
val mcUtilsButton = Button.primary("notice-mcutils${userString}", "MCUtils")
val pastebinButton = Button.primary("notice-pastebin${userString}", "Pastebin")

event.replyEmbeds(embed()
.setTitle("What do you want to notice about?")
.setDescription("Select what has the user done to notice them about it.")
.build()
).setActionRow(
aiNoticeButton, mcUtilsButton, pastebinButton
).queue()
}
}
52 changes: 52 additions & 0 deletions src/main/kotlin/com/learnspigot/bot/notice/NoticeListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.learnspigot.bot.notice

import com.learnspigot.bot.notice.types.AiNotice
import com.learnspigot.bot.notice.types.McUtilsNotice
import com.learnspigot.bot.notice.types.NoticeType
import com.learnspigot.bot.notice.types.PastebinNotice
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent
import net.dv8tion.jda.api.hooks.ListenerAdapter
import net.dv8tion.jda.api.interactions.InteractionHook
import java.util.concurrent.TimeUnit

class NoticeListener : ListenerAdapter() {

private val notifyMap: Map<String, NoticeType> = mapOf(
"ai" to AiNotice(),
"mcutils" to McUtilsNotice(),
"pastebin" to PastebinNotice(),
)

override fun onButtonInteraction(event: ButtonInteractionEvent) {
var componentId = event.componentId
if (!componentId.startsWith("notice-")) return
componentId = componentId.substring("notice-".length)

val userId = componentId.substring(componentId.indexOf("-") + 1)
val hook = event.hook

if (componentId.startsWith("ai")) {
notifyUser(hook, userId, "ai")
}
else if (componentId.startsWith("mcutils")) {
notifyUser(hook, userId, "mcutils")
}
else if (componentId.startsWith("pastebin")) {
notifyUser(hook, userId, "pastebin")
}
}

private fun notifyUser(hook: InteractionHook, userId: String?, notificationType: String) {
if (userId == null) return

hook.sendMessage("<@${userId}>").queue { message ->
run {
hook.deleteMessageById(message.idLong).queueAfter(500, TimeUnit.MILLISECONDS)
}
}

val notifyType = notifyMap[notificationType] ?: return

hook.sendMessageEmbeds(notifyType.notifyEmbed(userId).build()).queue()
}
}
20 changes: 20 additions & 0 deletions src/main/kotlin/com/learnspigot/bot/notice/types/AiNotice.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.learnspigot.bot.notice.types

import com.learnspigot.bot.util.embed
import net.dv8tion.jda.api.EmbedBuilder
import java.awt.Color

class AiNotice : NoticeType {
override fun notifyEmbed(userId: String): EmbedBuilder {
return embed()
.setTitle("Artificial Intelligence")
.setDescription("" +
"While artificial intelligence has proven to be a helpful tool across various fields, " +
"using AI for coding introduces a number of significant concerns that can outweigh the benefits. " +
"One key issue is its lack of true understanding—AI can produce code that appears correct, " +
"but without grasping the underlying logic or context, which can lead developers to adopt solutions they don’t fully comprehend, " +
"making long-term maintenance and debugging more challenging. For these reasons, using AI-generated code is not recommended, " +
"and support for such code may not be provided or guaranteed.")
.setColor(Color.RED)
}
}
18 changes: 18 additions & 0 deletions src/main/kotlin/com/learnspigot/bot/notice/types/McUtilsNotice.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.learnspigot.bot.notice.types

import com.learnspigot.bot.util.embed
import net.dv8tion.jda.api.EmbedBuilder
import java.awt.Color

class McUtilsNotice : NoticeType {
override fun notifyEmbed(userId: String): EmbedBuilder {
return embed()
.setTitle("MC Utils")
.setDescription("" +
"[MC Utils](https://mcutils.com/) is a free, community-powered website that offers a wide range of tools for " +
"Minecraft players, server admins, and developers — from server jar downloads and start file " +
"generators to color text tools, banner creators, and more.")
.addField("Link", ":right: https://mcutils.com/", false)
.setColor(Color.CYAN)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.learnspigot.bot.notice.types

import net.dv8tion.jda.api.EmbedBuilder

interface NoticeType {

public fun notifyEmbed(userId: String): EmbedBuilder

}
18 changes: 18 additions & 0 deletions src/main/kotlin/com/learnspigot/bot/notice/types/PastebinNotice.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.learnspigot.bot.notice.types

import com.learnspigot.bot.util.embed
import net.dv8tion.jda.api.EmbedBuilder
import java.awt.Color

class PastebinNotice : NoticeType {
override fun notifyEmbed(userId: String): EmbedBuilder {
return embed()
.setTitle("Pastebin")
.setDescription("" +
"Because Discord tends to break code formatting in text channels, we recommend " +
"using our own Pastebin site when sharing code. It helps keep things clear and makes it " +
"easier for us to understand and solve the problem with you.")
.addField("Link", ":right: https://paste.learnspigot.com/", false)
.setColor(Color.YELLOW)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class LeaderboardMessage(private val profileRegistry: ProfileRegistry) {

private val executorService = Executors.newSingleThreadScheduledExecutor()

private val monthlyRewardMessage: Message
private val lifetimeMessage: Message
private val monthlyMessage: Message
//private val monthlyRewardMessage: Message
//private val lifetimeMessage: Message
//private val monthlyMessage: Message

init {
Server.leaderboardChannel.apply {
Expand All @@ -31,6 +31,7 @@ class LeaderboardMessage(private val profileRegistry: ProfileRegistry) {
* If all 3 messages aren't there, delete any existing ones and send the new 3
* Otherwise, just get them, edit to update, and store for constant updating like normal
*/
/*
if (size != 3) {
forEach { it.delete().queue() }
monthlyRewardMessage = sendMessageEmbeds(buildPrizeEmbed()).complete()
Expand All @@ -41,12 +42,14 @@ class LeaderboardMessage(private val profileRegistry: ProfileRegistry) {
lifetimeMessage = get(1).editMessageEmbeds(buildLeaderboard(false)).complete()
monthlyMessage = get(0).editMessageEmbeds(buildLeaderboard(true)).complete()
}

*/
}
}

executorService.scheduleAtFixedRate({
lifetimeMessage.editMessageEmbeds(buildLeaderboard(false)).queue()
monthlyMessage.editMessageEmbeds(buildLeaderboard(true)).queue()
//lifetimeMessage.editMessageEmbeds(buildLeaderboard(false)).queue()
//monthlyMessage.editMessageEmbeds(buildLeaderboard(true)).queue()

if (isLastMin()){
Server.managerChannel.sendMessageEmbeds(buildLeaderboard(true)).queue {println("Manager channel leaderboard message sent.")}
Expand Down