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
import parser import time import datetime import string from Read import getUser, getMessage from Socket import openSocket, sendMessage from Init import joinRoom nameint = 0 s = openSocket() joinRoom(s) readbuffer = "" start_time = time.time() #I KNOW HOW SHIT THIS BOT IS, BUT HONESTLY. I DON'T CARE :D #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()
def main_loop(): s = openSocket() joinRoom(s) s.setblocking(0) chan = "" user = "" modstatus = False message = "" msglog = {} s.send("CAP REQ :twitch.tv/tags\n") readbuffer = "" elapsed = 0 elapsed2 = 0 toldit = 0 spam = 1 adtime = 300 checkban = "" prevline = "" votenum = 0 done1, done2, done3 = 0, 0, 0 choices = {} votes = {} voters = {} voteon = {} options = {} msglogfreq = 500 prevtemp = "" approved = [owner, 'mmorz', 'bulftrik'] cooldownlist = [] cdlist = [] cdtimer = 0 modonlycmd = 0 kuismafix = ["strongkuisma", "harshmouse"] gamerequs = {} dik = refreshCmds() writePidFile() reload(sys) sys.setdefaultencoding("utf-8") sendChanMsg(s, owner, "started") while 1: start = idiotclock() temp = "" try: getit = s.recv(4096) readbuffer = readbuffer + getit temp = string.split(readbuffer, "\n") readbuffer = temp.pop() except: sleep(0.1) if temp != "": for line in temp: try: if "PING" in line: s.send("PONG :tmi.twitch.tv\r\n") else: if "PRIVMSG" in getit: user = getUser(line).encode('utf8') message = getMessage(line).encode('utf8') chan = getChannel(line).encode('utf8') modstatus = getMod(line) user = user.strip().lower() message = message.strip() chan = chan.strip().lower() #time = datetime.now().strftime('%Y-%d-%m %H:%M:%S') if "WHISPER" in getit: user = getUserWhisper(line).encode('utf8') message = getMessageWhisper(line).encode('utf8') chan = "jtv," + user modstatus = False if user == "finnishforce_": modstatus = True #msglog[chan].append(strftime('%x %X') + "<{0}>: {1}".format(user, message)) #print msglog except: pass try: msglog[chan] except: msglog[chan] = [''] pass end = idiotclock() #elapsed = elapsed + (end-start) elapsed2 = elapsed2 + (end - start) #if(elapsed >= 300): # s.send("PONG :tmi.twitch.tv\r\n") # elapsed = 0 if (elapsed2 >= 30): try: cdlist.pop(0) elapsed2 = 0 except: pass if (temp != "" and ("PRIVMSG" or "WHISPER" in getit) and checkban != (user + chan + message)): if modstatus or user == chan or user in approved: modstatus = True checkban = user + chan + message msglog[chan].append( strftime('%x %X') + "<{0}>: {1}".format(user, message)) if len(msglog[chan]) > msglogfreq: log(msglog[chan], chan) del msglog[chan] if message.startswith(''): if (len(cooldownlist) >= 1): cooldownlist.pop(0) try: voteon[chan] except Exception, e: pass voteon[chan] = 0 voters[chan] = [''] #cdtimer = timer() cooldownlist.append(checkban) if message.startswith(''): #handleMsg(s, dik, modstatus, chan, user, message) #tryCommands(s, chan, user, modstatus, message) Process(target=handleMsg, args=( s, dik, modstatus, chan, user, message, )).start() Process(target=tryCommands, args=( s, chan, user, modstatus, message, )).start() #p1.start() #p2.start() if "has won the giveaway" in message and user.lower( ) == "nightbot": try: search, b = message.split(" ", 1) sendChanMsg(s, chan, getFollowStatus(search, chan)) except Exception, e: print "nightbot giveaway detection error:", e if message.startswith("!freq") and user == owner: try: a, b = message.split("!freq ") msglogfreq = int(b) except Exception, e: print "logfreq error:", e if message.startswith("!kuismafix") and (modstatus or user == owner): try: if chan not in kuismafix: kuismafix.append(chan) sendChanMsg(s, chan, "Channel has been kuismafixed") elif chan in kuismafix: kuismafix.remove(chan) sendChanMsg(s, chan, "Kuismafix has been lifted") except Exception, e: print "kuismafix error:", e
import string from Read import getUser, getMessage from Socket import openSocket, sendMessage from Init import joinRoom import stepper as stepper s = openSocket() joinRoom(s) readbuffer = "" stepper.setup() try: while True: readbuffer = readbuffer + s.recv(1024) temp = string.split(readbuffer, "\n") readbuffer = temp.pop() # TODO: look into storing the commands in a multi deminsion array[[username],[command]]. this will allow pausing of the motors and displaying username with what command was performed. for line in temp: print(line) if "PING" in line: print("sending pong back") s.send(line.replace("PING", "PONG")) break user = getUser(line) message = getMessage(line) print user + " typed :" + message if "You Suck" in message: sendMessage(s, "No, you suck!") break if "left\r" == message: print("MOOOOVE left") stepper.moveLeft()