From 7cad13248ad4578e9901bf32178ca9b8866f93ae Mon Sep 17 00:00:00 2001 From: Julius de Jeu Date: Sun, 23 Feb 2020 13:22:02 +0100 Subject: [PATCH] yeet --- .gitignore | 3 +- src/main/kotlin/nl/voidcorp/ottologs/Main.kt | 33 +++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index cd3d2f4..e76af5c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea/ .gradle/ -build/ \ No newline at end of file +build/ +out/ diff --git a/src/main/kotlin/nl/voidcorp/ottologs/Main.kt b/src/main/kotlin/nl/voidcorp/ottologs/Main.kt index aa4cd70..e0cc01d 100644 --- a/src/main/kotlin/nl/voidcorp/ottologs/Main.kt +++ b/src/main/kotlin/nl/voidcorp/ottologs/Main.kt @@ -1,18 +1,49 @@ package nl.voidcorp.ottologs +import net.dv8tion.jda.api.EmbedBuilder import net.dv8tion.jda.api.JDABuilder import net.dv8tion.jda.api.entities.Activity import net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent +import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent import net.dv8tion.jda.api.hooks.ListenerAdapter +import java.awt.Color fun main() { val token: String = System.getenv("DISCORD_TOKEN") ?: throw RuntimeException("Missing DISCORD_TOKEN in env!") val jda = JDABuilder().setToken(token).setActivity(Activity.watching("you")).addEventListeners(LogListener).build() } +data class Message(val user: Long, val content: String, val channel: Long, val guild: Long, val message: Long) + +val messages = mutableListOf() object LogListener : ListenerAdapter() { - override fun onGuildMessageDelete(event: GuildMessageDeleteEvent) { + override fun onGuildMessageReceived(event: GuildMessageReceivedEvent) { + if (!event.isWebhookMessage && !event.author.isBot) { + val m = Message( + event.author.idLong, + event.message.contentRaw, + event.message.channel.idLong, + event.guild.idLong, + event.message.idLong + ) + messages += m + } + } + override fun onGuildMessageDelete(event: GuildMessageDeleteEvent) { + val m = messages.firstOrNull { it.message == event.messageIdLong } ?: return + val logs = event.guild.textChannels.find { it.name == "logs" } + logs?.sendMessage( + EmbedBuilder().setDescription(m.content).setTitle("Message Deleted!") + .addField("Channel", event.channel.asMention, true).addField( + "User", + event.jda.getUserById(m.user)?.asTag ?: "No Idea...", + true + ).setColor(Color.RED) + .build() + )?.queue { + + } } }