Guest User

asploquotes.py

a guest
Nov 27th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.86 KB | None | 0 0
  1. import socket, string, time, random
  2.  
  3. HOST = "irc.twitch.tv"
  4.  
  5. NICK = "OldAsploSimulator"
  6. PORT = 6667
  7. PASS = "oauth:qa83iqz145orn4n8rlcund3njmcmxc"
  8. CHANNEL = "#_core54_1464148741723 "
  9. #CHANNEL = "#beyondmywaifupurge "
  10. TRIGGER_DELAY = 14400 #Delay in seconds for when  bot triggers automatically
  11. COMMAND_DELAY = 10 #Delay in seconds for cooldown of commands
  12. triggerKey = '='
  13.  
  14.  
  15. readbuffer = ""
  16. MODT = False
  17. commandTime = time.time()
  18.  
  19. s = socket.socket()
  20. s.connect((HOST, PORT))
  21. s.send("PASS " + PASS + "\r\n")
  22. s.send("NICK " + NICK + "\r\n")
  23. s.send("JOIN " + CHANNEL + "\r\n")
  24.  
  25. print('Connected.')
  26.  
  27. #Sends a message to chat:
  28. def sendMessage(message):
  29.     s.send("PRIVMSG " + CHANNEL + ":" + message + "\r\n")
  30.    
  31. #Open list of quotes, and selects one at random, and sends to chat:
  32. def makeQuote():
  33.     with open('quotes.txt', 'r') as asploQuotesFile:
  34.         data = asploQuotesFile.read()
  35.     asploQuotes = data.split('\n')
  36.     i = random.randint(0,(len(asploQuotes)-1))
  37.     sendMessage(asploQuotes[i])
  38.    
  39. #Checks to see if user is allowed to use commands
  40. def isAdmin(user):
  41.     with open('admins.txt', 'r') as adminsFile:
  42.         data = adminsFile.read()
  43.     if user.lower() in data.split('\n'):
  44.         return True
  45.     else:
  46.         return False
  47.  
  48. while True:
  49.     readbuffer = readbuffer + s.recv(1024)
  50.     temp = string.split(readbuffer, "\n")
  51.     readbuffer = temp.pop()
  52.     for line in temp:
  53.         #print line
  54.         if 'PING' in line:
  55.             s.send("PONG tmi.twitch.tv\r\n")
  56.             break
  57.         else:
  58.             parts = string.split(line, ":")
  59.             if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]:
  60.                 try:
  61.                     message = parts[2][:len(parts[2]) - 1]
  62.                 except:
  63.                     message = ""
  64.                 usernamesplit = string.split(parts[1], "!")
  65.                 username = usernamesplit[0]
  66.  
  67.                 if MODT:
  68.                     #print username + ": " + message
  69.                     if isAdmin(username):
  70.                         if message == triggerKey + 'trigger':
  71.                             makeQuote()
  72.                             commandTime = time.time()
  73.                             time.sleep(COMMAND_DELAY)
  74.                             break
  75.                         elif message[0:4] == triggerKey + 'add':
  76.                             with open('quotes.txt', 'a') as asploQuotesFile:
  77.                                 asploQuotesFile.write('\n' + message[5:])
  78.                             time.sleep(COMMAND_DELAY)
  79.                             break
  80.                     if float(time.time())-float(commandTime) > TRIGGER_DELAY:
  81.                         makeQuote()
  82.                         commandTime = time.time()
  83.                 for l in parts:
  84.                     if "End of /NAMES list" in l:
  85.                         MODT = True
Add Comment
Please, Sign In to add comment