Skip to content
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

Added check to see if the first message of a Help Post contains code. Added missing lecture about Display Entities and fixed a verification issue. #263

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
7 changes: 4 additions & 3 deletions src/main/kotlin/com/learnspigot/bot/help/HastebinListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.learnspigot.bot.help
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.learnspigot.bot.Server
import com.learnspigot.bot.util.PasteBins
import com.learnspigot.bot.util.embed
import net.dv8tion.jda.api.entities.channel.ChannelType
import net.dv8tion.jda.api.events.message.MessageReceivedEvent
Expand All @@ -18,9 +19,9 @@ class HastebinListener : ListenerAdapter() {
private val GSON = Gson()

private val KNOWN_PASTEBINS = listOf(
"pastebin.com",
"paste.md-5.net",
"paste.helpch.at"
PasteBins.pb,
PasteBins.md5,
PasteBins.helpch
)

private val LS_PASTEBIN = "https://paste.learnspigot.com"
Expand Down
31 changes: 25 additions & 6 deletions src/main/kotlin/com/learnspigot/bot/help/ThreadListener.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.learnspigot.bot.help

import com.learnspigot.bot.Server
import com.learnspigot.bot.util.PasteBins
import com.learnspigot.bot.util.embed
import net.dv8tion.jda.api.entities.channel.ChannelType
import net.dv8tion.jda.api.events.channel.ChannelCreateEvent
Expand All @@ -11,19 +12,37 @@ class ThreadListener : ListenerAdapter() {
if (event.channelType != ChannelType.GUILD_PUBLIC_THREAD) return
if (event.channel.asThreadChannel().parentChannel.id != Server.helpChannel.id) return

val threadChannel = event.channel.asThreadChannel()
val content = if (threadChannel.parentChannel.type != ChannelType.FORUM) {
threadChannel.retrieveParentMessage().complete()?.contentRaw
} else {
threadChannel.retrieveStartMessage().complete()?.contentRaw
}

val KNOWN_PASTEBINS = listOf(
PasteBins.ls,
PasteBins.pb,
PasteBins.md5,
PasteBins.discord,
PasteBins.helpch
)

val closeId = event.guild!!.retrieveCommands().complete()
.firstOrNull { it.name == "close" }
?.id
val containsPastebinLink = KNOWN_PASTEBINS.any { content?.contains(it, ignoreCase = true) == true }

event.channel.asThreadChannel().sendMessageEmbeds(
threadChannel.sendMessageEmbeds(
embed()
.setTitle("Thank you for creating a post!")
.setDescription("""
Please allow someone to read through your post and answer it!

If you fixed your problem, please run ${if (closeId == null) "/close" else "</close:$closeId>"}.
""".trimIndent())
Please allow someone to read through your post and answer it!
${if (!containsPastebinLink) """
We've noticed that you didn't send us any code, if that's voluntary, you can ignore this message!
If not, feel free to send us the code with our pastebin: https://paste.learnspigot.com""" else ""}
If you fixed your problem, please run ${if (closeId == null) "/close" else "</close:$closeId>"}.
""".trimIndent())
.build()
).queue()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ class LectureRegistry {
"Holograms",
"You'll learn how to create cool-looking single and multi-line holograms and how to make them clickable!"
),
Lecture(
"37363462",
"Display Entities (1.19.4+)",
"You'll learn how to create amazing floating text, blocks and items without Texture Packs."
),
Lecture(
"29869478",
"Setting Permissions",
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/com/learnspigot/bot/util/PasteBins.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.learnspigot.bot.util

object PasteBins {
val pb = "pastebin.com"
val md5 = "paste.md-5.net"
val helpch = "paste.helpch.at"
val ls = "paste.learnspigot.com"
val discord = "```"
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class VerificationListener : ListenerAdapter() {

var url = e.getValue("url")!!.asString

if (url.contains("|")) {
if (url.contains("|") || url.startsWith("udemy.com/course")) {
e.reply("Invalid profile link.").setEphemeral(true).queue()
return
}
Expand All @@ -220,7 +220,7 @@ class VerificationListener : ListenerAdapter() {
.setTitle("Your profile has been received!")
.setDescription("""
Please wait a short while as staff verify that you own the course! Once verified, this channel will disappear and you'll be able to talk in the rest of the server.

Don't re-send the verify if not asked by one of the members of the Staff Team.
If you have any concerns, please ask in <#${Environment.get("QUESTIONS_CHANNEL_ID")}""" + ">." + """

""")
Expand Down