N
N
NickName982020-03-29 09:47:30
Python
NickName98, 2020-03-29 09:47:30

"State changed from starting to crashed" The application is not working, why?

I am writing a twitch bot for a crocodile game. After deploying to Heroku, the application works for a while, but then stops. I do not understand what the problem is. There is nothing in the logs except "State changed from starting to crashed". And locally everything works without errors.

Here is my application:

import config
import utils
import socket
import re
import time
from time import sleep

def main():
    s = socket.socket()
    s.connect((config.HOST, config.PORT))
    s.send("PASS {}\r\n".format(config.PASS).encode("utf-8"))
    s.send("NICK {}\r\n".format(config.NICK).encode("utf-8"))
    s.send("JOIN #{}\r\n".format(config.CHAN).encode("utf-8"))


    chat_message = re.compile(r"^:\w+!\[email protected]\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
    s.send("CAP REQ :twitch.tv/commands\r\n".encode("utf-8"))


    while True:
        response = s.recv(1024).decode("utf-8")

        if response == "PING :tmi.twitch.tv\r\n":
            s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
    
        else:
            username = re.search(r"\w+", response).group(0)
            mess = chat_message.sub("", response)


        n
        if mess.strip() == "!начать" and username == "StreamerName":
            game = True
            word = ""
            count = {}
            utils.message(s, "/me Игра начата!")
            sleep(1)
            while game == True:
                response = s.recv(1024).decode("utf-8")
                if response[0:52] == ":[email protected] WHISPER":
                    username = re.search(r"\w+", response).group(0)
                    word = response[66:]
                    utils.message(s, "/me Cлово установлено!")
                    sleep(1)
                else:
                    username = re.search(r"\w+", response).group(0)
                    mess = chat_message.sub("", response)
                    if mess.lower() == word.lower():
                        utils.message(s, '/me @StreamerName {} отгадал слово!!!'.format(username))
                        sleep(1)
                        utils.message(s, "@{} отправь новое слово стримеру!".format(username))
                        sleep(1)
                        word = ""
                        if username in count:
                            count[username]+=1
                        else: count.update({username: 1})    
                    if mess.strip() == "!закончить" and username == "StreamerName":
                        utils.message(s, "/me Игра окончена!")
                        sleep(1)
                        game = False
                        result = ""
                        for key, value in count.items():
                            result+= "{}: {}  ".format(key, value)
                        utils.message(s, result)

if __name__ == "__main__":
    main()


Hope you can help me)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2020-03-29
@2ord

To simulate work in Heroku, you need to run heroku local.
There must be something wrong with the web application process. It must listen on the same port as the Procfile.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question