From a43c13c2e5e7f5a4dbbfd0912f46ef3bb240545b Mon Sep 17 00:00:00 2001
From: retoor <retoor@molodetz.nl>
Date: Sat, 11 Jan 2025 18:40:17 +0100
Subject: [PATCH] Less spam, easier for server.

---
 src/ragnar/bot.py |  6 ++++--
 src/ragnar/cli.py | 28 +++++++++++++---------------
 2 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/ragnar/bot.py b/src/ragnar/bot.py
index 5ec638d..4cce040 100644
--- a/src/ragnar/bot.py
+++ b/src/ragnar/bot.py
@@ -5,6 +5,7 @@ import time
 from ragnar import log
 from ragnar.api import Api
 from ragnar.cache import method_cache
+from ragnar.victoria import vic
 
 
 class Bot:
@@ -55,7 +56,7 @@ class Bot:
         self.api = Api(username=self.username, password=self.password)
 
     def rsleepii(self):
-        time.sleep(random.randint(10, 60))
+        time.sleep(random.randint(1, 2))
 
     @method_cache
     def login(self):
@@ -172,5 +173,6 @@ class Bot:
             self.rant_history.append(rant["id"])
 
     def down_vote_rant(self, rant):
-        log.warning("Downvoting rant by {}.".format(rant["user_username"]))
+        vic.dr_downvote_rant(rant["id"],5)
+        log.warning("Downvoting rant by {} for 5 times.".format(rant["user_username"]))
         log.debug("Vote result: ".format(self.api.post_rant_vote(rant["id"], -1)))
diff --git a/src/ragnar/cli.py b/src/ragnar/cli.py
index db05038..60ff4ec 100644
--- a/src/ragnar/cli.py
+++ b/src/ragnar/cli.py
@@ -4,7 +4,7 @@ from concurrent.futures import ThreadPoolExecutor as Executor
 from ragnar import log
 from ragnar.bot import Bot
 from ragnar.victoria import vic
-
+import time 
 
 def parse_args():
     parser = argparse.ArgumentParser(description="Process username and password.")
@@ -15,26 +15,24 @@ def parse_args():
     return parser.parse_args()
 
 
-def bot_task(username, password):
-    log.info(f"Created new bot runniner. Username: {username}")
-    while True:
-        try:
-            bot = Bot(username=username, password=password)
-            bot.login()
-            bot.fight()
-        except Exception as ex:
-            log.critical(ex, exc_info=True)
-
 
 def main():
     args = parse_args()
     usernames = vic.get_friends()
 
-    with Executor(len(usernames)) as executor:
+    while True:
         for username in usernames:
-            executor.submit(bot_task, f"{username}@molodetz.nl", args.password)
-        executor.shutdown(wait=True)
-
+            time_start = time.time()
+            try:
+                log.info(f"Created new bot runner. Username: {username}")
+                bot = Bot(username=username, password=args.password)
+                bot.login()
+                bot.fight()
+            except Exception as ex:
+                log.critical(ex, exc_info=True)
+                time.sleep(1)
+            time_duration = time.time() - time_start 
+            log.info(f"Bot {username} finished in {time_duration} seconds.")
 
 def run():
     main()