diff --git a/src/main/kotlin/com/learnspigot/bot/notice/NoticeCommand.kt b/src/main/kotlin/com/learnspigot/bot/notice/NoticeCommand.kt new file mode 100644 index 0000000..6e7397b --- /dev/null +++ b/src/main/kotlin/com/learnspigot/bot/notice/NoticeCommand.kt @@ -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() + } +} diff --git a/src/main/kotlin/com/learnspigot/bot/notice/NoticeListener.kt b/src/main/kotlin/com/learnspigot/bot/notice/NoticeListener.kt new file mode 100644 index 0000000..d5a5bc3 --- /dev/null +++ b/src/main/kotlin/com/learnspigot/bot/notice/NoticeListener.kt @@ -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 = 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() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/learnspigot/bot/notice/types/AiNotice.kt b/src/main/kotlin/com/learnspigot/bot/notice/types/AiNotice.kt new file mode 100644 index 0000000..f2d737c --- /dev/null +++ b/src/main/kotlin/com/learnspigot/bot/notice/types/AiNotice.kt @@ -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) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/learnspigot/bot/notice/types/McUtilsNotice.kt b/src/main/kotlin/com/learnspigot/bot/notice/types/McUtilsNotice.kt new file mode 100644 index 0000000..e1b4b41 --- /dev/null +++ b/src/main/kotlin/com/learnspigot/bot/notice/types/McUtilsNotice.kt @@ -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) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/learnspigot/bot/notice/types/NoticeType.kt b/src/main/kotlin/com/learnspigot/bot/notice/types/NoticeType.kt new file mode 100644 index 0000000..b2f6263 --- /dev/null +++ b/src/main/kotlin/com/learnspigot/bot/notice/types/NoticeType.kt @@ -0,0 +1,9 @@ +package com.learnspigot.bot.notice.types + +import net.dv8tion.jda.api.EmbedBuilder + +interface NoticeType { + + public fun notifyEmbed(userId: String): EmbedBuilder + +} \ No newline at end of file diff --git a/src/main/kotlin/com/learnspigot/bot/notice/types/PastebinNotice.kt b/src/main/kotlin/com/learnspigot/bot/notice/types/PastebinNotice.kt new file mode 100644 index 0000000..aa762d3 --- /dev/null +++ b/src/main/kotlin/com/learnspigot/bot/notice/types/PastebinNotice.kt @@ -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) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/learnspigot/bot/reputation/LeaderboardMessage.kt b/src/main/kotlin/com/learnspigot/bot/reputation/LeaderboardMessage.kt index 7af980c..7196331 100644 --- a/src/main/kotlin/com/learnspigot/bot/reputation/LeaderboardMessage.kt +++ b/src/main/kotlin/com/learnspigot/bot/reputation/LeaderboardMessage.kt @@ -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 { @@ -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() @@ -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.")}