Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #All hail RNG_MODS
- # USER STRUCTURE
- # user: [twitch user name]
- # stats: {"attack", "defense"}
- # analytics: {"chatlines"}
- import sys
- import string
- import socket
- import globals
- import userFunctions
- import arrow
- import requests
- from dateutil.relativedelta import relativedelta
- CLIENT_ID = ''
- OAUTH_TOKEN = '' # needs to be from narcissa account and have channel_check_subscription scope
- usedTimeouts = ['narcissa_bot']
- victims = ['narcissa_bot']
- def sub_data(username):
- response = requests.get(
- 'https://api.twitch.tv/kraken/channels/narcissawright/subscriptions/{}'.format(username),
- headers={
- 'Accept': 'application/vnd.twitchtv.v3+json',
- 'Client-Id': CLIENT_ID,
- 'Authorization': 'OAuth {}'.format(OAUTH_TOKEN)})
- print (response.status_code)
- if response.status_code == 200:
- return response.json()
- def enable_membership(self):
- self.sock.deliver('CAP REQ :twitch.tv/membership\r\n')
- def data_months_getter(data):
- print(data['created_at'])
- print(data['user']['name'])
- created_at = arrow.get(data['created_at']).datetime
- now = arrow.get().datetime
- delta = relativedelta(now, created_at)
- months = 12*delta.years + delta.months
- return months
- def ircLoop():
- global usedTimeouts
- global victims
- HOST = "irc.chat.twitch.tv"
- PORT = 6667
- PASSWORD = "oauth:"
- NICK = "Narcissa_Bot"
- IDENT = "Narcissa_Bot"
- REALNAME = "Narcissa_Bot"
- CHANNEL = "#narcissawright"
- globals.twitchSocket.connect((HOST, PORT))
- globals.twitchSocket.send(bytes("PASS %s\r\n" % PASSWORD, "UTF-8"))
- globals.twitchSocket.send(bytes("NICK %s\r\n" % NICK, "UTF-8"))
- globals.twitchSocket.send(bytes("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME), "UTF-8"))
- globals.twitchSocket.send(bytes("JOIN %s\r\n" % globals.CHANNEL, "UTF-8"));
- globals.twitchSocket.send(bytes("PRIVMSG %s :Hello World!~ \r\n" % globals.CHANNEL, "UTF-8"))
- chatLines = 0
- readbuffer = ""
- def getSender(line):
- sender = ""
- for char in line[0]:
- if(char == "!"):
- break
- if(char != ":"):
- sender += char
- return sender
- def getVictim(message):
- victim = message.partition(' ')[2] #grab the characters after the first space
- if not victim: #if an empty string
- return False #return False
- victim = victim.lower() #make lowercase
- if victim[0] == '@': #grab first character, check if it is an @ symbol (used for twitch chat autocomplete)
- victim = victim[1:] #remove the first character if it is an @ symbol so it returns just the victim
- return victim
- while 1:
- try:
- readbuffer = readbuffer+globals.twitchSocket.recv(1024).decode("UTF-8")
- temp = str.split(readbuffer, "\n")
- readbuffer=temp.pop( )
- except:
- temp = ""
- for line in temp: #for each line recieved,
- line = str.rstrip(line)
- line = str.split(line)
- if(line[0] == "PING"): #if its a PING:
- globals.twitchSocket.send(bytes("PONG %s\r\n" % line[1], "UTF-8"))
- print("* PING")
- if(line[1] == "353"): #if its a USER LIST:
- line[5] = line[5].lstrip(":")
- for i in range(5, len(line)):
- globals.userlist.append(userFunctions.addMissingUser(line[i]))
- print("* Populating globals.userlist. Total:", len(globals.userlist))
- if(line[1] == "PRIVMSG"): #if its a MESSAGE:
- sender = getSender(line)
- size = len(line)
- i = 3
- message = ""
- while(i < size):
- message += line[i] + " "
- i = i + 1
- message = message.lstrip(":").lower().rstrip() #tidy up the message, remove the :, trailing character, and make lowercase.
- ####################
- ## ADMIN COMMANDS ##
- ####################
- if (sender == "narcissawright"): #if narcissawright types it:
- if (message.partition(' ')[0] == "!end"): #if its ENDING THE PROGRAM
- return
- ###################
- ## USER COMMANDS ##
- ###################
- if (message.partition(' ')[0] == "!timeout"): #if its a timeout
- global usedTimeouts
- global victims
- sender = getSender(line)
- data = sub_data(sender)
- uses = usedTimeouts.count(sender)
- #if sender in usedTimeouts:
- # globals.twitchSocket.send(bytes("PRIVMSG %s :you've already used your timeout this stream. \r\n" % (globals.CHANNEL), "UTF-8"))
- #else:
- if data:
- months = data_months_getter(data)
- months += 1
- totalUses = months // 6
- if totalUses != 0:
- if uses >= totalUses:
- globals.twitchSocket.send(bytes("PRIVMSG %s :you've already used your timeouts this stream. \r\n" % (globals.CHANNEL), "UTF-8"))
- else:
- victim = getVictim(message)
- data2 = sub_data(victim)
- if not data2:
- severity = victims.count(victim)
- uses += 1
- if severity == 0:
- globals.twitchSocket.send(bytes("PRIVMSG %s :.timeout %s %s\r\n" % (globals.CHANNEL, victim, 300), "UTF-8")) #timeout for 5min
- globals.twitchSocket.send(bytes("PRIVMSG %s :%s has been timed out for 5 minutes. (%s/%s) \r\n" % (globals.CHANNEL, victim, uses, totalUses), "UTF-8"))
- if severity == 1:
- globals.twitchSocket.send(bytes("PRIVMSG %s :.timeout %s %s\r\n" % (globals.CHANNEL, victim, 1200), "UTF-8")) #timeout for 20min
- globals.twitchSocket.send(bytes("PRIVMSG %s :%s has been timed out for 20 minutes. (%s/%s) \r\n" % (globals.CHANNEL, victim, uses, totalUses), "UTF-8"))
- if severity == 2:
- globals.twitchSocket.send(bytes("PRIVMSG %s :.timeout %s %s\r\n" % (globals.CHANNEL, victim, 5400), "UTF-8")) #timeout for 90min
- globals.twitchSocket.send(bytes("PRIVMSG %s :%s has been timed out for 90 minutes. (%s/%s) \r\n" % (globals.CHANNEL, victim, uses, totalUses), "UTF-8"))
- if severity > 2:
- globals.twitchSocket.send(bytes("PRIVMSG %s :.timeout %s %s\r\n" % (globals.CHANNEL, victim, 43200), "UTF-8")) #timeout for 12hrs
- globals.twitchSocket.send(bytes("PRIVMSG %s :%s has been timed out for 12 hours. (%s/%s) \r\n" % (globals.CHANNEL, victim, uses, totalUses), "UTF-8"))
- usedTimeouts.append(sender)
- victims.append(victim)
- else:
- globals.twitchSocket.send(bytes("PRIVMSG %s :subscribers cannot time out subscribers.\r\n" % (globals.CHANNEL), "UTF-8"))
- else:
- globals.twitchSocket.send(bytes("PRIVMSG %s :you must be subscribed for 6 months to attain timeout power. (%s/6) \r\n" % (globals.CHANNEL, months), "UTF-8"))
- if (message.partition(' ')[0] == "!sub"): #if its a HI
- sender = getSender(line)
- data = sub_data(sender)
- if data:
- months = data_months_getter(data)
- months += 1
- globals.twitchSocket.send(bytes("PRIVMSG %s :%s subbed for %s month(s). \r\n" % (globals.CHANNEL, sender, months), "UTF-8"))
- #print('{} months subscribed'.format(12*delta.years + delta.months))
- else:
- globals.twitchSocket.send(bytes("PRIVMSG %s :%s hasn't subscribed. \r\n" % (globals.CHANNEL, sender), "UTF-8"))
- #victim = getVictim(message)
- ##userFunctions.attackUser(sqlite.getUser(str(sender)), sqlite.getUser(str(victim)))
- if(line[1] == "JOIN"): #if its a JOIN:
- sender = getSender(line)
- if(sender != "rng_mods"):
- globals.userlist.append(userFunctions.addMissingUser(sender))
- print("*", sender, "joined. Total:", len(globals.userlist))
- if(line[1] == "PART"): #if its a PART:
- sender = getSender(line)
- while sender in globals.userlist: globals.userlist.remove(sender)
- print("*", sender, "left. Total:", len(globals.userlist))
- ircLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement