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

Improvement: Powder Mining Chat Filter V2 #2152

Merged
merged 26 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4857607
Update Powder Mining filter to be much more specifically targetable
DavidArthurCole Jun 25, 2024
b31217d
Fix migration of config
DavidArthurCole Jun 25, 2024
6ff3f13
Formatting and config move to unify
DavidArthurCole Jun 25, 2024
aac83b7
Fix malformed pattern
DavidArthurCole Jun 25, 2024
1806459
Mark as module to prevent repo pattern late init
DavidArthurCole Jun 25, 2024
6fb7520
Formatting issues
DavidArthurCole Jun 25, 2024
d21ca7c
Let's try that again
DavidArthurCole Jun 25, 2024
5fb0762
Convert simple bools to draggable list
DavidArthurCole Jun 25, 2024
086c8a8
Fix formatting of imports? I think?
DavidArthurCole Jun 25, 2024
8d8fe2d
Add back chest pattern, fix hanging patterns
DavidArthurCole Jun 25, 2024
56f2232
Match formatting in custom enums
DavidArthurCole Jun 25, 2024
ffbb40f
Bump powder numbers to account for edge cases
DavidArthurCole Jun 25, 2024
14fdc16
One.. more.. time!
DavidArthurCole Jun 25, 2024
30b728b
Merge branch 'hannibal002:beta' into PowderFilterV2
DavidArthurCole Jul 15, 2024
40e0182
Fix V2 of the powder filter to work with new patterns
DavidArthurCole Jul 15, 2024
25de797
I think this'll work
DavidArthurCole Jul 15, 2024
9a5d886
Nvm that pattern was cringe and bad
DavidArthurCole Jul 15, 2024
b1e7141
And also remove public
DavidArthurCole Jul 15, 2024
4d3983d
And formatting ...
DavidArthurCole Jul 15, 2024
cdead52
Formatting pt 2
DavidArthurCole Jul 15, 2024
cab88c9
Generic pattern was still cringe. Also enabled check
DavidArthurCole Jul 15, 2024
efbd50e
Add message blocking for non-level-20 explorer
DavidArthurCole Jul 18, 2024
dfa1e12
So many fixes
DavidArthurCole Jul 28, 2024
3d88b12
Merge branch 'hannibal002:beta' into PowderFilterV2
DavidArthurCole Jul 28, 2024
2e5533b
Formatting and improvement
DavidArthurCole Jul 28, 2024
b7aaf85
Formatting and strings
DavidArthurCole Jul 28, 2024
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 @@ -12,7 +12,7 @@ import com.google.gson.JsonPrimitive
object ConfigUpdaterMigrator {

val logger = LorenzLogger("ConfigMigration")
const val CONFIG_VERSION = 51
const val CONFIG_VERSION = 52
fun JsonElement.at(chain: List<String>, init: Boolean): JsonElement? {
if (chain.isEmpty()) return this
if (this !is JsonObject) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

import at.hannibal2.skyhanni.config.FeatureToggle;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.Accordion;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

public class FilterTypesConfig {

@Expose
@ConfigOption(name = "Powder Mining", desc = "")
@Accordion
public PowderMiningFilterConfig powderMiningFilter = new PowderMiningFilterConfig();

@Expose
@ConfigOption(name = "Hypixel Lobbies", desc = "Hide announcements in Hypixel lobbies " +
"(player joins, loot boxes, prototype lobby messages, radiating generosity, Hypixel tournaments)")
Expand Down Expand Up @@ -50,13 +56,6 @@ public class FilterTypesConfig {
@FeatureToggle
public boolean winterGift = false;

@Expose
@ConfigOption(name = "Powder Mining", desc = "Hide messages while opening chests in the Crystal Hollows. " +
"(except powder numbers over 1k, essence numbers over 2, Prehistoric Eggs, and Automaton Parts)")
@ConfigEditorBoolean
@FeatureToggle
public boolean powderMining = false;

@Expose
@ConfigOption(name = "Kill Combo", desc = "Hide messages about your Kill Combo from the Grandma Wolf pet.")
@ConfigEditorBoolean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package at.hannibal2.skyhanni.config.features.chat;

import at.hannibal2.skyhanni.config.FeatureToggle;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.Accordion;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDraggableList;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorDropdown;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorSlider;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static at.hannibal2.skyhanni.config.features.chat.PowderMiningFilterConfig.SimplePowderMiningRewardTypes.ASCENSION_ROPE;
import static at.hannibal2.skyhanni.config.features.chat.PowderMiningFilterConfig.SimplePowderMiningRewardTypes.JUNGLE_HEART;
import static at.hannibal2.skyhanni.config.features.chat.PowderMiningFilterConfig.SimplePowderMiningRewardTypes.OIL_BARREL;
import static at.hannibal2.skyhanni.config.features.chat.PowderMiningFilterConfig.SimplePowderMiningRewardTypes.SLUDGE_JUICE;
import static at.hannibal2.skyhanni.config.features.chat.PowderMiningFilterConfig.SimplePowderMiningRewardTypes.TREASURITE;
import static at.hannibal2.skyhanni.config.features.chat.PowderMiningFilterConfig.SimplePowderMiningRewardTypes.WISHING_COMPASS;
import static at.hannibal2.skyhanni.config.features.chat.PowderMiningFilterConfig.SimplePowderMiningRewardTypes.YOGGIE;

public class PowderMiningFilterConfig {
@Expose
@ConfigOption(name = "Enabled", desc = "Hide messages while opening chests in the Crystal Hollows.")
@ConfigEditorBoolean
@FeatureToggle
public boolean enabled = false;

@Expose
@ConfigOption(
name = "Powder", desc = "Hide §dGemstone §7and §aMithril §7Powder rewards under a certain amount." +
"\n§a0§7: §aShow all\n§c60000§7: §cHide all"
)
@ConfigEditorSlider(minValue = 0, maxValue = 60000, minStep = 500)
public int powderFilterThreshold = 1000;

@Expose
@ConfigOption(
name = "Essence", desc = "Hide §6Gold §7and §bDiamond §7Essence rewards under a certain amount." +
"\n§a0§7: §aShow all\n§c20§7: §cHide all"
)
@ConfigEditorSlider(minValue = 0, maxValue = 20, minStep = 1)
public int essenceFilterThreshold = 5;

public enum SimplePowderMiningRewardTypes {

ASCENSION_ROPE("§9Ascension Rope"),
WISHING_COMPASS("§aWishing Compass"),
OIL_BARREL("§aOil Barrel"),
PREHISTORIC_EGG("§fPrehistoric Egg"),
PICKONIMBUS("§5Pickonimbus 2000"),
JUNGLE_HEART("§6Jungle Heart"),
SLUDGE_JUICE("§aSludge Juice"),
YOGGIE("§aYoggie"),
ROBOT_PARTS("§9Robot Parts"),
TREASURITE("§5Treasurite"),
;

private final String name;

SimplePowderMiningRewardTypes(String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}

@Expose
@ConfigOption(name = "Common Items", desc = "Hide reward messages for listed items.")
@ConfigEditorDraggableList
public List<SimplePowderMiningRewardTypes> simplePowderMiningTypes = new ArrayList<>(Arrays.asList(
ASCENSION_ROPE,
WISHING_COMPASS,
OIL_BARREL,
JUNGLE_HEART,
SLUDGE_JUICE,
YOGGIE,
TREASURITE
));

@Expose
@ConfigOption(name = "Goblin Egg", desc = "Hide Goblin Egg rewards that are below a certain rarity.")
@ConfigEditorDropdown
public GoblinEggFilterEntry goblinEggs = GoblinEggFilterEntry.YELLOW_UP;

public enum GoblinEggFilterEntry {
SHOW_ALL("Show all"),
HIDE_ALL("Hide all"),
GREEN_UP("Show §aGreen §7and up"),
YELLOW_UP("Show §eYellow §7and up"),
RED_UP("Show §cRed §7and up"),
BLUE_ONLY("Show §3Blue §7only");

private final String name;

GoblinEggFilterEntry(String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}

@Expose
@ConfigOption(name = "Gemstones", desc = "")
@Accordion
public PowderMiningGemstoneFilterConfig gemstoneFilterConfig = new PowderMiningGemstoneFilterConfig();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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.ConfigEditorDropdown;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;

public class PowderMiningGemstoneFilterConfig {

@Expose
@ConfigOption(name = "Stronger Tool Messages", desc = "Hide 'You need a stronger tool..' messages.")
@ConfigEditorBoolean
public boolean strongerToolMessages = true;

@Expose
@ConfigOption(name = "Ruby", desc = "Hide Ruby gemstones under a certain quality.")
@ConfigEditorDropdown
public GemstoneFilterEntry rubyGemstones = GemstoneFilterEntry.FINE_ONLY;

@Expose
@ConfigOption(name = "Sapphire", desc = "Hide Sapphire gemstones under a certain quality.")
@ConfigEditorDropdown
public GemstoneFilterEntry sapphireGemstones = GemstoneFilterEntry.FINE_ONLY;

@Expose
@ConfigOption(name = "Amber", desc = "Hide Amber gemstones under a certain quality.")
@ConfigEditorDropdown
public GemstoneFilterEntry amberGemstones = GemstoneFilterEntry.FINE_ONLY;

@Expose
@ConfigOption(name = "Amethyst", desc = "Hide Amethyst gemstones under a certain quality.")
@ConfigEditorDropdown
public GemstoneFilterEntry amethystGemstones = GemstoneFilterEntry.FINE_ONLY;

@Expose
@ConfigOption(name = "Jade", desc = "Hide Jade gemstones under a certain quality.")
@ConfigEditorDropdown
public GemstoneFilterEntry jadeGemstones = GemstoneFilterEntry.FINE_ONLY;

@Expose
@ConfigOption(name = "Topaz", desc = "Hide Topaz gemstones under a certain quality.")
@ConfigEditorDropdown
public GemstoneFilterEntry topazGemstones = GemstoneFilterEntry.FINE_ONLY;

public enum GemstoneFilterEntry {
SHOW_ALL("Show All"),
HIDE_ALL("Hide all"),
FLAWED_UP("Show §aFlawed §7or higher"),
FINE_ONLY("Show §9Fine §7only");

private final String str;

GemstoneFilterEntry(String str) {
this.str = str;
}

@Override
public String toString() {
return str;
}
}
}
47 changes: 30 additions & 17 deletions src/main/java/at/hannibal2/skyhanni/features/chat/ChatFilter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigUpdaterMigrator
import at.hannibal2.skyhanni.data.HypixelData
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.chat.PowderMiningChatFilter.genericMiningRewardMessage
import at.hannibal2.skyhanni.features.dungeon.DungeonAPI
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.RegexUtils.groupOrNull
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RegexUtils.matches
import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraft.util.ChatComponentText
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern

Expand Down Expand Up @@ -324,20 +329,6 @@ object ChatFilter {
"§cThis gift is for §r.*§r§c, sorry!".toPattern(),
)

// Powder Mining
private val powderMiningPatterns = listOf(
"§cYou need a stronger tool to mine (Amethyst|Ruby|Jade|Amber|Sapphire|Topaz) Gemstone Block§r§c.".toPattern(),
"§aYou received §r§f\\d* §r§f[❤❈☘⸕✎✧] Rough (Ruby|Amethyst|Jade|Amber|Sapphire|Topaz) Gemstone§r§a\\.".toPattern(),
"§aYou received §r§f\\d §r§a[❤❈☘⸕✎✧] Flawed (Ruby|Amethyst|Jade|Amber|Sapphire|Topaz) Gemstone§r§a\\.".toPattern(),

// Jungle
"§aYou received §r§f\\d* §r§aSludge Juice§r§a\\.".toPattern(),

// Useful, maybe in another chat
"§aYou received §r§b\\+\\d{1,3} §r§a(Mithril|Gemstone) Powder.".toPattern(),
"§aYou received §r(§6|§b)\\+[1-2] (Diamond|Gold) Essence§r§a.".toPattern(),
)

private val fireSalePattern by RepoPattern.pattern(
"chat.firesale",
"§6§k§lA§r §c§lFIRE SALE §r§6§k§lA(?:\\n|.)*",
Expand Down Expand Up @@ -428,7 +419,6 @@ object ChatFilter {
"winter_island" to winterIslandPatterns,
"annoying_spam" to annoyingSpamPatterns,
"winter_gift" to winterGiftPatterns,
"powder_mining" to powderMiningPatterns,
"fire_sale" to fireSalePatterns,
"event" to eventPatterns,
"factory_upgrade" to factoryUpgradePatterns,
Expand Down Expand Up @@ -469,7 +459,8 @@ object ChatFilter {

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
val blockReason = block(event.message)
var blockReason = block(event.message)
if (blockReason == "" && config.powderMiningFilter.enabled) blockReason = powderMiningBlock(event)
if (blockReason == "") return

event.blockedReason = blockReason
Expand All @@ -494,7 +485,6 @@ object ChatFilter {
config.others && isOthers(message) -> othersMsg

config.winterGift && message.isPresent("winter_gift") -> "winter_gift"
config.powderMining && message.isPresent("powder_mining") -> "powder_mining"
config.eventLevelUp && (message.isPresent("event") || StringUtils.isEmpty(message)) -> "event"
config.fireSale && (fireSalePattern.matches(message) || message.isPresent("fire_sale")) -> "fire_sale"
config.factoryUpgrade && message.isPresent("factory_upgrade") -> "factory_upgrade"
Expand All @@ -509,6 +499,28 @@ object ChatFilter {
else -> ""
}

/**
* Checks if the message is a blocked powder mining message, as defined in PowderMiningChatFilter.
* Will modify un-filtered Mining rewards, or return a resultant blocking code
* @param event The event to check
* @return Block reason if applicable
* @see block
*/
private fun powderMiningBlock(event: LorenzChatEvent): String {
val powderMiningMatchResult = PowderMiningChatFilter.block(event.message)
if (powderMiningMatchResult == "no_filter") {
genericMiningRewardMessage.matchMatcher(event.message) {
val reward = groupOrNull("reward") ?: ""
val amountFormat = groupOrNull("amount")?.let {
"§a+ §b$it§r"
} ?: "§a+§r"
event.chatComponent = ChatComponentText("$amountFormat $reward")
}
return ""
}
return powderMiningMatchResult
}

private var othersMsg = ""

/**
Expand Down Expand Up @@ -565,5 +577,6 @@ object ChatFilter {
event.move(3, "chat.killCombo", "chat.filterType.killCombo")
event.move(3, "chat.profileJoin", "chat.filterType.profileJoin")
event.move(3, "chat.others", "chat.filterType.others")
event.move(52, "chat.filterType.powderMining", "chat.filterType.powderMiningFilter.enabled")
}
}
Loading
Loading