Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is just a basic command bot for Twitch chat.
- # Imports
- import socket
- # no need to change, always this
- SERVER = "irc.twitch.tv"
- # no need to change, always this
- PORT = 6667
- # change inbetween "quotes" your oath you get from https://twitchapps.com/tmi/
- PASS = "REPLACETHISWITHOATH:SOMERANDOMCHARACTERSINUROATH"
- # channel in witch you want this bot to work
- CHANNEL = "lowercasechannelname"
- # account name in lowercase which will be used as bot
- BOT = "lowercasenameofyourstandardchatbot"
- def sendMessage(s, message):
- messageTemp = "PRIVMSG #" + CHANNEL + " :" + message
- s.send((messageTemp + "\r\n").encode())
- def getUser(line):
- separate = line.split(":", 2)
- user = separate[1].split("!", 1)[0]
- return user
- def getMessage(line):
- global message
- try:
- message = (line.split(":", 2))[2]
- except:
- message = ""
- return message
- def joinchat():
- readbuffer_join = "".encode()
- Loading = True
- while Loading:
- readbuffer_join = s.recv(1024)
- readbuffer_join = readbuffer_join.decode()
- temp = readbuffer_join.split("\n")
- readbuffer_join = readbuffer_join.encode()
- readbuffer_join = temp.pop()
- for line in temp:
- Loading = loadingCompleted(line)
- sendMessage(s, "Bot Entered Channel Message")
- print("Bot has joined " + CHANNEL + " Channel!")
- def loadingCompleted(line):
- if ("End of /NAMES list" in line):
- return False
- else:
- return True
- s_prep = socket.socket()
- s_prep.connect((SERVER, PORT))
- s_prep.send(("PASS " + PASS + "\r\n").encode())
- s_prep.send(("NICK " + BOT + "\r\n").encode())
- s_prep.send(("JOIN #" + CHANNEL + "\r\n").encode())
- s = s_prep
- joinchat()
- readbuffer = ""
- def Console(line):
- if "PRIVMSG" in line:
- return False
- else:
- return True
- while True:
- try:
- readbuffer = s.recv(1024)
- readbuffer = readbuffer.decode()
- temp = readbuffer.split("\n")
- readbuffer = readbuffer.encode()
- readbuffer = temp.pop()
- except:
- temp = ""
- for line in temp:
- if line == "":
- break
- if "PING" in line and Console(line):
- msgg = "PONG tmi.twitch.tv\r\n".encode()
- s.send(msgg)
- print(msgg)
- break
- user = getUser(line)
- message = getMessage(line)
- PMSG = "/w " + user + " "
- # Now the stuff to change. Just copy paste the if to break part as many times as you want to make multiple commands.
- if "!command" in message:
- sendMessage(s, "First respond message.")
- sendMessage(s, "Second respond message.")
- break
- if ".anothercommand" in message:
- sendMessage(s, "Your message.")
- break
Add Comment
Please, Sign In to add comment