Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket, string, time, random
- HOST = "irc.twitch.tv"
- NICK = "OldAsploSimulator"
- PORT = 6667
- PASS = "oauth:qa83iqz145orn4n8rlcund3njmcmxc"
- CHANNEL = "#_core54_1464148741723 "
- #CHANNEL = "#beyondmywaifupurge "
- TRIGGER_DELAY = 14400 #Delay in seconds for when bot triggers automatically
- COMMAND_DELAY = 10 #Delay in seconds for cooldown of commands
- triggerKey = '='
- readbuffer = ""
- MODT = False
- commandTime = time.time()
- s = socket.socket()
- s.connect((HOST, PORT))
- s.send("PASS " + PASS + "\r\n")
- s.send("NICK " + NICK + "\r\n")
- s.send("JOIN " + CHANNEL + "\r\n")
- print('Connected.')
- #Sends a message to chat:
- def sendMessage(message):
- s.send("PRIVMSG " + CHANNEL + ":" + message + "\r\n")
- #Open list of quotes, and selects one at random, and sends to chat:
- def makeQuote():
- with open('quotes.txt', 'r') as asploQuotesFile:
- data = asploQuotesFile.read()
- asploQuotes = data.split('\n')
- i = random.randint(0,(len(asploQuotes)-1))
- sendMessage(asploQuotes[i])
- #Checks to see if user is allowed to use commands
- def isAdmin(user):
- with open('admins.txt', 'r') as adminsFile:
- data = adminsFile.read()
- if user.lower() in data.split('\n'):
- return True
- else:
- return False
- while True:
- 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("PONG tmi.twitch.tv\r\n")
- break
- else:
- parts = string.split(line, ":")
- if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]:
- try:
- message = parts[2][:len(parts[2]) - 1]
- except:
- message = ""
- usernamesplit = string.split(parts[1], "!")
- username = usernamesplit[0]
- if MODT:
- #print username + ": " + message
- if isAdmin(username):
- if message == triggerKey + 'trigger':
- makeQuote()
- commandTime = time.time()
- time.sleep(COMMAND_DELAY)
- break
- elif message[0:4] == triggerKey + 'add':
- with open('quotes.txt', 'a') as asploQuotesFile:
- asploQuotesFile.write('\n' + message[5:])
- time.sleep(COMMAND_DELAY)
- break
- if float(time.time())-float(commandTime) > TRIGGER_DELAY:
- makeQuote()
- commandTime = time.time()
- for l in parts:
- if "End of /NAMES list" in l:
- MODT = True
Add Comment
Please, Sign In to add comment