Skip to content

Commit

Permalink
Optionally close Chat Box to prevent disconnected when someone DM you (
Browse files Browse the repository at this point in the history
…#85)

* add new image

* new feature close chat box

* fix tabs

* Update README

Co-authored-by: 9-9-9-9 <9-9-9-9>
  • Loading branch information
9-9-9-9 authored Nov 19, 2022
1 parent d3afc1b commit 686a95a
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- [ ] Hallowed Dimension (Expedition)
- [ ] Jammie Dimension (Expedition)
- [ ] Battle Bards (Expedition)
## To the folks who using this bot but not giving this repository a Star: Fvck U, from the 8 pixels world to the 4D reality
## To the folks who are using this bot but not giving this repository a Star: **Fvck U! from the 8 pixels world to the 4D reality!**

___
**Upgrade notes:** copy configuration files `user-config.properties` and `readonly.*.user-config.properties` from previous bot version's directory _(if you update the bot via auto-update method then no need to do this)_
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>bh.bot</groupId>
<artifactId>99bot</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>

<dependencies>
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ cat <<EOF > ./release/user-config.properties
# Alter interval between loops of checking images, if you believe your PC is fast, you can use this key for a faster progression. Default interval for most functions is 5 seconds (please see at --help of each function), accepted format is: "number" = number of seconds / "number" + "s" = number of seconds / "number" + "ms" = number of milliseconds, eg: 50ms = loop every 50 milliseconds, or 5000ms equals to 5 seconds
#interval.loop.main=1s
# Normally, when someone send you a message (DM), bot got confused by the chat box and can not do anything, then you will be disconnected after amount if time
# by setting the following flag to "true", bot will take and save a screenshot into folder 'out\chatbox', close the chat box then continue it's work
#behavior.close-chat-box-direct-message=true
# Google Chrome path, for Windows only
#external.application.chrome.path=C:\\\\Program Files (x86)\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe
Expand Down
68 changes: 68 additions & 0 deletions src/main/java/bh/bot/app/AbstractApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ private void initOutputDirectories() {
mkdir("out");
mkdir("out", "images");
mkdir("out", "images", getAppCode());
mkdir("out", "chatbox");
}

@SuppressWarnings("SameParameterValue")
Expand Down Expand Up @@ -265,6 +266,10 @@ protected void saveImage(BufferedImage img, String prefix) {
File file = Paths
.get("out", "images", getAppCode(), prefix + "_" + System.currentTimeMillis() + ".bmp")
.toFile();
saveImage(img, file);
}

protected void saveImage(BufferedImage img, File file) {;
try {
ImageIO.write(img, "bmp", file);
} catch (IOException e) {
Expand Down Expand Up @@ -707,6 +712,7 @@ protected Tuple2<Point[], Byte> detectRadioButtons(Rectangle scanRect) {
private static final int persuadeSleepSecsIntervalInCaseManual = 30;
private static final int persuadeSleepSecsAwaitAction = 20;
private static final int showWarningWorldBossTeamSleepSecs = 60;
private static final int detectChatboxDirectMessageSleepSecs = 60;

protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
try {
Expand All @@ -720,6 +726,8 @@ protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
boolean persuade = st.persuade && !argumentInfo.disablePersuade;
long nextShowWarningWorldBossTeam = addSec(showWarningWorldBossTeamSleepSecs);
boolean showWarningWorldBossTeam = st.showWarningWorldBossTeam;
long nextDetectChatBoxDirectMessage = addSec(detectChatboxDirectMessageSleepSecs);
boolean closeChatBoxDirectMessage = Configuration.closeChatBoxDirectMessage;

if (persuade) {
info("Auto persuade had been turned on, that means in case of any persuade screen appears, bot will automatically persuade the monster with Gold. If you want to disable this feature, you can use '%s' flag", FlagDisablePersuade.FlagName);
Expand Down Expand Up @@ -767,6 +775,14 @@ protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
.yellow(" to persuade/bribe manually, otherwise bot can't continue your tasks and becomes waste of resources")
.reset()
);

if (st.detectChatboxDirectMessage) {
if (closeChatBoxDirectMessage) {
warn("You had configured to close chatbox direct message, screenshot of the message will be saved in folder %s", saveChatboxDirectMessageImageTo);
} else {
warn("You did not configure to close chatbox direct message, so the income messages will stay as is and you might be disconnected after amount of time. Screenshot of the message will be saved in folder %s", saveChatboxDirectMessageImageTo);
}
}

while (!masterSwitch.get()) {
sleep(1_000);
Expand Down Expand Up @@ -794,6 +810,10 @@ protected void internalDoSmallTasks(AtomicBoolean masterSwitch, SmallTasks st) {
warningWatchWorldBossTeam(ColorizeUtil.formatWarning);
nextShowWarningWorldBossTeam = addSec(showWarningWorldBossTeamSleepSecs);
}


if (st.detectChatboxDirectMessage && nextDetectChatBoxDirectMessage <= System.currentTimeMillis())
nextDetectChatBoxDirectMessage = detectChatBoxDirectMessage(closeChatBoxDirectMessage, masterSwitch);
}
} catch (Exception ex) {
ex.printStackTrace();
Expand All @@ -814,6 +834,7 @@ protected static class SmallTasks {
public final boolean closeEnterGameNewsDialog;
public final boolean persuade;
public final boolean showWarningWorldBossTeam;
public final boolean detectChatboxDirectMessage;

private SmallTasks(Builder b) {
this.clickTalk = b.f(0);
Expand All @@ -823,6 +844,7 @@ private SmallTasks(Builder b) {
this.closeEnterGameNewsDialog = b.f(4);
this.persuade = b.f(5);
this.showWarningWorldBossTeam = b.f(6);
this.detectChatboxDirectMessage = b.f(7);
}

public static Builder builder() {
Expand Down Expand Up @@ -872,6 +894,10 @@ public Builder persuade() {
public Builder warningWorldBossTeam() {
return this.set(6);
}

public Builder detectChatboxDirectMessage() {
return this.set(7);
}
}
}

Expand Down Expand Up @@ -1047,6 +1073,48 @@ private long detectDisconnected(AtomicBoolean masterSwitch) {
return addSec(detectDcSleepSecs);
}

private static final String saveChatboxDirectMessageImageTo = "out\\chatbox";
private long detectChatBoxDirectMessage(boolean closeChatBoxDirectMessage, AtomicBoolean masterSwitch) {
if (clickImage(BwMatrixMeta.Metas.Globally.Buttons.sendMessage)) {
try {
Telegram.sendMessage("Someone sent you a direct message", false);
} catch (Throwable t) {
err("Failed to send telegram message");
err(t);
} finally {
if (!closeChatBoxDirectMessage)
masterSwitch.set(true);
}

try {
int x = Configuration.gameScreenOffset.X.get();
int y = Configuration.gameScreenOffset.Y.get();
int w = Configuration.screenResolutionProfile.getSupportedGameResolutionWidth();
int h = Configuration.screenResolutionProfile.getSupportedGameResolutionHeight();

BufferedImage sc = InteractionUtil.Screen.captureScreen(x, y, w, h);
try {
File file = Paths
.get("out", "chatbox", "direct_message_" + System.currentTimeMillis() + ".bmp")
.toFile();
saveImage(sc, file);
warn("Someone sent you a direct message, screenshot of the message has been saved into folder %s", saveChatboxDirectMessageImageTo);
} finally {
freeMem(sc);
}
} catch (Throwable t) {
err("Failed to capture and save direct message");
err(t);
}

if (closeChatBoxDirectMessage) {
clickImage(BwMatrixMeta.Metas.Globally.Buttons.closeChatBox);
}

}
return addSec(detectChatboxDirectMessageSleepSecs);
}

@SuppressWarnings("FieldCanBeLocal")
private final byte maxContinousRed = 6;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/bh/bot/app/AfkApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ protected void internalRun(String[] args) {
.autoExit() //
.closeEnterGameNewsDialog() //
.persuade() //
.detectChatboxDirectMessage() //
.build() //
), //
() -> doCheckGameScreenOffset(masterSwitch) //
Expand Down
1 change: 1 addition & 0 deletions src/main/java/bh/bot/app/FishingApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ protected void internalRun(String[] args) {
.builder() //
.clickDisconnect() //
.autoExit() //
.detectChatboxDirectMessage() //
.build() //
), //
() -> doCheckGameScreenOffset(masterSwitch) //
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/bh/bot/app/ReRunApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected void internalRun(String[] args) {
.clickDisconnect() //
.reactiveAuto() //
.autoExit() //
.persuade() //
.persuade() //
.detectChatboxDirectMessage() //
.build() //
), //
() -> detectDefeatedOnRaid(masterSwitch),
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/bh/bot/app/dev/TestApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public class TestApp extends AbstractApplication {
protected void internalRun(String[] args) {
adjustScreenOffset();

System.out.println("Clicked U = " + clickImage(BwMatrixMeta.Metas.WorldBoss.Buttons.unready));

//
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/bh/bot/app/farming/AbstractDoFarmingApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ protected void internalRun(String[] args) {
.reactiveAuto() //
.autoExit() //
.closeEnterGameNewsDialog() //
.persuade() //
.persuade() //
.detectChatboxDirectMessage() //
.build() //
), //
() -> doCheckGameScreenOffset(masterSwitch) //
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/bh/bot/common/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Configuration {
public static AtomicOffset gameScreenOffset;
public static final boolean enableDevFeatures = new File("im.dev").exists();
public static boolean noThrowWhenImageNotAvailable = false;
public static boolean closeChatBoxDirectMessage = false;

public static class Interval {

Expand Down Expand Up @@ -119,6 +120,8 @@ public static void loadSystemConfig(final ParseArgumentsResult parseArgumentsRes
}

noThrowWhenImageNotAvailable = StringUtil.isTrue(read("dev.no-throw-when-image-not-available"));

closeChatBoxDirectMessage = StringUtil.isTrue(read("behavior.close-chat-box-direct-message"));

if (parseArgumentsResult.mainLoopInterval >= FlagAlterLoopInterval.minimumValue) {
Interval.Loop.main = parseArgumentsResult.mainLoopInterval;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/bh/bot/common/types/ScreenResolutionProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public abstract class ScreenResolutionProfile {

public abstract Offset getOffsetButtonBribePersuade();

public abstract Offset getOffsetButtonSendMessage();

public abstract Offset getOffsetButtonCloseChatBox();

public abstract Offset getOffsetLabelPersuadeKaleido();

public abstract Offset getOffsetLabelPersuadeViolace();
Expand Down Expand Up @@ -729,6 +733,16 @@ public Offset getOffsetButtonBribePersuade() {
return new Offset(567, 329);
}

@Override
public Offset getOffsetButtonSendMessage() {
return new Offset(507, 367);
}

@Override
public Offset getOffsetButtonCloseChatBox() {
return new Offset(603, 101);
}

@Override
public Offset getOffsetLabelPersuadeKaleido() {
return new Offset(189, 78);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/bh/bot/common/types/images/BwMatrixMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ public static class Buttons {
public static BwMatrixMeta mapButtonOnFamiliarUi;
public static BwMatrixMeta persuade;
public static BwMatrixMeta persuadeBribe;
public static BwMatrixMeta sendMessage;
public static BwMatrixMeta closeChatBox;
}

public static class Dialogs {
Expand Down Expand Up @@ -410,6 +412,16 @@ public static void load() throws IOException {
Configuration.screenResolutionProfile.getOffsetButtonBribePersuade(), //
0xFFFFFF
);
Metas.Globally.Buttons.sendMessage = BwMatrixMeta.from(//
"buttons/globally.send-message2?",
Configuration.screenResolutionProfile.getOffsetButtonSendMessage(), //
0xCEDEB5
);
Metas.Globally.Buttons.closeChatBox = BwMatrixMeta.from(//
"buttons/globally.close-chatbox2?",
Configuration.screenResolutionProfile.getOffsetButtonCloseChatBox(), //
0xFFFFFF
);
Metas.Globally.Dialogs.confirmQuitBattle = BwMatrixMeta.from(//
"dialogs/globally.confirm-quit-battle2?",
Configuration.screenResolutionProfile.getOffsetDialogConfirmQuitBattle(), //
Expand Down
Binary file not shown.
Binary file not shown.

0 comments on commit 686a95a

Please sign in to comment.