示例#1
0
def loop():
    twitch = Chat()
    twitch.connect()
    time.sleep(3)
    while True:
        try:
            response = twitch.get_message()
            #DEBUG
            #print("Reponse:"+response)
            if response == "PING :tmi.twitch.tv\r\n":
                twitch.pong()
            elif response:
                evaluate_message(response)
        except socket.timeout:
            debug_event = True
            #print("Socket Timed Out!")

        except socket.error:
            print("Socket Error, Connection closed!")
            time.sleep(1)
            twitch.connect()
        except Exception as e:
            print("Unknown error")
            print(e)
        #TODO: Find a better sleep cycle. Rate limiting already in place
        time.sleep(1 / cfg.RATE)
示例#2
0
def msgs():
    form = SendMessage(request.form)
    if request.method == 'POST' and form.validate():
        message = form.message.data
        msg = Chat(message)
        msg_db = root.child('chathistory')
        msg_db.push({'message': msg.get_message()})

        flash('Message Sent', 'success')

    chathist = root.child('chathistory').get()
    list = []
    for chatid in chathist:
        eachmsg = chathist[chatid]
        print(eachmsg)
        msg = Chat(eachmsg['message'])
        msg.set_chatid(chatid)
        print(msg.get_chatid())
        list.append(msg)
    print(list)
    print(chathist)

    return render_template('chat.html', form=form, chathist=list)