Advertisement
Buffet_Time

asd;lfkjasdf;lkasjdf;lsj

Nov 23rd, 2015
1,701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. # bot.py
  2. import cfg
  3. import socket
  4. import time
  5. import re
  6.  
  7.  
  8. def chat(sock, msg):
  9.     sock.send("PRIVMSG #{} :{}".format(cfg.CHAN, msg))
  10.  
  11.  
  12. def ban(sock, user):
  13.     chat(sock, ".ban {}".format(user))
  14.  
  15.  
  16. def timeout(sock, user, secs=60):
  17.     chat(sock, ".timeout {}".format(user, secs))
  18.  
  19.  
  20. CHAT_MSG = re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
  21.  
  22.  
  23. # network functions go here
  24. s = socket.socket()
  25. s.connect((cfg.HOST, cfg.PORT))
  26. s.send("PASS {}\r\n".format(cfg.PASS).encode("utf-8"))
  27. s.send("NICK {}\r\n".format(cfg.NICK).encode("utf-8"))
  28. s.send("JOIN {}\r\n".format(cfg.CHAN).encode("utf-8"))
  29.  
  30.  
  31. while True:
  32.     response = s.recv(1024).decode("utf-8")
  33.     if response == "PING :tmi.twitch.tv\r\n":
  34.         s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
  35.         print("Pong")
  36.     else:
  37.         username = re.search(r"\w+", line).group(0)  # return the entire match
  38.         message = CHAT_MSG.sub("", line)
  39.         print(username + ": " + message)
  40.         for pattern in cfg.PATT:
  41.             if re.match(pattern, message):
  42.                 ban(s, username)
  43.                 break
  44.         time.sleep(1 / cfg.RATE)
  45.  
  46. //////////////
  47.  
  48. #cfg.py
  49.  
  50. HOST = "irc.twitch.tv"                          # Twitch irc host
  51. PORT = 6667                                     # IRC port
  52. CHAN = "#*************"                         # CHAN = the channel to connect to
  53. NICK = "**********"                             # NICK = Twitch username
  54. PASS = "************************************"   # authkey for the NICK
  55. RATE = (100/30)  # 100 per 30 seconds = Mod   ||||   20 per 30 seconds = User
  56. PATT = [
  57.     r"swear",
  58.     # ...
  59.     r"some_pattern"
  60. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement