Skip to content

Commit

Permalink
add auto afk reply (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
MicrocontrollersDev committed Jun 18, 2024
1 parent a0a0403 commit 9ad1928
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 78 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/polyfrost/hytils/config/HytilsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ public class HytilsConfig extends Config {
)
public static boolean autoPartyWarpConfirm;

@Switch(
name = "Auto Reply When AFK",
description = "Automatically sends a reply to anyone who PMs you when you are AFK in Limbo.",
category = "Chat", subcategory = "Automatic"
)
public static boolean autoReplyAfk;

@Switch(
name = "Game Status Restyle",
description = "Replace common game status messages with a new style.\n§eExamples:\n§a§l+ §bSteve §e(§b1§e/§b12§e)\n§c§l- §bSteve§r\n§e§l* §aGame starts in §b§l5 §aseconds.",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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 net.minecraftforge.client.event.ClientChatReceivedEvent;
import org.jetbrains.annotations.NotNull;
import org.polyfrost.hytils.config.HytilsConfig;
import org.polyfrost.hytils.handlers.chat.ChatReceiveModule;

import java.util.regex.Matcher;

public class AutoAfkReply implements ChatReceiveModule {
// TODO: maybe write a general afk checker for skyblock afkers, as they won't be in limbo
@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
if (getLocraw() != null && !getLocraw().getServerId().equals("limbo")) return;
String message = event.message.getUnformattedText();
Matcher matcher = getLanguage().autoAfkReplyPatternRegex.matcher(message);
if (matcher.matches()) {
UChat.say("/msg " + matcher.group(2) + " Hey " + matcher.group(2) + ", I am currently AFK!");
}
}

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

@Override
public int getPriority() {
return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
import java.util.concurrent.TimeUnit;

public class AutoChatReportConfirm implements ChatReceiveModule {

@Override
public int getPriority() {
return 3;
}

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
if (event.message.getUnformattedText().equals(getLanguage().autoChatReportConfirm)) {
Expand All @@ -46,4 +40,9 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
public boolean isEnabled() {
return HytilsConfig.autoChatReportConfirm;
}

@Override
public int getPriority() {
return 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@
import java.util.regex.Matcher;

public class AutoChatSwapper implements ChatReceiveModule {

@Override
public int getPriority() {
return 3;
}

@SuppressWarnings("all")
@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
Expand Down Expand Up @@ -118,6 +112,11 @@ public boolean isEnabled() {
return HytilsConfig.chatSwapper;
}

@Override
public int getPriority() {
return 3;
}

public static class ChatChannelMessagePreventer {

private boolean hasDetected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ private static String getGLMessage() {
}

@Override
public int getPriority() {
return 3;
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText()).trim();
if (message.contains(": ")) return;
if (message.endsWith("The game starts in 5 seconds!")) {
Minecraft.getMinecraft().thePlayer.sendChatMessage("/ac " + getGLMessage());
}
}

@Override
Expand All @@ -43,11 +47,7 @@ public boolean isEnabled() {
}

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText()).trim();
if (message.contains(": ")) return;
if (message.endsWith("The game starts in 5 seconds!")) {
Minecraft.getMinecraft().thePlayer.sendChatMessage("/ac " + getGLMessage());
}
public int getPriority() {
return 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.util.concurrent.TimeUnit;

public class AutoPartyWarpConfirm implements ChatReceiveModule {

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
final String message = EnumChatFormatting.getTextWithoutFormattingCodes(event.message.getUnformattedText());
Expand All @@ -40,12 +39,12 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
}

@Override
public int getPriority() {
return 3;
public boolean isEnabled() {
return HytilsConfig.autoPartyWarpConfirm;
}

@Override
public boolean isEnabled() {
return HytilsConfig.autoPartyWarpConfirm;
public int getPriority() {
return 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ public class AutoQueue implements ChatReceiveModule {
private String command = null;
private boolean sentCommand;

/**
* We want this to activate early so that it catches the queue message.
*/
@Override
public int getPriority() {
return -11;
}

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
if (!HytilsConfig.autoQueue) {
Expand All @@ -62,11 +54,6 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
}
}

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

@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
if (this.command != null) {
Expand Down Expand Up @@ -99,4 +86,17 @@ private void switchGame() {

}, HytilsConfig.autoQueueDelay, TimeUnit.SECONDS);
}

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

/**
* We want this to activate early so that it catches the queue message.
*/
@Override
public int getPriority() {
return -11;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ public AutoVictory() {
MinecraftForge.EVENT_BUS.register(this);
}

@Override
public int getPriority() {
return 3;
}

@Override
public boolean isEnabled() {
return HytilsConfig.autoGetWinstreak || HytilsConfig.autoGetGEXP;
}

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
String unformattedText = UTextComponent.Companion.stripFormatting(event.message.getUnformattedText());
Expand Down Expand Up @@ -153,4 +143,15 @@ private boolean isSupportedMode(LocrawInfo locraw) {
}
return false;
}

@Override
public boolean isEnabled() {
return HytilsConfig.autoGetWinstreak || HytilsConfig.autoGetGEXP;
}

@Override
public int getPriority() {
return 3;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@
import java.util.regex.Matcher;

public class AutoWB implements ChatReceiveModule {

@Override
public int getPriority() {
return -6;
}

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

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
String msg = event.message.getFormattedText().trim();
Expand Down Expand Up @@ -95,4 +84,14 @@ private String getNextMessage(String name) {
return newMessage.replace("%player%", name);
}
}

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

@Override
public int getPriority() {
return -6;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@

public class AutoWarn implements ChatReceiveModule {
@Override
public int getPriority() {
return 3;
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
if (UTextComponent.Companion.stripFormatting(event.message.getUnformattedText()).startsWith("A kick")) {
UChat.say(HytilsConfig.putInCaps ? "/pc ---------REQUEUE, I'VE BEEN KICKED!---------" : "/pc ---------I've been kicked, please requeue!---------");
}
}

@Override
Expand All @@ -37,9 +39,7 @@ public boolean isEnabled() {
}

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
if (UTextComponent.Companion.stripFormatting(event.message.getUnformattedText()).startsWith("A kick")) {
UChat.say(HytilsConfig.putInCaps ? "/pc ---------REQUEUE, I'VE BEEN KICKED!---------" : "/pc ---------I've been kicked, please requeue!---------");
}
public int getPriority() {
return 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@
import java.util.regex.Matcher;

public class GuildWelcomer implements ChatReceiveModule {

@Override
public int getPriority() {
return 1;
}

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
final String text = event.message.getUnformattedText();
Expand All @@ -46,4 +40,9 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
public boolean isEnabled() {
return HytilsConfig.guildWelcomeMessage;
}

@Override
public int getPriority() {
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.regex.Matcher;

public class SilentRemoval implements ChatReceiveModule {

private static final Set<String> silentUsers = new HashSet<>();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@
import org.jetbrains.annotations.NotNull;

public class ThankWatchdog implements ChatReceiveModule {

@Override
public int getPriority() {
return 3;
}

@Override
public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
if (event.message.getUnformattedText().equals("[WATCHDOG ANNOUNCEMENT]") || event.message.getUnformattedText().startsWith("A player has been removed from your")) {
Expand All @@ -42,4 +36,9 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
public boolean isEnabled() {
return HytilsConfig.thankWatchdog;
}

@Override
public int getPriority() {
return 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class LanguageData {
private String autoQueuePrefixGlobal = "^(?:You died! .+|YOU DIED! .+|You have been eliminated!|You won! .+|YOU WON! .+)$";

private String autoFriendPattern = "Friend request from (?<name>.+)\\[ACCEPT] - \\[DENY] - \\[IGNORE].*";
private String autoAfkReplyPattern = "^From (\\[.+?] )?(.+?): .+$";

private String chatCleanerJoin = "(?:sled into|slid into|joined|spooked into) the lobby";
private String chatCleanerTicketAnnouncer = "^(?<player>(?!You )\\w{1,16} )has found an? .+$";
Expand Down Expand Up @@ -114,6 +115,7 @@ public class LanguageData {
public Pattern autoQueuePrefixGlobalRegex;

public Pattern autoFriendPatternRegex;
public Pattern autoAfkReplyPatternRegex;

public Pattern chatCleanerJoinRegex;
public Pattern chatCleanerTicketAnnouncerRegex;
Expand Down Expand Up @@ -176,6 +178,7 @@ public void initialize() {
autoQueuePrefixGlobalRegex = Pattern.compile(autoQueuePrefixGlobal);

autoFriendPatternRegex = Pattern.compile(autoFriendPattern);
autoAfkReplyPatternRegex = Pattern.compile(autoAfkReplyPattern);

chatCleanerJoinRegex = Pattern.compile(chatCleanerJoin);
chatCleanerTicketAnnouncerRegex = Pattern.compile(chatCleanerTicketAnnouncer);
Expand Down

0 comments on commit 9ad1928

Please sign in to comment.