Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ----------------------------------------------------------------------------------------------------------------------
- """
- --- Bot Send-Chat Functionality ---
- Recommended: Do not touch.
- """
- def send(sock, msg):
- if len(message) > 0:
- sock.sendall((msg + "\n").encode("utf-8"))
- def chat(msg):
- print(cfg.NICK + ": " + msg)
- send(s, ('PRIVMSG {0} :{1}'.format(cfg.CHAN, msg)))
- # ----------------------------------------------------------------------------------------------------------------------
- """
- --- Chat Commands ---
- These are commands that you can have the bot respond to (i.e. !Purge to purge chat)
- """
- # ----------------------------------------------------------------------------------------------------------------------
- """
- --- IRC Connection Setup ---
- Recommended: Do not touch.
- """
- import cfg
- import socket
- import time
- import re
- CHAT_MSG = re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
- s = socket.socket()
- s.connect((cfg.HOST, cfg.PORT))
- s.send("PASS {}\r\n".format(cfg.PASS).encode("utf-8"))
- s.send("NICK {}\r\n".format(cfg.NICK).encode("utf-8"))
- s.send("JOIN {}\r\n".format(cfg.CHAN).encode("utf-8"))
- # ----------------------------------------------------------------------------------------------------------------------
- #BigotBot.py
- while True: #Main Loop
- response = s.recv(1024).decode("utf-8")
- if response == "PING :tmi.twitch.tv\r\n": #If Ping, return Pong
- s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
- print("Pong Successful")
- else: #Else, Decode User Message
- username = re.search(r"\w+", response).group(0) #Gets User
- message = CHAT_MSG.sub("", response) #Gets Message
- print (username + ": " + message) #Prints User Message
- if message.find("!hello") != -1: #Simple Test command to see if Reading Chat Input
- chat ("Hello! I'm speaking!\r\n")
- time.sleep(1 / cfg.RATE)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement