Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### The only import you need!
- import socket
- import time
- ### Cooldown variables
- min_call_freq = 5
- begintime = 0
- used = {}
- ### Options (Don't edit)
- SERVER = "irc.twitch.tv" # server
- PORT = 6667 # port
- ### Options (Edit this)
- PASS = "passIcantshow" # bot password can be found on https://twitchapps.com/tmi/
- BOT = "mybotname" # Bot's name [NO CAPITALS]
- CHANNEL = "criogenesis" # Channal name [NO CAPITALS]
- OWNER = "criogenesis" # Owner's name [NO CAPITALS]
- ### Functions
- 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, "Chat room joined!")
- print("Bot has joined " + CHANNEL + " Channel!")
- def loadingCompleted(line):
- if ("End of /NAMES list" in line):
- return False
- else:
- return True
- def call_command(command):
- print('Calling command `%s`.' % command)
- def cooldown(command):
- print('You have used command `%s` in the last %u seconds.' % (command, min_call_freq))
- def process_command(command):
- if (
- command not in used
- #time.time() - used[command] > min_call_freq
- ):
- used[command] = time.time() - min_call_freq
- #print(time.time() - used[command])
- call_command(command)
- print('A')
- elif time.time() - used[command] < min_call_freq:
- #used[command] = time.time()
- print(time.time() - used[command])
- print('1')
- cooldown(command)
- else:
- print(time.time() - used[command])
- used[command] = time.time()
- print('2')
- call_command(command)
- ### Code runs
- 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):
- # gets if it is a user or twitch server
- 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
- # So twitch doesn't timeout the bot.
- if "PING" in line and Console(line):
- msgg = "PONG tmi.twitch.tv\r\n".encode()
- s.send(msgg)
- print(msgg)
- break
- # get user
- user = getUser(line)
- # get message send by user
- message = getMessage(line)
- # for you to see the chat from CMD
- print(user + " > " + message)
- # sends private msg to the user (start line)
- PMSG = "/w " + user + " "
- ################################# Command ##################################
- ############ Here you can add as meny commands as you wish of ! ############
- ############################################################################
- clubquestion = "club"
- twerkrequest = "twerk"
- wtfisthis = "wtf is this"
- extreme = "extreme"
- Nut = " N "
- makeitjingle = "make it jingle"
- if user == OWNER and "!command" in message:
- sendMessage(s, "This can only be used by the owner")
- break
- if "!private" in message:
- sendMessage(s, PMSG + "This is a private message send to the user")
- break
- if "!global" in message:
- sendMessage(s, "This is a global message send to the chat")
- break
- if "!me" in message:
- sendMessage(s, "/me this is a test for the slash me")
- print(used)
- break
- if clubquestion in message:
- process_command(clubquestion)
- print(time.time() - used[clubquestion])
- if time.time() - used[clubquestion] < min_call_freq:
- break
- else:
- sendMessage(s, "If you're asking if Avery goes to clubs, the answer is no")
- if twerkrequest in message:
- process_command(twerkrequest)
- if time.time() - used[twerkrequest] == begintime:
- sendMessage(s, "I shall shake my posterior for you human *twerkles*")
- if time.time() - used[twerkrequest] < min_call_freq and not begintime:
- break
- else:
- sendMessage(s, "I shall shake my posterior for you human *twerkles*")
- if wtfisthis in message:
- process_command(wtfisthis)
- if time.time() - used[wtfisthis] == begintime:
- sendMessage(s, "@" + user + " " + "This is what we would like to call dancing, it's really fun")
- if time.time() - used[wtfisthis] < min_call_freq and not begintime:
- break
- else:
- sendMessage(s, "@" + user + " " + "This is what we would like to call dancing, it's really fun")
- if extreme in message:
- process_command(extreme)
- if time.time() - used[extreme] == begintime:
- sendMessage(s, "Do you want her to die?")
- if time.time() - used[extreme] < min_call_freq and not begintime:
- break
- else:
- sendMessage(s, "Do you want her to die?")
- if Nut in message:
- process_command(Nut)
- if time.time() - used[Nut] == begintime:
- sendMessage(s, "NUT Kreygasm")
- if time.time() - used[Nut] < min_call_freq and not begintime:
- break
- else:
- sendMessage(s, "NUT Kreygasm")
- if makeitjingle in message:
- process_command(makeitjingle)
- if time.time() - used[makeitjingle] == begintime:
- sendMessage(s, "@" + user + " " + "Avery can't do that song because it includes twerking and that is against TOS. However I am a bot so I can make twerk")
- if time.time() - used[makeitjingle] < min_call_freq and not begintime:
- break
- else:
- sendMessage(s, "@" + user + " " + "Avery can't do that song because it includes twerking and that is against TOS. However I am a bot so I can make twerk")
- if "skynet" in message:
- sendMessage(s, "yes I am skynet... boooooo")
- break
- if "bang" in message:
- sendMessage(s, "oh fuck, im......my splee-I mean my bolts...im dead")
- ############################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement