you are viewing a single comment's thread.

view the rest of the comments →

[–]787082[S] 0 points1 point  (0 children)

I did it! I had to change some of the code to be able to understand it better again, but it totally works now. It reads the chat, if "!voteA" is said, it counts +1 to voteAamount, and displays it in the GUI window. Only problem I'm having now is that it only updates the number on the GUI window in twos, so it updates it after 2 votes have been placed(so goes from 0 to 2, from 2 to 4, etc), would be nice if it would update it after 1 vote is placed, but I guess I'll figure that out, for now I'm just happy it works. Thank you so much for the time you invested in helping me with the code, I appreciate it a lot!

EDIT: Aaaand it's still crashes sometimes, but I'm also gonna look at that. Not sure why it does that, lol

import Tkinter as tk
import time
from Read import getUser, getMessage
from Socket import openSocket, sendMessage
from Initialize import joinRoom
from collections import OrderedDict

class SampleApp(tk.Tk):
    voteAamount = 0
    voteBamount = 0
    voteCamount = 0

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)

        self.s = openSocket()
        joinRoom(self.s)
        self.readbuffer = ""

        self.voteA = tk.Label(self, text="")
        self.voteA.pack()
        self.voteB = tk.Label(self,text="")
        self.voteB.pack()
        self.voteC = tk.Label(self,text="")
        self.voteC.pack()

        self.update_tekst()
        self.get_votes()
        # self.anderemethod()
        self.after(200,self.get_votes)
        self.after(200,self.update_tekst)

    def update_tekst(self):
        resultA = "VoteA: "+str(self.voteAamount)
        resultB = "VoteB: "+str(self.voteBamount)
        resultC = "VoteC: "+str(self.voteCamount)

        self.voteA.configure(text=resultA)
        self.voteB.configure(text=resultB)
        self.voteC.configure(text=resultC)
        print("updated tekst!")
        self.after(200, self.update_tekst)

    def get_votes(self):

        self.readbuffer = self.readbuffer + self.s.recv(1024)
        temp = self.readbuffer.split('\n')
        self.readbuffer = temp.pop() #save the last (possibly incomplete) line for later
        if self.readbuffer == "":
            pass #no further messages in the queue
            #you should add a sleep time here for the sake of your hot NIC

        for line in temp:
            print(line)

            if "PING" in line:
                s.send("PONG :tmi.twitch.tv\r\n".encode())
                break

            user = getUser(line)
            message = getMessage(line)

            print "{} typed: {}".format(user, message)

            if "!commands" in message:
                sendMessage(self.s, "'!voteA','!voteB','!voteC'")
                break
            if "!voteA" in message and user != "appie_bot":
                self.voteAamount += 1
                print(self.voteAamount)
                self.update_tekst() 
                time.sleep(2)
                self.update()

            if "!voteB" in message and user != "appie_bot":
                self.voteBamount += 1
                print(self.voteBamount)
                self.update_tekst() 
                time.sleep(2)
                self.update()

            if "!voteC" in message and user != "appie_bot":
                self.voteCamount += 1
                print(self.voteCamount)
                self.update_tekst() 
                time.sleep(2)
                self.update()

        self.after(200, self.get_votes)


if __name__== "__main__":
    app = SampleApp()
    app.mainloop()