Hectozar commited on
Commit
bbd628b
·
verified ·
1 Parent(s): 61b7f42

Update lichess-bot-master/lichess-bot.py

Browse files
Files changed (1) hide show
  1. lichess-bot-master/lichess-bot.py +77 -1
lichess-bot-master/lichess-bot.py CHANGED
@@ -1,5 +1,81 @@
1
  """Starting point for lichess-bot."""
 
 
 
 
 
 
2
  from lib.lichess_bot import start_program
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  if __name__ == "__main__":
5
- start_program()
 
 
 
 
 
 
1
  """Starting point for lichess-bot."""
2
+ import os
3
+ import sys
4
+
5
+ # Ensure the local libraries can be imported
6
+ sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
7
+
8
  from lib.lichess_bot import start_program
9
+ from lib import conversation
10
+
11
+ # --- CUSTOM ENGINE COMMANDS & REACTION INTERCEPTORS ---
12
+
13
+ def patch_lichess_bot():
14
+ """Hooks into lichess-bot's event processing to inject your features."""
15
+
16
+ # 1. Store the original message processor from the underlying library
17
+ if not hasattr(conversation.Conversation, "_original_react"):
18
+ conversation.Conversation._original_react = conversation.Conversation.react
19
+
20
+ # 2. Rewrite the reaction method to handle your custom uppercase commands
21
+ def custom_react(self, event, game):
22
+ # Intercept chat messages sent by players or spectators
23
+ if event.get("type") == "chatLine" and event.get("room") == "player":
24
+ username = event.get("username")
25
+ # Avoid the bot replying to its own chat lines
26
+ if username != game.username:
27
+ text = event.get("text", "").strip().lower()
28
+
29
+ if text == "!help":
30
+ self.send_reply("player", "AVAILABLE ACTIONS: !NAME (SHOWS ENGINE GROUP NAME), !EXPLAIN (SHOWS CREDITS), !HELP (SHOWS THIS MESSAGE). SAY 'FAST' OR 'SLOW' IN CHAT TO REQUEST A CHANGE IN PACING.")
31
+ elif text == "!name":
32
+ self.send_reply("player", "CBOT ORIGINAL ENGINES")
33
+ elif text == "!explain":
34
+ self.send_reply("player", "I AM CBOT AND I USE A SPECIAL C++ ENGINE TO MOVE. THIS ENGINE IS CREATED BY @HECTOZAR.")
35
+ elif text == "fast":
36
+ # Updates the active running engine properties instantly
37
+ if hasattr(game, "engine") and game.engine:
38
+ game.engine.movetime = 1
39
+ self.send_reply("player", "SPEED MODE CHANGED! MOVING INSTANTLY.")
40
+ elif text == "slow":
41
+ # Delays search parameters to 5 seconds
42
+ if hasattr(game, "engine") and game.engine:
43
+ game.engine.movetime = 5000
44
+ self.send_reply("player", "SLOW THINKING ENGAGED! MOVING WITH A 5 SECOND DELAY.")
45
+
46
+ # 3. Handle dynamic move evaluation shifts
47
+ elif event.get("type") == "gameState":
48
+ # Retrieve evaluation scores safely from the running state
49
+ moves = event.get("moves", "").split()
50
+ if moves:
51
+ # We can check if an evaluation drop or gain occurred
52
+ # To prevent chat flooding, we tie it to game evaluation snapshots
53
+ pass
54
+
55
+ # 4. Handle clean Uppercase End Game triggers
56
+ elif event.get("type") == "gameFinish":
57
+ winner = event.get("game", {}).get("winner")
58
+ status = event.get("game", {}).get("status", {}).get("name")
59
+
60
+ if status in ["mate", "resign", "outoftime"]:
61
+ if winner == game.username:
62
+ self.send_reply("player", "YOU PLAYED WELL, TRY AGAIN NEXT TIME!")
63
+ else:
64
+ self.send_reply("player", "YOU DID WELL, I WILL TRY TO WIN YOU NEXT TIME")
65
+
66
+ # Hand control back over to the core program loop
67
+ return self._original_react(event, game)
68
+
69
+ # Apply the runtime code override injection
70
+ conversation.Conversation.react = custom_react
71
+
72
+
73
+ # --- RUN PROGRAM ---
74
 
75
  if __name__ == "__main__":
76
+ try:
77
+ patch_lichess_bot()
78
+ except Exception:
79
+ pass # Ensure code injection never blocks main boot up sequencing
80
+
81
+ start_program()