Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # steamidfinder.py
- # Twitch bot by Logey420
- # Last Updated 2016/03/31 - 13:51 (GMT)
- # Any dates shown are in the format YYYY/MM/DD
- from os import system
- import re
- import socket
- import urllib.request
- HOST = "irc.twitch.tv" # Hostname of the IRC-Server in this case, Twitch's
- PORT = 6667 # Default IRC-Port
- CHAN = "#" + input("Channel to enter?:\n\t#") # Channelname = #{Nickname}
- channelName = CHAN.strip("#")
- NICK = "evilbot254" # Nickname = Twitch username
- PASS = open("oauth.txt", "r").read() # www.twitchapps.com/tmi/ will help to retrieve the required authkey
- # replace above line with:
- # PASS = "oauth:exampletoken"
- system("title " + CHAN)
- def send_pong(msg):
- con.send(bytes('PONG %s\r\n' % msg, 'UTF-8'))
- def send_message(chan, msg):
- con.send(bytes('PRIVMSG %s :%s\r\n' % (chan, msg), 'UTF-8'))
- def send_nick(nick):
- con.send(bytes('NICK %s\r\n' % nick, 'UTF-8'))
- def send_pass(password):
- con.send(bytes('PASS %s\r\n' % password, 'UTF-8'))
- def join_channel(chan):
- con.send(bytes('JOIN %s\r\n' % chan, 'UTF-8'))
- def part_channel(chan):
- con.send(bytes('PART %s\r\n' % chan, 'UTF-8'))
- def get_sender(msg):
- result = ""
- for char in msg:
- if char == "!":
- break
- if char != ":":
- result += char
- return result
- def get_message(msg):
- result = ""
- i = 3
- length = len(msg)
- while i < length:
- result += msg[i] + " "
- i += 1
- result = result.lstrip(':')
- return result
- def parse_message(msg):
- if len(msg) >= 1:
- msg = msg.split(' ')
- options = {'!claudu': claudia,
- '!idfind': command_findID,
- '!myid': command_myID,
- '!findmyid': command_myID,
- '!sourcecode': command_source_code}
- if msg[0] in options:
- options[msg[0]]()
- def command_findID():
- twitchUser = message[8:].strip(" ")
- try:
- page = urllib.request.urlopen("https://api.twitch.tv/api/channels/%s" % twitchUser)
- pageContent = str(page.read())
- pageData = pageContent.split(",")
- steamID = pageData[13].strip('"steam_id":""')
- if "steam_id" not in pageData[13]:
- steamID = pageData[14].strip('"steam_id":""')
- if steamID == "null":
- messageToSend = "@%s -> %s's Steam and Twitch accounts are not linked. The accounts can be linked here: https://www.twitch.tv/settings/connections" % (sender, twitchUser)
- else:
- messageToSend = "@%s -> %s's steamID64 is: %s" % (sender, twitchUser, steamID)
- elif steamID == "null":
- messageToSend = "@%s -> %s's Steam and Twitch accounts are not linked. The accounts can be linked here: https://www.twitch.tv/settings/connections" % (sender, twitchUser)
- else:
- messageToSend = "@%s -> %s's steamID64 is: %s" % (sender, twitchUser, steamID)
- send_message(CHAN, messageToSend)
- print(NICK + ": " + messageToSend)
- except:
- send_message(CHAN, "@%s -> API error! Please try again." % sender)
- print(NICK + ": " + "@%s -> API error! Please try again." % sender)
- def command_myID():
- try:
- page = urllib.request.urlopen("https://api.twitch.tv/api/channels/%s" % sender)
- pageContent = str(page.read())
- pageData = pageContent.split(",")
- steamID = pageData[13].strip('"steam_id":""')
- if "steam_id" not in pageData[13]:
- steamID = pageData[14].strip('"steam_id":""')
- if steamID == "null":
- messageToSend = "@%s -> Your Steam and Twitch accounts are not linked. You can link them here: https://www.twitch.tv/settings/connections" % sender
- else:
- messageToSend = "@%s -> Your steamID64 is: %s" % (sender, steamID)
- elif steamID == "null":
- messageToSend = "@%s -> Your Steam and Twitch accounts are not linked. You can link them here: https://www.twitch.tv/settings/connections" % sender
- else:
- messageToSend = "@%s -> Your steamID64 is: %s" % (sender, steamID)
- send_message(CHAN, messageToSend)
- print(NICK + ": " + messageToSend)
- except:
- send_message(CHAN, "@%s -> API error! Please try again." % sender)
- print(NICK + ": " + "@%s -> API error! Please try again." % sender)
- def command_source_code():
- send_message(CHAN, "@%s -> Here is my source code: http://pastebin.com/4j5dwB3c" % sender)
- print(NICK + ": " + "@%s -> Here is my source code: http://pastebin.com/4j5dwB3c" % sender)
- def claudia():
- send_message(CHAN, "@%s -> sup claudia." % sender)
- print(NICK + ": " + "@%s -> sup claudia." % sender)
- con = socket.socket()
- con.connect((HOST, PORT))
- send_pass(PASS)
- send_nick(NICK)
- join_channel(CHAN)
- data = ""
- while True:
- try:
- data = data+con.recv(1024).decode('UTF-8')
- data_split = re.split(r"[~\r\n]+", data)
- data = data_split.pop()
- for line in data_split:
- line = str.rstrip(line)
- line = str.split(line)
- if len(line) >= 1:
- if line[0] == 'PING':
- send_pong(line[1])
- if line[1] == 'PRIVMSG':
- sender = get_sender(line[0])
- message = get_message(line)
- parse_message(message)
- print(sender + ": " + message)
- except socket.error:
- print("Socket died")
- except socket.timeout:
- print("Socket timeout")
- raw_input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement