Advertisement
Guest User

Bot code

a guest
Nov 1st, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. import socket
  2.  
  3.  
  4.  
  5. HOST = "irc.twitch.tv"
  6. PORT = 6667
  7. NICK = "pjevs121"
  8. PASS = 'oauth:uuuw876479lnzllyfu8mnechaeuy2h'
  9.  
  10. def send_message(message):
  11. s.send(bytes("PRIVMSG #" + NICK + " :" + message + "\r\n", "UTF-8"))
  12.  
  13. s = socket.socket()
  14. s.connect((HOST, PORT))
  15. s.send(bytes("PASS " + PASS + "\r\n", "UTF-8"))
  16. s.send(bytes("NICK " + NICK + "\r\n", "UTF-8"))
  17. s.send(bytes("JOIN #" + NICK + " \r\n", "UTF-8"))
  18.  
  19.  
  20. while True:
  21. line = str(s.recv(1024))
  22. if "PING :tmi.twitch.tv" in line:
  23. print("PONG :tmi.twitch.tv")
  24. s.send(bytes("PONG :tmi.twitch.tv", "UTF-8"))
  25.  
  26. if "End of /NAMES list" in line:
  27. break
  28.  
  29. while True:
  30. for line in str(s.recv(1024)).split('\\r\\n'):
  31. parts = line.split(':')
  32. if len(parts) < 3:
  33. continue
  34.  
  35. if "QUIT" not in parts[1] and "JOIN" not in parts[1] and "PART" not in parts[1]:
  36. message = parts[2][:len(parts[2])]
  37.  
  38. usernamesplit = parts[1].split("!")
  39. username = usernamesplit[0]
  40.  
  41. print(username + ": " + message)
  42. if message == "Hey" or message == "hey" or message == "hej" or message == "Hej ":
  43. send_message("Welcome to my stream, " + username)
  44.  
  45. if message == "!sr":
  46. send_message("Use !sr <your song request> to request a song")
  47.  
  48. if message.startswith('!sr '):
  49. send_message(username + " your request has been saved")
  50. with open('sr.txt', 'a') as f:
  51. f.write(username + " requested " + message + '\n')
  52. f.close()
  53.  
  54. if message.startswith('!download '):
  55. send_message(username + ", your request will be downloaded before next stream")
  56. with open('download.txt', 'a') as g:
  57. g.write(username + " requested " + message + '\n')
  58. g.close()
  59.  
  60. if message == ("!download"):
  61. send_message(username + ", use !download to request a song that is not on the playlist already")
  62.  
  63. if message == "Hey" and username == "yeehaaman" or username == "Yeehaaman":
  64. send_message(username + ", skift dit navn til Yeehaahippiman!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement