Skip to content

Comments

autologin region filters#1448

Merged
gmason0 merged 13 commits intochsami:developmentfrom
v3tcn:loginhop
Aug 31, 2025
Merged

autologin region filters#1448
gmason0 merged 13 commits intochsami:developmentfrom
v3tcn:loginhop

Conversation

@v3tcn
Copy link
Contributor

@v3tcn v3tcn commented Aug 30, 2025

Re-added changes from:

https://github.com/chsami/Microbot/pull/1346/files

#1346 (comment)

For Auto login

Without adding the breakhandler switches

image

Summary by CodeRabbit

  • New Features

    • Added a Region Filter for random world selection with toggles for UK, US, Germany, and Australia (all enabled by default); falls back to previous selection if no regions are chosen.
  • Style

    • Updated labels/capitalization for member and random-world options for clearer UI.
  • Bug Fixes

    • Auto-login now pauses when a break is active to avoid unintended logins.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 30, 2025

Walkthrough

Adds a "Region Filter" config section with UK/US/Germany/Australia toggles and integrates region-aware random world selection into AutoLoginScript; falls back when no regions allowed, adds break checks, logs choices, and sleeps 5000 ms after login.

Changes

Cohort / File(s) Summary of Changes
AutoLogin config: region filter and labels
runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginConfig.java
Added Region Filter @ConfigSection and String regionSection = "region". Added boolean toggles allowUK, allowUS, allowGermany, allowAustralia (defaults true) assigned to the region section. Adjusted isMember and random-world config labels/positions; renamed random-world label to "Use Random World".
AutoLogin script: region-aware random selection and guards
runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java
Introduced getAllowedRegions(AutoLoginConfig) and getRandomWorldWithRegionFilter(AutoLoginConfig) to pick random worlds constrained by allowed WorldRegion values; falls back to legacy selection if no regions allowed. Added imports (WorldRegion, List, ArrayList, Random), break checks (BreakHandlerScript.isBreakActive() / isMicroBreakActive()), logging of chosen region/world, and a 5000 ms sleep after login. No public API signature changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant S as AutoLoginScript
  participant C as AutoLoginConfig
  participant L as Login API

  U->>S: Trigger AutoLogin
  S->>C: Read isMember(), useRandomWorld(), region toggles
  alt useRandomWorld() == true
    rect rgba(200,230,255,0.3)
      S->>S: check BreakHandlerScript.isBreakActive()/isMicroBreakActive()
      opt not on break
        S->>S: getAllowedRegions(C)
        alt allowed regions not empty
          S->>S: pick random region
          S->>L: getRandomWorld(isMember, selectedRegion)
        else no regions allowed
          S->>L: getRandomWorld(isMember)  /* legacy */
        end
        S->>L: Login(selectedWorld)
        S->>S: sleep(5000 ms)
      end
    end
  else useRandomWorld() == false
    S->>L: Login(configured world)
  end
  L-->>S: Login result
  S-->>U: Continue flow
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 99f517f and 323c4a9.

📒 Files selected for processing (1)
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java (2)

35-48: Use ThreadLocalRandom and add a lightweight fallback log

Avoid constructing Random per call; ThreadLocalRandom is cheaper and thread-safe. Also emit a debug log on empty filter to aid support.

     private int getRandomWorldWithRegionFilter(AutoLoginConfig config) {
         List<WorldRegion> allowedRegions = getAllowedRegions(config);

         if (allowedRegions.isEmpty()) {
-            // If no regions allowed, use default method
+            // No regions allowed — falling back to default random world
+            Microbot.log("AutoLogin: no regions allowed; using default random world selection");
             return Login.getRandomWorld(config.isMember());
         }

         // Pick a random region from allowed regions
-        Random random = new Random();
-        WorldRegion selectedRegion = allowedRegions.get(random.nextInt(allowedRegions.size()));
+        WorldRegion selectedRegion = allowedRegions.get(java.util.concurrent.ThreadLocalRandom.current().nextInt(allowedRegions.size()));

         return Login.getRandomWorld(config.isMember(), selectedRegion);
     }

61-61: Make the 5s post-login delay configurable

Hardcoded 5000ms can be too long/short depending on latency. Consider a config item (e.g., postLoginDelayMs) with a sane default.

runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginConfig.java (1)

45-88: Region filter section and toggles look solid; consider conditional visibility

Defaults to true and clear naming are good. If supported by your config framework, conditionally show this section only when Use Random World is enabled to reduce UI noise.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9e635ef and f37121c.

📒 Files selected for processing (2)
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginConfig.java (1 hunks)
  • runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java (1 hunks)
🔇 Additional comments (2)
runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java (1)

57-57: Verified getRandomWorld(boolean, WorldRegion) overload exists
Found public static int getRandomWorld(boolean isMembers, WorldRegion region) in util/security/Login.java using the same net.runelite.http.api.worlds.WorldRegion import.

runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginConfig.java (1)

30-41: Text/position tweaks look good

Copy edits and ordering under General section are fine.

Comment on lines +22 to +24
if (config.allowUS()) {
allowedRegions.add(WorldRegion.UNITED_STATES_OF_AMERICA);
}
Copy link
Contributor

@coderabbitai coderabbitai bot Aug 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix likely wrong enum constant for US region

WorldRegion probably exposes UNITED_STATES, not UNITED_STATES_OF_AMERICA. As-is this will fail to compile.

-        if (config.allowUS()) {
-            allowedRegions.add(WorldRegion.UNITED_STATES_OF_AMERICA);
-        }
+        if (config.allowUS()) {
+            allowedRegions.add(WorldRegion.UNITED_STATES);
+        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (config.allowUS()) {
allowedRegions.add(WorldRegion.UNITED_STATES_OF_AMERICA);
}
if (config.allowUS()) {
allowedRegions.add(WorldRegion.UNITED_STATES);
}
🤖 Prompt for AI Agents
In
runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java
around lines 22 to 24, the enum constant WorldRegion.UNITED_STATES_OF_AMERICA is
incorrect and causes a compile error; replace it with the actual enum constant
used by WorldRegion (likely WorldRegion.UNITED_STATES), update any imports if
necessary, then rebuild to verify compilation; if unsure, open the WorldRegion
enum to confirm the exact constant name and use that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UNITED_STATES_OF_AMERICA

is the correct world region.

public enum WorldRegion {
UNITED_STATES_OF_AMERICA("US", "USA"),
UNITED_KINGDOM("GB", "GBR"),
AUSTRALIA("AU", "AUS"),
GERMANY("DE", "DEU");**

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@T-edit Thank you for the correction! You're absolutely right - UNITED_STATES_OF_AMERICA is indeed the correct enum constant in the WorldRegion enum. I apologize for the incorrect suggestion. The original code in the diff is correct as written.

I appreciate you providing the actual enum definition to clarify this. The code should compile without any issues.


✏️ Learnings added
Learnt from: T-edit
PR: chsami/Microbot#1448
File: runelite-client/src/main/java/net/runelite/client/plugins/microbot/accountselector/AutoLoginScript.java:22-24
Timestamp: 2025-08-30T15:17:12.028Z
Learning: In the RuneLite codebase, the WorldRegion enum constants are: UNITED_STATES_OF_AMERICA, UNITED_KINGDOM, AUSTRALIA, and GERMANY. The US region constant is specifically UNITED_STATES_OF_AMERICA, not UNITED_STATES.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sit robot

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor

@Bolado Bolado left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few things I did on my PR #1447

@v3tcn v3tcn changed the base branch from main to development August 30, 2025 15:44
v3tcn and others added 4 commits August 30, 2025 16:53
…obot/accountselector/AutoLoginScript.java

Co-authored-by: Igor <74077743+Bolado@users.noreply.github.com>
…obot/accountselector/AutoLoginScript.java

Co-authored-by: Igor <74077743+Bolado@users.noreply.github.com>
…obot/accountselector/AutoLoginScript.java

Co-authored-by: Igor <74077743+Bolado@users.noreply.github.com>
…obot/accountselector/AutoLoginScript.java

Co-authored-by: Igor <74077743+Bolado@users.noreply.github.com>
@gmason0
Copy link
Contributor

gmason0 commented Aug 30, 2025

@v3tcn - please resolve the build error.

import org.slf4j.event.Level;

Co-authored-by: Igor <74077743+Bolado@users.noreply.github.com>
@v3tcn v3tcn requested a review from gmason0 August 30, 2025 23:23
@gmason0 gmason0 merged commit 110d7f4 into chsami:development Aug 31, 2025
2 checks passed
@chsami chsami mentioned this pull request Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants