Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Fixed the Bot.stop() function from failing when called explicitly within script #125

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/model/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ def stop(self):
"""
self.log_msg("Stopping script.")
if self.status != BotStatus.STOPPED:
self.set_status(BotStatus.STOPPED)
self.thread.stop()
self.thread.join()
self.set_status(BotStatus.STOPPED)
else:
self.log_msg("Bot is already stopped.")

Expand Down
8 changes: 3 additions & 5 deletions src/model/near_reality/combat.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def main_loop(self): # sourcery skip: low-code-quality
while not self.is_in_combat():
if timeout <= 0:
self.log_msg("Timed out looking for NPC.")
self.set_status(BotStatus.STOPPED)
return
self.stop()
npc: RuneLiteObject = self.get_nearest_tagged_NPC()
if npc is not None:
self.log_msg("Attacking NPC...")
Expand All @@ -80,8 +79,7 @@ def main_loop(self): # sourcery skip: low-code-quality
while self.is_in_combat():
if timeout <= 0:
self.log_msg("Timed out fighting NPC.")
self.set_status(BotStatus.STOPPED)
return
self.stop()
time.sleep(2)
timeout -= 2

Expand All @@ -92,4 +90,4 @@ def main_loop(self): # sourcery skip: low-code-quality
self.update_progress(1)
self.log_msg("Bot has completed all of its iterations.")
self.logout()
self.set_status(BotStatus.STOPPED)
self.stop()
5 changes: 2 additions & 3 deletions src/model/near_reality/fishing.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def main_loop(self): # sourcery skip: low-code-quality, use-named-expression
time.sleep(2)
if failed_searches > 10:
self.log_msg("Failed to find fishing spot.")
self.set_status(BotStatus.STOPPED)
return
self.stop()
else:
self.log_msg("Clicking fishing spot...")
self.mouse.move_to(spot.random_point())
Expand All @@ -80,4 +79,4 @@ def main_loop(self): # sourcery skip: low-code-quality, use-named-expression
self.update_progress(1)
self.log_msg("Finished.")
self.logout()
self.set_status(BotStatus.STOPPED)
self.stop()
5 changes: 1 addition & 4 deletions src/model/near_reality/mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,13 @@ def main_loop(self): # sourcery skip: low-code-quality
# Check to logout
if self.logout_on_friends and self.friends_nearby():
self.__logout("Friends nearby. Logging out.")
return

# Get the rocks
rocks: List[RuneLiteObject] = self.get_all_tagged_in_rect(self.win.game_view, clr.PINK)
if not rocks:
failed_searches += 1
if failed_searches > 5:
self.__logout("Failed to find a rock to mine. Logging out.")
self.set_status(BotStatus.STOPPED)
return
time.sleep(1)
continue

Expand All @@ -95,4 +92,4 @@ def main_loop(self): # sourcery skip: low-code-quality
def __logout(self, msg: str):
self.log_msg(msg)
self.logout()
self.set_status(BotStatus.STOPPED)
self.stop()
7 changes: 2 additions & 5 deletions src/model/near_reality/pickpocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ def main_loop(self): # sourcery skip: low-code-quality, use-named-expression
self.mouse.click()
else:
self.__logout(f"Out of food. Bot ran for {(time.time() - start_time) / 60} minutes.")
return

# Check if we should drop inventory
if self.should_drop_inv and api.get_is_inv_full():
Expand Down Expand Up @@ -156,7 +155,6 @@ def main_loop(self): # sourcery skip: low-code-quality, use-named-expression
time.sleep(1)
if npc_search_fail_count > 39:
self.__logout(f"No NPC found for {npc_search_fail_count} seconds. Bot ran for {(time.time() - start_time) / 60} minutes.")
return

# Click coin pouch
stack_size = api.get_inv_item_stack_amount(item_ids.coin_pouches)
Expand All @@ -182,8 +180,7 @@ def main_loop(self): # sourcery skip: low-code-quality, use-named-expression

# Check for mods
if self.logout_on_friends and self.friends_nearby():
self.__logout(f"Friends detected nearby. Bot ran for {(time.time() - start_time) / 60} minutes.")
return
self.__logout(f"Friends detected nearby. Bot ran for {round((time.time() - start_time) / 60)} minutes.")

# Update progress
self.update_progress((time.time() - start_time) / end_time)
Expand All @@ -194,4 +191,4 @@ def main_loop(self): # sourcery skip: low-code-quality, use-named-expression
def __logout(self, msg):
self.log_msg(msg)
self.logout()
self.set_status(BotStatus.STOPPED)
self.stop()
4 changes: 1 addition & 3 deletions src/model/near_reality/woodcutting.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ def main_loop(self): # sourcery skip: low-code-quality
# Check to logout
if self.logout_on_friends and self.friends_nearby():
self.__logout("Friends nearby. Logging out.")
return

# Find a tree
tree = self.get_nearest_tag(clr.PINK)
if tree is None:
failed_searches += 1
if failed_searches > 10:
self.__logout("No tagged trees found. Logging out.")
return
time.sleep(1)
continue

Expand Down Expand Up @@ -100,4 +98,4 @@ def main_loop(self): # sourcery skip: low-code-quality
def __logout(self, msg):
self.log_msg(msg)
self.logout()
self.set_status(BotStatus.STOPPED)
self.stop()
3 changes: 1 addition & 2 deletions src/model/osrs/woodcutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ def main_loop(self):
if failed_searches > 60:
# If we've been searching for a whole minute...
self.__logout("No tagged trees found. Logging out.")
return
time.sleep(1)
continue
failed_searches = 0 # If code got here, a tree was found
Expand Down Expand Up @@ -102,7 +101,7 @@ def main_loop(self):
def __logout(self, msg):
self.log_msg(msg)
self.logout()
self.set_status(BotStatus.STOPPED)
self.stop()

def __move_mouse_to_nearest_tree(self, next_nearest=False):
"""
Expand Down
3 changes: 1 addition & 2 deletions src/model/zaros/woodcutting.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def main_loop(self):
if failed_searches > 60:
# If we've been searching for a whole minute...
self.__logout("No tagged trees found. Logging out.")
return
time.sleep(1)
continue
failed_searches = 0 # If code got here, a tree was found
Expand Down Expand Up @@ -106,7 +105,7 @@ def main_loop(self):
def __logout(self, msg):
self.log_msg(msg)
self.logout()
self.set_status(BotStatus.STOPPED)
self.stop()

def __inv_is_full(self):
"""
Expand Down