Skip to content

Commit

Permalink
Fix: /viewrecipe (#1939)
Browse files Browse the repository at this point in the history
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
hannibal002 and hannibal002 authored May 30, 2024
1 parent e058044 commit 5d89d56
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@ package at.hannibal2.skyhanni.features.commands

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.MessageSendToServerEvent
import at.hannibal2.skyhanni.utils.ChatUtils.senderIsSkyhanni
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object ViewRecipeCommand {

private val config get() = SkyHanniMod.feature.misc.commands

/**
* REGEX-TEST: /viewrecipe aspect of the end
* REGEX-TEST: /viewrecipe aspect_of_the_end
* REGEX-TEST: /viewrecipe ASPECT_OF_THE_END
*/
private val pattern by RepoPattern.pattern(
"commands.viewrecipe",
"\\/viewrecipe (?<item>.*)"
)

@SubscribeEvent
fun onMessageSendToServer(event: MessageSendToServerEvent) {
if (!config.viewRecipeLowerCase) return
val message = event.message
if (!message.startsWith("/viewrecipe ", ignoreCase = true)) return
if (event.senderIsSkyhanni()) return

val item = pattern.matchMatcher(event.message.lowercase()) {
group("item").uppercase().replace(" ", "_")
} ?: return

if (message == message.uppercase()) return
val item = message.uppercase().substringAfter("viewrecipe").trim()
if (item.isEmpty()) return
event.isCanceled = true
HypixelCommands.viewRecipe(item)
}
Expand Down

0 comments on commit 5d89d56

Please sign in to comment.