This commit is contained in:
Julius 2020-02-23 13:22:02 +01:00
parent b0e2255767
commit 7cad13248a
2 changed files with 34 additions and 2 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
.idea/ .idea/
.gradle/ .gradle/
build/ build/
out/

View file

@ -1,18 +1,49 @@
package nl.voidcorp.ottologs package nl.voidcorp.ottologs
import net.dv8tion.jda.api.EmbedBuilder
import net.dv8tion.jda.api.JDABuilder import net.dv8tion.jda.api.JDABuilder
import net.dv8tion.jda.api.entities.Activity import net.dv8tion.jda.api.entities.Activity
import net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent 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 net.dv8tion.jda.api.hooks.ListenerAdapter
import java.awt.Color
fun main() { fun main() {
val token: String = System.getenv("DISCORD_TOKEN") ?: throw RuntimeException("Missing DISCORD_TOKEN in env!") 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() 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<Message>()
object LogListener : ListenerAdapter() { object LogListener : ListenerAdapter() {
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) { 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 {
} }
}
} }