Skip to content

Commit

Permalink
initial untested implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
MicrocontrollersDev committed Jun 18, 2024
1 parent eebbc9c commit e10b829
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 1 deletion.
74 changes: 74 additions & 0 deletions src/main/java/org/polyfrost/hytils/config/HytilsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,66 @@ public class HytilsConfig extends Config {

// Chat

@Switch(
name = "Auto GG",
description = "Send a \"gg\" message at the end of a game.",
category = "Chat", subcategory = "Automatic"
)
public static boolean autoGG;

@Switch(
name = "Auto GG Second Message",
description = "Enable a secondary message to send after your first GG.",
category = "Chat", subcategory = "Automatic"
)
public static boolean autoGGSecondMessage;

@Switch(
name = "Casual Auto GG",
description = "Send a \"gg\" message at the end of minigames/events that don't give out Karma, such as SkyBlock and The Pit events.",
category = "Chat", subcategory = "Automatic"
)
public static boolean casualAutoGG;

@Switch(
name = "Anti GG",
description = "Remove GG messages from chat.",
category = "Chat", subcategory = "Automatic"
)
public static boolean antiGG;

@Dropdown(
name = "Auto GG First Message",
description = "Choose what message is said on game completion.",
category = "Chat", subcategory = "Automatic",
options = {"gg", "GG", "gf", "Good Game", "Good Fight", "Good Round! :D"}
)
public static int autoGGMessage = 0;

@Slider(
name = "Auto GG First Phrase Delay",
description = "Delay after the game ends to say the first message in seconds.",
category = "Chat", subcategory = "Automatic",
min = 0, max = 5
)
public static int autoGGFirstPhraseDelay = 1;

@Dropdown(
name = "Auto GG Second Message",
description = "Send a secondary message sent after the first GG message.",
category = "Chat", subcategory = "Automatic",
options = {"Have a good day!", "<3", "AutoGG By Hytils!", "gf", "Good Fight", "Good Round", ":D", "Well played!", "wp"}
)
public static int autoGGMessage2 = 0;

@Slider(
name = "Auto GG Second Phrase Delay",
description = "Delay after the game ends to say the second message in seconds.",
category = "Chat", subcategory = "Automatic",
min = 0, max = 5
)
public static int autoGGSecondPhraseDelay = 1;

@Switch(
name = "Auto GL",
description = "Send a message 5 seconds before a Hypixel game starts.",
Expand Down Expand Up @@ -339,6 +399,13 @@ public class HytilsConfig extends Config {
)
public static boolean preventShoutingOnCooldown = true;

@Switch(
name = "Hide Karma Messages",
description = "Remove Karma messages from the chat.",
category = "Chat", subcategory = "Toggles"
)
public static boolean hideKarmaMessages;

@Switch(
name = "Hide Locraw Messages",
description = "Hide locraw messages in chat (e.g {\"server\": \"something\"}).",
Expand Down Expand Up @@ -1065,6 +1132,13 @@ public HytilsConfig() {

addDependency("gexpMode", "autoGetGEXP");

addDependency("autoGGSecondMessage", "autoGG");
addDependency("casualAutoGG", "autoGG");
addDependency("autoGGMessage", "autoGG");
addDependency("autoGGFirstPhraseDelay", "autoGG");
addDependency("autoGGMessage2", "autoGG");
addDependency("autoGGSecondPhraseDelay", "autoGG");

addDependency("glPhrase", "autoGL");

addDependency("guildAutoWB", "autoWB");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public ChatHandler() {
// Blockers

this.registerModule(new AdBlocker());
this.registerModule(new AntiGG());
this.registerModule(new AntiGL());
this.registerModule(new AutoWB());
this.registerModule(new BedwarsAdvertisementsRemover());
Expand All @@ -66,6 +67,7 @@ public ChatHandler() {
this.registerModule(new GuildMOTD());
this.registerModule(new HotPotatoRemover());
this.registerModule(new HypeLimitReminderRemover());
this.registerModule(new KarmaRemover());
this.registerModule(new LobbyFishingAnnouncementRemover());
this.registerModule(new LobbyStatusRemover());
this.registerModule(new MvpEmotesRemover());
Expand Down Expand Up @@ -98,6 +100,7 @@ public ChatHandler() {
this.registerModule(new AutoChatReportConfirm());
this.registerModule(new AutoChatSwapper());
this.registerModule(new AutoFriend());
this.registerModule(new AutoGG());
this.registerModule(new AutoGL());
this.registerModule(new AutoPartyWarpConfirm());
this.registerModule(new AutoVictory());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Hytils Reborn - Hypixel focused Quality of Life mod.
* Copyright (C) 2020, 2021, 2022, 2023 Polyfrost, Sk1er LLC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.polyfrost.hytils.handlers.chat.modules.blockers;

import cc.polyfrost.oneconfig.utils.hypixel.LocrawUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import org.jetbrains.annotations.NotNull;
import org.polyfrost.hytils.config.HytilsConfig;
import org.polyfrost.hytils.handlers.chat.ChatReceiveModule;

public class AntiGG implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText().toLowerCase());
if ((message.startsWith("-") && message.endsWith("-")) || (message.startsWith("▬") && message.endsWith("▬")) || (message.startsWith("≡") && message.endsWith("≡")) || (!message.contains(": ")) || (message.contains(Minecraft.getMinecraft().getSession().getUsername().toLowerCase())) || (LocrawUtil.INSTANCE.getLocrawInfo() != null && !LocrawUtil.INSTANCE.isInGame())) return;
if (getLanguage().cancelGgMessagesRegex.matcher(message).matches()) {
event.setCanceled(true);
}
}

@Override
public boolean isEnabled() {
return HytilsConfig.antiGG;
}

@Override
public int getPriority() {
return -3;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Hytils Reborn - Hypixel focused Quality of Life mod.
* Copyright (C) 2020, 2021, 2022, 2023 Polyfrost, Sk1er LLC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.polyfrost.hytils.handlers.chat.modules.blockers;

import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import org.jetbrains.annotations.NotNull;
import org.polyfrost.hytils.config.HytilsConfig;
import org.polyfrost.hytils.handlers.chat.ChatReceiveModule;

public class KarmaRemover implements ChatReceiveModule {
@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
if (getLanguage().cancelKarmaMessagesRegex.matcher(message).matches()) {
event.setCanceled(true);
}
}

@Override
public boolean isEnabled() {
return HytilsConfig.hideKarmaMessages;
}

@Override
public int getPriority() {
return -1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Hytils Reborn - Hypixel focused Quality of Life mod.
* Copyright (C) 2020, 2021, 2022, 2023 Polyfrost, Sk1er LLC and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package org.polyfrost.hytils.handlers.chat.modules.triggers;

import cc.polyfrost.oneconfig.libs.universal.UChat;
import cc.polyfrost.oneconfig.utils.Multithreading;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import org.jetbrains.annotations.NotNull;
import org.polyfrost.hytils.config.HytilsConfig;
import org.polyfrost.hytils.handlers.cache.PatternHandler;
import org.polyfrost.hytils.handlers.chat.ChatReceiveModule;

import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

public class AutoGG implements ChatReceiveModule {
private static final String[] ggMessagesOne = {"gg", "GG", "gf", "Good Game", "Good Fight", "Good Round! :D"};
private static final String[] ggMessagesTwo = {"Have a good day!", "<3", "AutoGG By Hytils!", "gf", "Good Fight", "Good Round", ":D", "Well played!", "wp"};

private static String getGGMessageOne() {
return ggMessagesOne[HytilsConfig.autoGGMessage];
}
private static String getGGMessageTwo() {
return ggMessagesTwo[HytilsConfig.autoGGMessage2];
}

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText()).trim();
if (!hasGameEnded(message)) return;
Multithreading.schedule(() -> UChat.say("/ac " + getGGMessageOne()), HytilsConfig.autoGGFirstPhraseDelay, TimeUnit.SECONDS);
if (HytilsConfig.autoGGSecondMessage)
Multithreading.schedule(() -> UChat.say("/ac " + getGGMessageTwo()), HytilsConfig.autoGGSecondPhraseDelay, TimeUnit.SECONDS);
}

private boolean hasGameEnded(String message) {
if (!PatternHandler.INSTANCE.gameEnd.isEmpty()) {
for (Pattern triggers : PatternHandler.INSTANCE.gameEnd) {
if (triggers.matcher(message).matches()) {
return true;
}
}
}
return false;
}

@Override
public boolean isEnabled() {
return HytilsConfig.autoGG;
}

@Override
public int getPriority() {
return 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public AutoVictory() {
@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
String unformattedText = UTextComponent.Companion.stripFormatting(event.message.getUnformattedText());
if (PatternHandler.INSTANCE.gameEnd.size() != 0) {
if (!PatternHandler.INSTANCE.gameEnd.isEmpty()) {
if (!victoryDetected) { // prevent victories being detected twice
Multithreading.runAsync(() -> { //run this async as getting from the API normally would freeze minecraft
for (Pattern triggers : PatternHandler.INSTANCE.gameEnd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public class LanguageData {

private String hypixelLevelUp = "You are now Hypixel Level (?<level>\\d+)!";

private String cancelGgMessages = "^(?:.* )?(?:\\\\[.+] )?\\\\w{1,16}(?: .+)?: (?:❤|gg|GG|gf|Good Game|Good Fight|Good Round! :D|Have a good day!|<3|AutoGG By Sk1er|AutoGG By Hytils|gf|Good Fight|Good Round|:D|Well Played!|wp)$";
private String cancelKarmaMessages = "^\\+(?<karma>\\d)+ Karma!$";
private String cancelGlMessages = "(?!.+: )(gl|glhf|good luck|have a good game|autogl by sk1er)";

public String autoChatReportConfirm = "Please type /report confirm to log your report for staff review.";
Expand Down Expand Up @@ -164,6 +166,8 @@ public class LanguageData {

public Pattern hypixelLevelUpRegex;

public Pattern cancelGgMessagesRegex;
public Pattern cancelKarmaMessagesRegex;
public Pattern cancelGlMessagesRegex;

public Pattern gameBossbarAdvertisementRegex;
Expand Down Expand Up @@ -227,6 +231,8 @@ public void initialize() {

hypixelLevelUpRegex = Pattern.compile(hypixelLevelUp);

cancelGgMessagesRegex = Pattern.compile(cancelGgMessages);
cancelKarmaMessagesRegex = Pattern.compile(cancelKarmaMessages);
cancelGlMessagesRegex = Pattern.compile(cancelGlMessages, Pattern.CASE_INSENSITIVE);

gameBossbarAdvertisementRegex = Pattern.compile(gameBossbarAdvertisement);
Expand Down

0 comments on commit e10b829

Please sign in to comment.