Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #bot.py
- import cfg
- import socket
- import re
- import commands
- def chat(sock, msg):
- """
- Send a chat message to the server.
- Keyword arguments:
- sock -- the socket over which to send the message
- msg -- the message to be sent
- """
- sock.send("PRIVMSG #{} :{}\r\n".format(cfg.CHAN, msg).encode("utf-8"))
- def ban(sock, user):
- """
- Ban a user from the current channel.
- Keyword arguments:
- sock -- the socket over which to send the ban command
- user -- the user to be banned
- """
- chat(sock, ".ban {}".format(user))
- def timeout(sock, user, secs=600):
- """
- Time out a user for a set period of time.
- Keyword arguments:
- sock -- the socket over which to send the timeout command
- user -- the user to be timed out
- secs -- the length of the timeout in seconds (default 600)
- """
- chat(sock, ".timeout {}".format(user, secs))
- HOST = "irc.twitch.tv" # the Twitch IRC server
- PORT = 6667 # always use port 6667!
- NICK = "wolfmanager" # your Twitch username, lowercase
- PASS = "oauth:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" # your Twitch OAuth token
- CHAN = "#arcticwolfhowls" # the channel you want to join
- s = socket.socket()
- s.connect((HOST, PORT))
- s.send("PASS {}\r\n".format(PASS).encode("utf-8"))
- s.send("NICK {}\r\n".format(NICK).encode("utf-8"))
- s.send("JOIN {}\r\n".format(CHAN).encode("utf-8"))
- # Make sure you prefix the quotes with an 'r'!
- CHAT_MSG = re.compile(r"^:\w+!\w+@\w+\.tmi\.twitch\.tv PRIVMSG #\w+ :")
- while True:
- response = s.recv(1024).decode("utf-8")
- if response == "PING :tmi.twitch.tv\r\n":
- s.send("PONG :tmi.twitch.tv\r\n".encode("utf-8"))
- else:
- username = re.search(r"\w+", response).group(0) # return the entire match
- message = CHAT_MSG.sub("", response)
- print(username + ": " + message)
- #Commands
- clist = ["!add", ]
- if message.strip() == "!add":
- chat(s, "Syntax: !add !<command> <what the command does>")
- if message.strip().startswith("!add"):
- clist.append(message[5:])
- chat(s, "The command has been added!")
- if message.strip() == "!wolfmanager":
- chat(s, "I am a chat bot coded by Arcticwolfhowls! type: !commands for a list of commands. Check it every now and again because it changes constantly!")
- if message.strip() == "!commands":
- chat(s, clist)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement