def run(): s = openSocket() userListFile = open("userlist.txt", "w") joinRoom(s) readbuffer = "" while True: readbuffer = readbuffer + s.recv(1024).decode() temp = readbuffer.split("\n") readbuffer = temp.pop() for line in temp: print(line) if "PING" in line: s.send((line.replace("PING", "PONG")+ "\r\n").encode("utf-8")) break user = getUser(line) message = getMessage(line) print (user + " typed :" + message) #Greet New User if isUserNew(user): welcomeNewUser(s,user) users.append(user) userListFile.write(user + " ") print(users)
def createUsers(): global currentUserIndex currentUserIndex = 0 global users users = [] for num, name in enumerate(usernames): users.append(openSocket(num))
def __init__(self, *args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.overrideredirect(True) self['background'] = 'black' self.geometry("+0+20") self.attributes("-alpha", 1) self.s = openSocket() joinRoom(self.s) self.readbuffer = "" self.questionLabel = tk.Label(self, text="", bg="black", fg="white", font="HouseSlant-Regular 15", anchor="w") self.questionLabel.pack() self.voteA = tk.Label(self, text="", bg="black", fg="white", font="HouseSlant-Regular 30", anchor="w") self.voteA.pack() self.voteB = tk.Label(self, text="", bg="black", fg="white", font="HouseSlant-Regular 30", anchor="w") self.voteB.pack() self.voteC = tk.Label(self, text="", bg="black", fg="white", font="HouseSlant-Regular 30", anchor="w") self.voteC.pack() self.update_tekst() self.get_votes()
def main(): s = openSocket() joinRoom(s) channel = getChannel() p = re.compile("!([a-zA-Z]+)") #Setting up pattern to match commands cd = getDict() #Dictionary of Commands td = {c: 0 for c in cd} #Initializing dictionary of most recent commands ld = getLims() #Dictionary of time limits for commands followtime = time.time() readBuffer, user, message = "", "", "" #Initializing needed variables try: while True: readBuffer = readBuffer + s.recv(1024).decode("UTF-8") temp = readBuffer.split("\n") readBuffer = temp.pop() followtime = checkFollow(s, followtime) for line in temp: if "PING :tmi.twitch.tv" in line: if "PING :tmi.twitch.tv" == line[:19]: print(line) sysMessage(s, (line.replace("PING", "PONG"))) else: sendMessage(s, "Nice try.") #Preventing shennanigans else: user = getUser(line) message = getMessage(line) print(user + " typed :" + message) m = p.match(message) #Pattern matching for commands if m: td = recognize(s, m.group(1), cd, td, ld) #Checking if the broadcaster called for the bot to quit if "!quit" in message and user == channel: return finally: closeSocket(s) return
from Socket import openSocket, sendMessage from Initialize import joinRoom from Settings import OWNER import time from User import users, games from Time_functions import stopWatch, checkUptime from Info_functions import getMessage, getUser, Console, checkUser from Bad_words import timeOut, bad_words from Commands import checkCommand, commands s = openSocket() joinRoom(s) start = time.time() readbuffer = "" while True: try: readbuffer = s.recv(1024) readbuffer = readbuffer.decode() temp = readbuffer.split("\n") readbuffer = readbuffer.encode() readbuffer = temp.pop() except: temp = "" for line in temp: if line == "": break # So twitch doesn't timeout the bot. if "PING" in line and Console(line): msg = "PONG tmi.twitch.tv\r\n".encode()
def chatBot(chan, newjoin): lasttip = datetime.datetime.now() s = openSocket(chan) joinRoom(s, chan, newjoin) readbuffer = "" close = False while close != True: lastping = datetime.datetime.now() readbuffer = readbuffer + s.recv(1024).decode("UTF-8") temp = str.split(readbuffer, "\n") readbuffer = temp.pop() js = open('users.txt') users = json.load(js) js.close() # User Settings Go Here caps = users[chan][0] if lasttip < datetime.datetime.now() - datetime.timedelta(hours=1): lasttip = datetime.datetime.now() commandFROGTip(s, chan, caps) for line in temp: print(line) # reply to IRC PING's so we dont get disconnected if "PING" in line: s.sendall(bytes("PONG :tmi.twitch.tv\r\n", "UTF-8")) lastping = datetime.datetime.now() break user = getUser(line) message = getMessage(line) print(user + " typed :" + message) #Listen for !frogtip command if re.search(r'^!frogtip', message, re.IGNORECASE): if lasttip < datetime.datetime.now() - datetime.timedelta( seconds=15): commandFROGTip(s, chan, caps) lasttip = datetime.datetime.now() break if re.search(r'^!join', message, re.IGNORECASE): print(chan) if chan == IDENT.lower(): if user not in users: newjoin = True users[user] = [0] sendMessage( s, chan, "Joining " + user + "'s channel. If you would like FROGTips to hop off, type !leave in your channel while FROG is nearby." ) joinChannel(user, newjoin) with open('users.txt', 'w') as file: file.write(json.dumps(users)) file.close else: sendMessage( s, chan, "FROGTips is already in this channel. Please do not hog FROG" ) break else: sendMessage( s, chan, "To have FROGTips join your channel, say !join in the chat at https://twitch.tv/frogtips" ) break break if re.search(r'^!leave', message, re.IGNORECASE): if chan == user: sendMessage(s, chan, "Leaving " + user + "'s channel. D:") del users[user] print(users) with open('users.txt', 'w') as file: file.write(json.dumps(users)) file.close close = True else: sendMessage(s, chan, "Hop off, you aren't the channel owner.") break if re.search(r'^!caps', message, re.IGNORECASE): if chan == IDENT.lower(): sendMessage(s, chan, "Toggling CAPS in " + user + "'s channel.") print(users[user][0]) if users[user][0] == 1: users[user][0] = 0 with open('users.txt', 'w') as file: file.write(json.dumps(users)) file.close else: users[user][0] = 1 with open('users.txt', 'w') as file: file.write(json.dumps(users)) file.close break break time.sleep(0.2) if lastping < datetime.datetime.now() - datetime.timedelta(minutes=7): chatBot(chan, newjoin) close = True pass
ptr1 += msgCacheLength # increment the plot by the volume of messages received # print(data1) # print(data2) # print(data3) # print(data4) curve1.setData(data1) curve1.setPos(ptr1, 0) curve2.setData(data2) curve2.setPos(ptr1, 0) curve3.setData(data3) curve3.setPos(ptr1, 0) curve4.setData(data4) curve4.setPos(ptr1, 0) # create socket to send information and receive information from chat s, connected = openSocket() print(connected) joinRoom(s) response = "" netTotal = 0.0 neuTotal = 0.0 negTotal = 0.0 posTotal = 0.0 avgTotal = 0.0 netAvg = 0.0 neuAvg = 0.0 negAvg = 0.0 posAvg = 0.0 start = time.time() avgElapsedBtwnMessageList = [5, 5, 5, 5, 5]
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.''' import string import time from Read import getUser, getMessage from Socket import openSocket, sendMessage from Initialize import joinRoom from Chat_Commands import chatCommands, fileRead from sys import argv 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:
from Socket import openSocket,sendMessage from Initialize import joinRoom from Funcs import getUserAndMessage, getTime, getDate, getCommands from datetime import datetime sock = openSocket() joinRoom(sock) readBuffer = "" while True: readBuffer = readBuffer + sock.recv(2048).decode('utf-8') temp = readBuffer.split('\n') readBuffer = temp.pop() for line in temp: user, message = getUserAndMessage(line) commands = {"!hello\r" : "HeyGuys, @" + user + "! Я - twitchKMBot!", "!clear\r" : "/clear", "!date\r" : getDate(), "!time\r" : getTime(), "!commands\r" : ""} commands["!commands\r"] = getCommands(commands) print(user + " typed :" + message) if message in commands: sendMessage(sock, commands[message]) # отвечает на сообщение Twitch'a 'PING :tmi.twitch.tv', показывая, что бот не АФК if line.startswith('PING'): sendMessage(sock, "Hey, Twitch! I'm not AFK! SMOrc SMOrc SMOrc")
import string import pickle import time import threading import re from urllib.request import urlopen from Socket import openSocket,sendMessage,joinRoom,getUser,getMessage from Settings import CHANNEL,MBALL,COOLDOWNCMD,VERSION,UNMOD #from pastebin import getChangelog s=openSocket("#"+CHANNEL) joinRoom(s) #w=openSocket("$[whisper]") #joinRoom(w) # INIT #MODOS=["tanook_leduc","aiki_","faiscla","orso5895","vambok","tanook_lebot"] #REGULARS=["tanook_leduc","aiki_","faiscla","orso5895","vambok","tanook_lebot","magicdiner","landulyk","imsouseless","hikarichan73","sednegi","aruthekbr","davissyon","plumeblanche","neg_eggs","reidmercury__","massiste2","ptiteframboise71","rhyouk","les_survivants","perblez60"] #SLAVES=["vambok","landulyk","faiscla","rhyouk","perblez60","piouman"] #UPTIMES={'tanook_leduc':10,'tanook_lebot':10,'vambok':10} #MSGCOUNT={'tanook_leduc':10,'tanook_lebot':10,'vambok':10} #fichier=open("viewers","wb") #pickle.dump([MODOS,REGULARS,SLAVES,UPTIMES,MSGCOUNT],fichier) #fichier.close() fichier=open("viewers","rb") gens=pickle.load(fichier) fichier.close() MODOS=gens[0] REGULARS=gens[1] SLAVES=gens[2] UPTIMES=gens[3] MSGCOUNT=gens[4]
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
def __init__(self): self.s = openSocket() joinRoom(self.s)
def sendHi(chatArray): for n in range (0, len(chatArray)): chatArray[n] = "" sendMsg(openSocket(), "HeyGuys") return chatArray
def __init__(self, listener): self.socket = openSocket() self.listener = listener self.readBuffer = ""
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
def connect(): global s s = openSocket()