Skip to content

Commit

Permalink
Remove close ticket cta with something else, fix bug where messages t…
Browse files Browse the repository at this point in the history
…hat only have few words trigger the check
  • Loading branch information
MrPowerGamerBR committed Jul 16, 2024
1 parent 728735e commit bfabda2
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ class ComponentInteractionListener(val m: LorittaHelper) : ListenerAdapter() {

// Workaround because the LorittaResponse requires a content (it is only used for the "HelpMeResponse")
// So let's just use "button" as the content because it doesn't matter
val replies = response.getResponse("button")
val automatedSupportResponse = response.getSupportResponse("button")
val replies = automatedSupportResponse.replies

event.interaction.reply(replies.joinToString("\n") { it.build(event.user) })
.setEphemeral(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ class MessageListener(val m: LorittaHelper) : ListenerAdapter() {
.dropWhile { it.startsWith(">") }
.joinToString("\n")

val responses = channelResponses
.firstOrNull { it.handleResponse(cleanMessage) }?.getResponse(cleanMessage) ?: return@launch
val automatedSupportResponse = channelResponses
.firstOrNull { it.handleResponse(cleanMessage) }?.getSupportResponse(cleanMessage) ?: return@launch

val responses = automatedSupportResponse.replies
if (responses.isNotEmpty())
event.channel.sendMessage(
MessageCreateBuilder()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package net.perfectdreams.loritta.helper.serverresponses

import net.perfectdreams.loritta.api.messages.LorittaReply

data class AutomatedSupportResponse(
val replies: List<LorittaReply>,
val includeCloseTicketCallToAction: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,16 @@ interface LorittaResponse {
*
* @return a list (can be empty) of [LorittaReply] of this response
*/
fun getResponse(message: String): List<LorittaReply>
fun getResponse(message: String): List<LorittaReply> {
return emptyList()
}

/**
* Gets all the [LorittaReply] messages of this response
*
* @return a list (can be empty) of [LorittaReply] of this response
*/
fun getSupportResponse(message: String): AutomatedSupportResponse {
return AutomatedSupportResponse(getResponse(message), true)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.perfectdreams.loritta.helper.serverresponses.loritta.english

import net.perfectdreams.loritta.api.messages.LorittaReply
import net.perfectdreams.loritta.helper.serverresponses.AutomatedSupportResponse
import net.perfectdreams.loritta.helper.serverresponses.RegExResponse
import net.perfectdreams.loritta.helper.utils.Emotes
import java.util.regex.Pattern
Expand All @@ -17,10 +18,13 @@ class AddEmotesOnMessageResponse : RegExResponse() {
patterns.add("\\?".toPattern(Pattern.CASE_INSENSITIVE))
}

override fun getResponse(message: String) =
listOf(
LorittaReply(
"To add an emoji, send `\\:emoji:` in the chat, copy what appears (something like `<:loritta:331179879582269451>`) and then paste it in the message!", Emotes.LORI_OWO
)
override fun getSupportResponse(message: String) =
AutomatedSupportResponse(
listOf(
LorittaReply(
"To add an emoji, send `\\:emoji:` in the chat, copy what appears (something like `<:loritta:331179879582269451>`) and then paste it in the message!", Emotes.LORI_OWO
)
),
true
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.perfectdreams.loritta.helper.serverresponses.loritta.english

import net.perfectdreams.loritta.api.messages.LorittaReply
import net.perfectdreams.loritta.helper.serverresponses.AutomatedSupportResponse
import net.perfectdreams.loritta.helper.serverresponses.RegExResponse
import net.perfectdreams.loritta.helper.utils.Emotes
import java.util.regex.Pattern
Expand All @@ -18,11 +19,14 @@ class AddLoriResponse : RegExResponse() {
patterns.add(LORI_NAME.toPattern(Pattern.CASE_INSENSITIVE))
}

override fun getResponse(message: String) =
listOf(
LorittaReply(
"Adding me to your server is easy! Just click here and select the server you want to add me ^-^ <https://loritta.website/dashboard>",
Emotes.LORI_PAC
)
override fun getSupportResponse(message: String) =
AutomatedSupportResponse(
listOf(
LorittaReply(
"Adding me to your server is easy! Just click here and select the server you want to add me ^-^ <https://loritta.website/dashboard>",
Emotes.LORI_PAC
)
),
true
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.perfectdreams.loritta.helper.serverresponses.loritta.english

import net.perfectdreams.loritta.api.messages.LorittaReply
import net.perfectdreams.loritta.helper.serverresponses.AutomatedSupportResponse
import net.perfectdreams.loritta.helper.serverresponses.RegExResponse
import net.perfectdreams.loritta.helper.utils.Emotes
import java.util.regex.Pattern
Expand All @@ -17,11 +18,14 @@ class BadgeResponse : RegExResponse() {
patterns.add("\\?".toPattern(Pattern.CASE_INSENSITIVE))
}

override fun getResponse(message: String) =
listOf(
LorittaReply(
"Read more about badges and how you can acquire them in <#761337709720633392>",
Emotes.LORI_OWO
)
override fun getSupportResponse(message: String) =
AutomatedSupportResponse(
listOf(
LorittaReply(
"Read more about badges and how you can acquire them in <#761337709720633392>",
Emotes.LORI_OWO
)
),
true
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.perfectdreams.loritta.helper.serverresponses.loritta.english

import net.perfectdreams.loritta.api.messages.LorittaReply
import net.perfectdreams.loritta.helper.serverresponses.AutomatedSupportResponse
import net.perfectdreams.loritta.helper.serverresponses.RegExResponse
import net.perfectdreams.loritta.helper.utils.Emotes
import java.util.regex.Pattern
Expand All @@ -16,10 +17,13 @@ class VotarResponse : RegExResponse() {
patterns.add(LORI_NAME.toPattern(Pattern.CASE_INSENSITIVE))
}

override fun getResponse(message: String) = listOf(
LorittaReply(
"Thanks for wanting to vote in me! It helps me grow and also rewards you with Sonhos! It's a great deal, don't you think? To see the voting link, use `+dbl`!",
Emotes.LORI_OWO
)
override fun getSupportResponse(message: String) = AutomatedSupportResponse(
listOf(
LorittaReply(
"Thanks for wanting to vote in me! It helps me grow and also rewards you with Sonhos! It's a great deal, don't you think? To see the voting link, use `+dbl`!",
Emotes.LORI_OWO
)
),
true
)
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package net.perfectdreams.loritta.helper.serverresponses.sparklypower

import net.perfectdreams.loritta.api.messages.LorittaReply
import net.perfectdreams.loritta.helper.serverresponses.AutomatedSupportResponse

class HowToBuyPesadelosNaiveBayesResponse(sparklyNaiveBayes: SparklyNaiveBayes) : SparklyNaiveBayesResponse(SparklyNaiveBayes.QuestionCategory.BUY_PESADELOS, sparklyNaiveBayes) {
override fun getResponse(message: String): List<LorittaReply> {
return listOf(
LorittaReply(
"Você pode comprar pesadelos acessando o meu website! https://sparklypower.net/loja",
"<:pantufa_coffee:853048446981111828>"
)
override fun getSupportResponse(message: String): AutomatedSupportResponse {
return AutomatedSupportResponse(
listOf(
LorittaReply(
"Você pode comprar pesadelos acessando o meu website! https://sparklypower.net/loja",
"<:pantufa_coffee:853048446981111828>"
)
),
false
)
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package net.perfectdreams.loritta.helper.serverresponses.sparklypower

import net.perfectdreams.loritta.api.messages.LorittaReply
import net.perfectdreams.loritta.helper.serverresponses.AutomatedSupportResponse
import net.perfectdreams.loritta.helper.serverresponses.QuickAnswerResponse

class HowToVoteResponse : QuickAnswerResponse() {
override fun getResponse(message: String) =
listOf(
LorittaReply(
"Você pode votar no servidor acessando o meu website! https://sparklypower.net/votar",
"<:pantufa_coffee:853048446981111828>"
override fun getSupportResponse(message: String) =
AutomatedSupportResponse(
listOf(
LorittaReply(
"Você pode votar no servidor acessando o meu website! https://sparklypower.net/votar",
"<:pantufa_coffee:853048446981111828>"
),
LorittaReply(
"Você pode votar todos os dias para nos ajudar a crescer o SparklyPower cada vez mais!",
mentionUser = false
),
LorittaReply(
"E, é claro, você vai receber alguns brindes em troca! 1 mapa, 1 diamante, 1 caixa secreta e 7 pesadelos.",
mentionUser = false
)
),
LorittaReply(
"Você pode votar todos os dias para nos ajudar a crescer o SparklyPower cada vez mais!",
mentionUser = false
),
LorittaReply(
"E, é claro, você vai receber alguns brindes em troca! 1 mapa, 1 diamante, 1 caixa secreta e 7 pesadelos.",
mentionUser = false
)
true
)
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package net.perfectdreams.loritta.helper.serverresponses.sparklypower

import net.perfectdreams.loritta.api.messages.LorittaReply
import net.perfectdreams.loritta.helper.serverresponses.AutomatedSupportResponse
import net.perfectdreams.loritta.helper.serverresponses.QuickAnswerResponse

class ServerInformationResponse : QuickAnswerResponse() {
override fun getResponse(message: String) =
listOf(
LorittaReply(
"SparklyPower é o servidor de Minecraft Survival da Loritta & Pantufa! **IP:** `mc.sparklypower.net`",
"<:pantufa_hi:997662575779139615>"
override fun getSupportResponse(message: String) =
AutomatedSupportResponse(
listOf(
LorittaReply(
"SparklyPower é o servidor de Minecraft Survival da Loritta & Pantufa! **IP:** `mc.sparklypower.net`",
"<:pantufa_hi:997662575779139615>"
),
LorittaReply(
"**No computador:** Versões de *1.16* a *1.19*;",
"<a:wumpus_keyboard:682249824133054529>",
mentionUser = false
),
LorittaReply(
"**No celular:** Versão *1.19.0* (sempre a versão mais recente disponível, sem ser beta), **porta:** (padrão)",
"<a:wumpus_keyboard:682249824133054529>",
mentionUser = false
)
),
LorittaReply(
"**No computador:** Versões de *1.16* a *1.19*;",
"<a:wumpus_keyboard:682249824133054529>",
mentionUser = false
),
LorittaReply(
"**No celular:** Versão *1.19.0* (sempre a versão mais recente disponível, sem ser beta), **porta:** (padrão)",
"<a:wumpus_keyboard:682249824133054529>",
mentionUser = false
)
true
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ class SparklyNaiveBayes {
.replace(Regex("\\beh\\b", RegexOption.IGNORE_CASE), "é")
.replace(Regex("\\badissiona\\b", RegexOption.IGNORE_CASE), "adiciona")
.replace(Regex("\\badissiono\\b", RegexOption.IGNORE_CASE), "adiciono")

.replace(Regex("\\bcm\\b", RegexOption.IGNORE_CASE), "como")
.replace(Regex("\\bcnsg\\b", RegexOption.IGNORE_CASE), "consigo")
.replace(Regex("\\bptg\\b", RegexOption.IGNORE_CASE), "protege")
.replace(Regex("\\btern\\b", RegexOption.IGNORE_CASE), "terreno")

fun normalizeNaiveBayesInput(source: String) = source
.normalize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.perfectdreams.loritta.helper.serverresponses.sparklypower

import mu.KotlinLogging
import net.perfectdreams.loritta.helper.serverresponses.LorittaResponse
import net.perfectdreams.loritta.helper.utils.splitWords

abstract class SparklyNaiveBayesResponse(
private val category: SparklyNaiveBayes.QuestionCategory,
Expand All @@ -12,6 +13,10 @@ abstract class SparklyNaiveBayesResponse(
override fun handleResponse(message: String): Boolean {
val normalizedMessage = sparklyNaiveBayes.normalizeNaiveBayesInput(sparklyNaiveBayes.replaceShortenedWordsWithLongWords(message))

// Message too small, bail out!
if (2 >= normalizedMessage.splitWords().toList().size)
return false

val classifications = sparklyNaiveBayes.classifier.detailedClassification(normalizedMessage)
.entries
.sortedBy { it.value }
Expand All @@ -28,6 +33,6 @@ abstract class SparklyNaiveBayesResponse(
val diffBetweenBestMatchAndSecondBestMatch = bestMatch.value - secondBestMatch.value

// We compare between the second best because if two questions are very similar, then the question is a bit confusing
return bestMatch.value >= 0.4 && diffBetweenBestMatchAndSecondBestMatch >= 0.2
return bestMatch.value >= 0.5 && diffBetweenBestMatchAndSecondBestMatch >= 0.2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ object SparklyPowerResponses {
HowToTransferSonhosResponse(),
HowToVoteResponse(),

HowToBuyPesadelosNaiveBayesResponse(sparklyNaiveBayes),
HowToBuyPesadelosNaiveBayesResponse(sparklyNaiveBayes)
).sortedByDescending { it.priority }
}
Loading

0 comments on commit bfabda2

Please sign in to comment.