api icon indicating copy to clipboard operation
api copied to clipboard

Message from bot does not appear in the in-game chat before the first move

Open quiet23 opened this issue 4 years ago • 1 comments

Hi,

if my bot sends a message to the chat before the first move is made in the game, the message does not appear in the chat, despite the chatLine event with the message echoes back in the Bot game state API connection.

Log from the bot:

# Opening bot game state connection
03:31:13,79 MainThread DEBUG MakeAPICall() endpoint_url = /api/bot/game/stream/9wuj1IsL, method = GET
03:31:13,79 MainThread DEBUG MakeAPICall() headers = <CIMultiDict('Authorization': 'Bearer <cut>')>
03:31:13,79 MainThread DEBUG MakeAPICall() data = {}
03:31:13,160 MainThread DEBUG MakeAPICall() response code = 200

[skip]

# Sending message to the chat
03:31:13,162 MainThread DEBUG MakeAPICall() endpoint_url = /api/bot/game/9wuj1IsL/chat, method = POST
03:31:13,162 MainThread DEBUG MakeAPICall() headers = <CIMultiDict('Authorization': 'Bearer <cut>')>
03:31:13,162 MainThread DEBUG MakeAPICall() data = {'room': 'player', 'text': "Greetings, let's start the game!"}
03:31:13,389 MainThread DEBUG MakeAPICall() response code = 200

# The message echoes back through the game state connection
`03:31:13,393 MainThread DEBUG PlayGame() in-game event received: b'{"type":"chatLine","room":"player","username":"CheckmatePracticeBot","text":"Greetings, let\'s start the game!"}\n'

After the game finishes this message is sent, and it appears in the chat, so seems like only messages before the first move are lost:

03:31:19,711 MainThread DEBUG MakeAPICall() endpoint_url = /api/bot/game/9wuj1IsL/chat, method = POST
03:31:19,711 MainThread DEBUG MakeAPICall() headers = <CIMultiDict('Authorization': 'Bearer <cut>')>
03:31:19,711 MainThread DEBUG MakeAPICall() data = {'room': 'player', 'text': "It's a draw!"}

quiet23 avatar Nov 03 '21 23:11 quiet23

Seems like adding 1 sec. delay between opening bot game state connection and sending message makes it reliably appear. 0.2 sec. delay didn't help.

quiet23 avatar Nov 04 '21 22:11 quiet23

I cannot reproduce using this code:

class Req:

    def __init__(self) -> None:
        http = requests.Session()
        http.mount("https://", ADAPTER)
        http.mount("http://", ADAPTER)
        self.http = http

        print("streaming events")
        r = self.http.get("http://localhost:9663/api/stream/event", 
                            headers = {"Authorization": f"Bearer {TOKEN}"}, stream=True)
        for line in r.iter_lines():
            print(line)
            if line:
                event = json.loads(line)
                if event["type"] == "gameStart":
                    gameId = event["game"]["id"]
                    break

        print("sending chat")
        r = self.http.post(f"http://localhost:9663/api/bot/game/{gameId}/chat", 
                            headers = {"Authorization": f"Bearer {TOKEN}"}, 
                            data={"room": "player", "text": "message as soon as the game started!"})
        print(r.status_code)
        print(r)

Considering the age of the issue closing as completed for now

kraktus avatar Apr 21 '23 14:04 kraktus