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

Feature: Sound Responses (Meow) #2222

Open
wants to merge 5 commits into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,10 @@ public String toString() {
@ConfigEditorBoolean
@FeatureToggle
public boolean petRarityDropMessage = true;


@Expose
@ConfigOption(name = "Sound Responses", desc = "")
@Accordion
public SoundResponseConfig soundResponse = new SoundResponseConfig();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package at.hannibal2.skyhanni.config.features.chat;

import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

public class SoundResponseConfig {

@Expose
@ConfigOption(name = "Meow", desc = "Play a meow any time a meow appears in chat.")
@ConfigEditorBoolean
public boolean meow = false;

@Expose
@ConfigOption(name = "Bark", desc = "Play a bark any time a woof, arf or bark appears in chat.")
@ConfigEditorBoolean
public boolean bark = false;
}
35 changes: 35 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/features/chat/SoundResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package at.hannibal2.skyhanni.features.chat

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
object SoundResponse {

private val config get() = SkyHanniMod.feature.chat.soundResponse

private val repoGroup = RepoPattern.group("chat.sound.response")

/** REGEX-TEST: meow
REGEX-TEST: meow
REGEX-TEST: meow
REGEX-TEST: MEow
REGEX-TEST: §ameow
REGEX-TEST: hello §ameow
* */
private val meow by repoGroup.pattern("meow", "(?:^|^.* )(?: |§.)*(?i)meow(?: |§.)*(?:\$| .*\$)")
private val bark by repoGroup.pattern("bark", "(?:^|^.* )(?: |§.)*(?i)(?:bark|arf|woof)(?: |§.)*(?:\$| .*\$)")

@SubscribeEvent
fun onLorenzChat(event: LorenzChatEvent) {
when {
config.meow && meow.matches(event.message) -> SoundUtils.playMeowSound()
config.bark && bark.matches(event.message) -> SoundUtils.playBarkSound()
}
}
}
12 changes: 11 additions & 1 deletion src/main/java/at/hannibal2/skyhanni/utils/SoundUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ object SoundUtils {
private val beepSound by lazy { createSound("random.orb", 1f) }
private val clickSound by lazy { createSound("gui.button.press", 1f) }
private val errorSound by lazy { createSound("mob.endermen.portal", 0f) }
private val meowSound by lazy { createSound("mob.cat.meow", 1f) }
private val barkSound by lazy { createSound("mob.wolf.bark", 1f) }
val plingSound by lazy { createSound("note.pling", 1f) }
val centuryActiveTimerAlert by lazy { createSound("skyhanni:centurytimer.active", 1f) }

Expand All @@ -38,7 +40,7 @@ object SoundUtils {
}
ErrorManager.logErrorWithData(
e, "Failed to play a sound",
"soundLocation" to this.soundLocation
"soundLocation" to this.soundLocation,
)
} finally {
if (!SkyHanniMod.feature.misc.maintainGameVolume) {
Expand Down Expand Up @@ -73,6 +75,14 @@ object SoundUtils {
plingSound.playSound()
}

fun playMeowSound() {
meowSound.playSound()
}

fun playBarkSound() {
barkSound.playSound()
}

fun command(args: Array<String>) {
if (args.isEmpty()) {
ChatUtils.userError("Specify a sound effect to test")
Expand Down
Loading