|
| 1 | +package com.simplechat |
| 2 | + |
| 3 | +import java.util.regex.Matcher |
| 4 | +import java.util.regex.Pattern |
| 5 | + |
| 6 | +/** |
| 7 | + * Compacts par message pour les groupes hide-useless (action COMPACT). |
| 8 | + * Premier pattern qui matche gagne ; aucun match → null (le brut est gardé). Pur. |
| 9 | + * L'ordre compte : variantes spécifiques avant les génériques. |
| 10 | + */ |
| 11 | +object GroupCompacts { |
| 12 | + |
| 13 | + private fun c(regex: String, fmt: (Matcher) -> String): Pair<Pattern, (Matcher) -> String> = |
| 14 | + Pattern.compile(regex) to fmt |
| 15 | + |
| 16 | + /** Retire les articles de tête des sources ("The Mage's Magma", "Your fairy"). */ |
| 17 | + private fun src(s: String) = s.removePrefix("The ").removePrefix("Your ").trim() |
| 18 | + |
| 19 | + private val COMPACTS: List<Pair<Pattern, (Matcher) -> String>> = listOf( |
| 20 | + // --- Transitions (System) --- |
| 21 | + c("^Warping you to your SkyBlock island\\.\\.\\.") { "§8→ §7Island" }, |
| 22 | + c("^Queuing\\.\\.\\. (.+)$") { m -> "§8⌛ §7${m.group(1)}" }, |
| 23 | + c("^Welcome to Hypixel SkyBlock!$") { "§aWelcome back" }, |
| 24 | + c("^Latest update: SkyBlock (.+)$") { m -> "§7Update §8· §f${m.group(1)}" }, |
| 25 | + c("^You are playing on profile: (.+?)(?: \\(.+\\))?$") { m -> "§7Profile §8· §a${m.group(1)}" }, |
| 26 | + c("^Watchdog has banned ([\\d,.]+) players in the last 7 days\\.$") { m -> "§cWatchdog §7· §f${m.group(1)} §7bans" }, |
| 27 | + c("^You earned ([\\d,]+) Mystery Dust!$") { m -> "§7+${m.group(1)} Mystery Dust" }, |
| 28 | + c("^You earned ([\\d,]+) Pet Consumables items!$") { m -> "§7+${m.group(1)} Pet Consumables" }, |
| 29 | + |
| 30 | + // --- Notifications (Lobby) --- |
| 31 | + c("^You tipped (\\d+) players? in (\\d+) ") { m -> "§aTipped §f${m.group(1)} §7(${m.group(2)} games)" }, |
| 32 | + c("^You have just received ([\\d,]+) coins as interest") { m -> "§6+${ChatRules.shortNum(m.group(1))} coins §7(interest)" }, |
| 33 | + c("^You caught yourself an invisibug!") { "§a+ §fInvisibug" }, |
| 34 | + c("^Mochibear ate too much") { "§a+ §fMochibear" }, |
| 35 | + c("^Achievement Unlocked: (.+)$") { m -> "§eAchievement §7· §f${m.group(1)}" }, |
| 36 | + |
| 37 | + // --- Dungeons --- |
| 38 | + c("^A (.+) Key was picked up!") { m -> "§a+ §f${m.group(1)} Key" }, |
| 39 | + c("^(.+) opened a (?:.+ )?door!$") { m -> "§7Door §8· §f${m.group(1)}" }, |
| 40 | + c("^PUZZLE SOLVED! (.+)$") { m -> "§aPuzzle ✔ §7${m.group(1)}" }, |
| 41 | + c("^DUNGEON BUFF! (.+)$") { m -> "§dBuff §7· §f${m.group(1)}" }, |
| 42 | + c("^A Blessing of (.+) was picked up!") { m -> "§d+ §fBlessing of ${m.group(1)}" }, |
| 43 | + c("^(.+) has obtained Blessing of (.+)!") { m -> "§d+ §fBlessing of ${m.group(2)}" }, |
| 44 | + c("^(.+) has obtained (Superboom TNT(?: x\\d+)?|Revive Stone|Premium Flesh|Beating Heart)!") { m -> "§a+ §f${m.group(2)} §7(${m.group(1)})" }, |
| 45 | + |
| 46 | + // --- Abilities --- |
| 47 | + c("on cooldown for (?:about )?(\\d+) more seconds") { m -> "§7Cooldown §8· §f${m.group(1)}s" }, |
| 48 | + c("^(?:This (?:item's ability|item|ability)|Your Ultimate) is (?:temporarily disabled|on cooldown)") { "§7Cooldown" }, |
| 49 | + c("mana to (?:do this|activate this)!") { "§bNot enough mana" }, |
| 50 | + c("^(.+) is (?:ready to use! Press DROP|now (?:available|ready)!)") { m -> "§a✔ §f${m.group(1)} §7ready" }, |
| 51 | + c("^(Archer|Mage|Berserker|Tank|Healer) Milestone (\\S+)") { m -> "§6Milestone §7· §f${m.group(1)} ${m.group(2)}" }, |
| 52 | + c("^Creeper Veil (Activated|De-activated)!") { m -> if (m.group(1) == "Activated") "§7Veil on" else "§7Veil off" }, |
| 53 | + |
| 54 | + // --- Combat / heal --- |
| 55 | + c("^(.+?) (?:hit|burnt) you for ([\\d,.]+) (?:true )?damage") { m -> "§c-${ChatRules.shortNum(m.group(2))} §7(${src(m.group(1))})" }, |
| 56 | + c("^A (.+) exploded, hitting you for ([\\d,.]+) damage") { m -> "§c-${ChatRules.shortNum(m.group(2))} §7(${m.group(1)})" }, |
| 57 | + c("^You were healed for ([\\d,.]+) health") { m -> "§a+${ChatRules.shortNum(m.group(1))}❤" }, |
| 58 | + c("^(.+?) healed you for ([\\d,.]+) health") { m -> "§a+${ChatRules.shortNum(m.group(2))}❤ §7(${src(m.group(1))})" }, |
| 59 | + c("^You gained ([\\d,.]+) HP worth of absorption") { m -> "§e+${ChatRules.shortNum(m.group(1))} absorption" }, |
| 60 | + c("^(.+) granted you ([\\d,.]+) strength for 20 seconds!") { m -> "§4+${m.group(2)}❁ §7(20s)" }, |
| 61 | + c("^(.+) formed a tether with you!$") { m -> "§a⚯ §f${m.group(1)}" }, |
| 62 | + c("^(.+) picked up your (.+) Orb!") { m -> "§d⬤ §7${m.group(2)} (${m.group(1)})" }, |
| 63 | + c("^You picked up a (.+) Orb from (.+?) healing you") { m -> "§d⬤ §7${m.group(1)} (${m.group(2)})" }, |
| 64 | + c("^(.+) used (.+) on you!$") { m -> "§c${m.group(2)} §7(${src(m.group(1))})" }, |
| 65 | + |
| 66 | + // --- Rewards / drops --- |
| 67 | + c("^ESSENCE! .+ found ([\\d,]+) (.+) Essence!") { m -> "§d+${m.group(1)} ${m.group(2)} Essence" }, |
| 68 | + c(" found a Wither Essence! Everyone gains an extra essence!") { "§d+1 Wither Essence" }, |
| 69 | + c("^You earned ([\\d,]+) (Event EXP|GEXP) from playing ") { m -> |
| 70 | + if (m.group(2) == "GEXP") "§2+${m.group(1)} GEXP" else "§e+${m.group(1)} Event EXP" |
| 71 | + }, |
| 72 | + c("^BONUS! Temporarily earn (\\d+)% more skill experience!") { m -> "§e+${m.group(1)}% skill XP" }, |
| 73 | + c("^Your Kill Combo has expired! You reached a (\\d+) Kill Combo!") { m -> "§7Combo ended §8· §f${m.group(1)}" }, |
| 74 | + c("^(?:CHARM|SALT) You charmed a (.+) and captured its Shard\\.") { m -> "§a+ §fShard §7(${m.group(1)})" }, |
| 75 | + |
| 76 | + // --- Bazaar / AH --- |
| 77 | + c("^\\[Bazaar] Submitting sell offer") { "§6Bazaar §7· selling…" }, |
| 78 | + c("^\\[Bazaar] Submitting buy order") { "§6Bazaar §7· buying…" }, |
| 79 | + c("^(?:Buy Order|Sell Offer) Setup! (.+)$") { m -> "§6Bazaar §a✔ §f${m.group(1)}" }, |
| 80 | + c("^Putting item in escrow") { "§7Escrow…" }, |
| 81 | + c("^Setting up the auction") { "§6AH §7· setup…" }, |
| 82 | + |
| 83 | + // --- Slayer --- |
| 84 | + c("^SLAYER QUEST STARTED!") { "§5Slayer §7· started" }, |
| 85 | + c("^SLAYER QUEST COMPLETE!") { "§5Slayer §a✔ §fcomplete" }, |
| 86 | + c("^» Slay ([\\d,]+) Combat XP worth of (.+?)\\.?$") { m -> "§7Slay §f${m.group(1)} XP §7of ${m.group(2)}" }, |
| 87 | + |
| 88 | + // --- Events --- |
| 89 | + c("^Started parkour ") { "§bParkour §7· start" }, |
| 90 | + c("^Finished parkour .+ in (.+)!$") { m -> "§bParkour §a✔ §f${m.group(1)}" }, |
| 91 | + c("^Warped from the (.+) to the (.+)!$") { m -> "§8→ §7${m.group(2)}" }, |
| 92 | + c("^HOPPITY'S HUNT You found an? (.+?) Egg") { m -> "§6+ §f${m.group(1)} Egg" }, |
| 93 | + c("^SACRIFICE! .+ turned .+ into ([\\d,]+) Dragon Essence!") { m -> "§5Sacrifice §7· §f+${m.group(1)} Dragon Essence" }, |
| 94 | + ) |
| 95 | + |
| 96 | + // Mystery Box : item extrait du raw pour garder sa couleur de rareté. |
| 97 | + private val BOX_IN = Pattern.compile(" found an? (.+) in an? (?:Holiday )?Mystery Box!") |
| 98 | + private val BOX_TIER = Pattern.compile(" found an? (.+) Mystery Box!$") |
| 99 | + |
| 100 | + /** Segment coloré du raw entre "found a/an " et [endMarker], codes couleur conservés. */ |
| 101 | + fun rawItem(raw: String, endMarker: String): String? { |
| 102 | + val m = Regex("found an? ").find(raw) ?: return null |
| 103 | + val span = raw.substring(m.range.last + 1).substringBefore(endMarker) |
| 104 | + return span.replace(Regex("(?:§.|\\s)+$"), "").trim().ifEmpty { null } |
| 105 | + } |
| 106 | + |
| 107 | + /** Compact du message ou null si aucun beautifier ne matche. */ |
| 108 | + fun beautify(clean: String, raw: String): String? { |
| 109 | + var m = BOX_IN.matcher(clean) |
| 110 | + if (m.find()) return "§7Mystery Box §8· §r" + (rawItem(raw, "in a") ?: "§f${m.group(1)}") |
| 111 | + m = BOX_TIER.matcher(clean) |
| 112 | + if (m.find()) return "§7Mystery Box §8· §r" + (rawItem(raw, "Mystery Box") ?: "§f${m.group(1)}") |
| 113 | + for ((pattern, fmt) in COMPACTS) { |
| 114 | + val matcher = pattern.matcher(clean) |
| 115 | + if (matcher.find()) return fmt(matcher) |
| 116 | + } |
| 117 | + return null |
| 118 | + } |
| 119 | +} |
0 commit comments