Example #1
0
        for player in range(teamsize, teamsize * 2):
            teamMessage += players[player] + " "

        messageQueue.append(teamMessage)

    processMessageQueue()


while runServer:
    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:
        # print(response)
        user = getUser(response)
        message = getMessage(response)
        print(user + " typed: " + message)
        if "!enter" in message:
            if addUser(user):
                sendMessage(s, "{} entered".format(user))

        elif "!reset" in message and "cwittofur" in user:
            resetUsers()

        elif "!matchup" in message and "cwittofur" in user:
            if userCount() < 2:
                sendMessage(s, "Not enough entrants")
            else:
                shipTypeID = getShipTypeID(message)
                shipFactionID = getFactionID(message)
                if shipTypeID == 0:
Example #2
0
def main_loop():
    import os
    import sys
    import ftplib
    import string
    import select
    import fileinput
    from timeit import default_timer as timer
    from time import sleep, time
    from datetime import datetime, timedelta
    from Read import getUser, getMessage, getChannel
    from Socket import openSocket, sendMessage, sendChanMsg, joinChan, quitChan
    from Init import joinRoom
    from Logger import log
    from Api import getUptime, updateMods, restartbot, getSteamStats, convertToSteam64
    from Messagecommands import tryCommands

    s = openSocket()
    joinRoom(s)
    s.setblocking(0)
    readbuffer = ""
    num = 0
    elapsed = 0
    end = 0
    dt_uptime = 0
    downtime = 0
    reload(sys)
    sys.setdefaultencoding("utf8")
    # s.send("CAP REQ :twitch.tv/membership")
    # s.send("CAP REQ :twitch.tv/commands")
    # s.send("CAP REQ :twitch.tv/tags")
    sendChanMsg(s, "finnishforce_", "started")
    while 1:
        start = timer()
        temp = ""
        user = ""

        try:
            getit = s.recv(4096)
            # print getit
            readbuffer = readbuffer + getit
            temp = string.split(readbuffer, "\n")
            readbuffer = temp.pop()
        except:
            sleep(0.5)

        if temp != "":
            for line in temp:
                try:

                    if "PING :tmi.twitch.tv" in line.strip():
                        s.send("PONG :tmi.twitch.tv\r\n")
                        break
                    else:
                        if "PRIVMSG" in getit:
                            user = getUser(line).encode("utf8")
                            message = getMessage(line).encode("utf8")
                            chan = getChannel(line).encode("utf8")
                            time = datetime.now().strftime("%Y-%d-%m %H:%M:%S")
                            toLog = user.decode("utf-8") + ": " + message.decode("utf-8")
                            log(toLog, chan)
                        else:
                            sleep(0.1)
                except:
                    print "error ping"

        if temp != "":
            if "PRIVMSG" in getit:
                tryCommands(s, chan, user, message)

                # does not work after adding messagecommands.py, need new implementation
                # if message.startswith("!softresetbot"):
                #    if user.strip().lower() == "finnishforce_":
                #        sendChanMsg(s, chan, "DONE!")
                #        execfile("/home/pi/Desktop/ForceBotti/Run.py")

        end = timer()
        elapsed = elapsed + (end - start)
        if elapsed >= 300:
            s.send("PONG :tmi.twitch.tv\r\n")
            elapsed = 0
Example #3
0
while True:
    schedule.run_continuously()

    readbuffer = readbuffer + s.recv(1024)
    temp = string.split(readbuffer, "\n")
    readbuffer = temp.pop()

    for line in temp:
        print(line)
        if "PING" in line:
            s.send(line.replace("PING", "PONG"))
            break

        user = getUser(line)
        message = getMessage(line)
        print user + " typed :" + message

        if (sum(pattern in message for pattern in PATT) == 1):
            if (message.rstrip() == leftKey):
                leftKeyCounter = leftKeyCounter + 1
                print "left : %s" % leftKeyCounter
            if (message.rstrip() == rightKey):
                rightKeyCounter = rightKeyCounter + 1
                print "right : %s" % rightKeyCounter
            if (message.rstrip() == frontKey):
                frontKeyCounter = frontKeyCounter + 1
                print "front : %s" % frontKeyCounter
            if (message.rstrip() == backKey):
                backKeyCounter = backKeyCounter + 1
                print "back : %s" % backKeyCounter
Example #4
0
#I WAS BORED WHEN I MADE THIS
#Copyright please Fahkzy

while True:
		readbuffer = readbuffer + s.recv(4096)
		temp = string.split(readbuffer, "\n")
		readbuffer = temp.pop()
		
		for line in temp:
			print(line)
			if "PING" in line:
				s.send(line.replace("PING", "PONG"))
				sendMessage(s, "I just recieved a ping, and sent back a pong!")
				break
			user = getUser(line)
			message = getMessage(line).upper()
			print user + " typed :" + message
			#You suck and bad
			if "YOU SUCK" in message in message:
				sendMessage(s, "No, you suck!" + user)
				break
			#trade
			if "!TRADE" in message:
				sendMessage(s, "Fahkzy's trade link: https://steamcommunity.com/tradeoffer/new/?partner=65390294&token=efmHK3WH")
				break
			#Help Command
			if "!HELP" in message:
				sendMessage(s, "I am a lazy developer.")
				sendMessage(s, "The current commands:")
				sendMessage(s, "!help, !rules, !trade, !source, and !uptime")
				sendMessage(s, "If it breaks... Well shit, I coded this in a hour")
Example #5
0
    def get_votes(self):

        try:
            chat_data = self.s.recv(1024)
        except socket.timeout:
            self.after(500, self.get_votes)
            return

        self.readbuffer = self.readbuffer + chat_data
        print("Reading successful")
        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

        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 "!options" in message and user == CHANNEL:

                # Setting up the question/options to vote on
                # This is a bit of a work in progress

                theQuestion = message.split('? ', 1)[0] + "?"
                theQuestion2 = theQuestion.replace("!options", "")

                theOptions = message.split('? ', 1)[1]

                a = theOptions.split(' ', 4)[0]
                b = theOptions.split(' ', 4)[1]
                c = theOptions.split(' ', 4)[2]

                sendMessage(
                    self.s,
                    "Vote with: !" + str(a) + " !" + str(b) + " !" + str(c))

                self.questionUpdated = str(theQuestion2)
                self.optionA = str(a)
                self.optionB = str(b)
                self.optionC = str(c)

                # create empty options, needs a fix
                if "empty" in self.optionA:
                    self.optionA = " "

                self.voteAamount = 0
                self.voteBamount = 0
                self.voteCamount = 0

                self.alreadyVoted = []

                self.update_tekst()
                time.sleep(1)
                self.update()
                break

                #to do: Wrap if statements in separate functions
            if "!" + self.optionA in message and user != IDENT:
                self.voteAamount += 1
                print(self.voteAamount)
                self.update_tekst()
                time.sleep(1)
                self.update()
                break

            if "!" + self.optionB in message and user != IDENT:
                self.voteBamount += 1
                print(self.voteBamount)
                self.update_tekst()
                time.sleep(1)
                self.update()
                break

            if "!" + self.optionC in message and user != IDENT:
                self.voteCamount += 1
                print(self.voteCamount)
                self.update_tekst()
                time.sleep(1)
                self.update()
                break

            if "!reset" in message and user == CHANNEL:
                self.voteAamount = 0
                self.voteBamount = 0
                self.voteCamount = 0

                self.alreadyVoted = []

                self.update_tekst()
                time.sleep(1)
                self.update()

            if "!voteTest" in message and user not in self.alreadyVoted:
                self.voteTestAmount += 1
                self.alreadyVoted.append(user)
                break

            if "!exit" in message and user == CHANNEL:
                exit()

        self.update()
        self.after(500, self.get_votes)
Example #6
0
 def processLine(self, line):
     self.addToList(getUser(line), getMessage(line))
Example #7
0
#loogie()
while True:
        try:
                readbuffer = readbuffer + s.recv(1024).decode('utf-8')
                temp = str.split(readbuffer, "\n")
                readbuffer = temp.pop()

                for line in temp:
                        line = str.rstrip(line)
                        #print(line.encode("utf-8"))
                        if(line[0] == "P"):
                                s.send(bytes("PONG %s\r\n" % line[1], "UTF-8"))
                                print("sent ping")
                                break
                        user = getUser(line)
                        msg = getMessage(line)
                        now = time.time()
                        
                                
                        if now - updatetime > 100:
                                try:
                                        updatetime = time.time()
                                        response = urlopen("https://tmi.twitch.tv/group/user/"+channel+"/chatters")
                                        readable = response.read().decode("utf-8")
                                        chatlist = loads(readable)
                                        chatters = chatlist['chatters']
                                        updatetime = time.time() +100
                                        print("lists updated")
                                except:
                                        pass
                        print(user + " says: " + str(msg))
Example #8
-1
s = openSocket()
joinRoom(s)
readbuffer = ""

greeting = "hey, hi, hello, greetings"
person = "haylee, chat, friends, guys, all, everyone"
greeting = greeting.split(",")
person = person.split(",")
greeted = []
mods = []
trusted = []
wgreeted = open('Files/Greeted.txt', 'a')
tempWhitelist = []


while True:
	readbuffer = readbuffer + s.recv(1024)
        temp = string.split(readbuffer, "\n")
        readbuffer = temp.pop()
	for line in temp:
		#print("Debug: " + line)
                if "PING" in line:
                	s.send(line.replace("PING", "PONG"))
                        print(line)
                        print(line.replace("PING", "PONG"))
			sendMessage(s, "Debug: Ping found and responded too")
                        break
		user = getUser(line)
        	message = getMessage(line)
		chatCommands(readbuffer,s,message,temp,line,user,greeting,person,wgreeted,greeted,trusted,mods,tempWhitelist)