Skip to content

Commit

Permalink
Update conversation.py
Browse files Browse the repository at this point in the history
Please check the latest Lichess API documentations .
  • Loading branch information
ScriptDeveloper2004 authored Jan 28, 2024
1 parent 30c68e9 commit f0a6f14
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ def __init__(self, game, engine, xhr, version, challenge_queue):
self.engine = engine
self.xhr = xhr
self.version = version
self.challengers = challenge_queue
self.challenge_queue = challenge_queue

command_prefix = "!"

def react(self, line, game):
def react(self, line):
logger.info(f'*** {self.game.url()} [{line.room}] {line.username}: {line.text.encode("utf-8")}')
if line.text[0] == self.command_prefix:
self.command(line, game, line.text[1:].lower())
if line.text.startswith(self.command_prefix):
self.command(line, line.text[1:].lower())

def command(self, line, game, cmd):
def command(self, line, cmd):
if cmd == "commands" or cmd == "help":
self.send_reply(line, "Supported commands: !wait (only applicable at the start of the game), !name, !howto, !eval, !queue")
elif cmd == "wait" and game.is_abortable():
game.ping(60, 120, 120)
elif cmd == "wait" and self.game['state']['status'] == 'started':
self.game.ping(60, 120, 120)
self.send_reply(line, "Waiting 60 seconds...")
elif cmd == "name":
name = game.me.name
name = self.game.me['name']
self.send_reply(line, f"{name} running {self.engine.name()} (Lishogi-Bot v{self.version})")
elif cmd == "howto":
self.send_reply(line, "How to run: https://github.com/TheYoBots/Lishogi-Bot")
Expand All @@ -35,14 +35,14 @@ def command(self, line, game, cmd):
elif cmd == "eval":
self.send_reply(line, "I don't tell that to my opponent, sorry.")
elif cmd == "queue":
if self.challengers:
challengers = ", ".join([f"@{challenger.challenger_name}" for challenger in reversed(self.challengers)])
if self.challenge_queue:
challengers = ", ".join([f"@{challenger['challenger']['name']}" for challenger in reversed(self.challenge_queue)])
self.send_reply(line, f"Challenge queue: {challengers}")
else:
self.send_reply(line, "No challenges queued.")

def send_reply(self, line, reply):
self.xhr.chat(self.game.id, line.room, reply)
self.xhr.chat(self.game['id'], line.room, reply)

def send_message(self, room, message):
if message:
Expand All @@ -53,4 +53,4 @@ class ChatLine:
def __init__(self, json):
self.room = json.get("room")
self.username = json.get("username")
self.text = json.get("text")
self.text = json.get("text")

0 comments on commit f0a6f14

Please sign in to comment.