SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 2,253 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import discord
  2. from discord.ext import commands
  3. import json
  4. import asyncio
  5. import aiohttp
  6.  
  7. client = discord.Client()
  8. bot = commands.Bot(command_prefix='.')
  9. token = "NTk5MjExNjE3OTk3MTYwNDY5.XSi6OQ.E84Y-3kATL-rT1zNf3nwztyck7A"
  10. accounts_file = "accounts.json"
  11. codes_file = "codes.txt"
  12.  
  13.  
  14. @bot.event
  15. async def on_ready():
  16.     print("Logged in as:")
  17.     print(bot.user.name)
  18.     print(bot.user.id)
  19.     print("-----------")
  20.  
  21.     try:
  22.         with open(accounts_file) as file:
  23.             bot.accounts = json.load(file)
  24.     except FileNotFoundError:
  25.         raise FileNotFoundError(f"{accounts_file} doesn't exist.")
  26.  
  27.     try:
  28.         with open(codes_file, "r") as file:
  29.             bot.codes = [code.strip("\n") for code in file.readlines()]
  30.     except FileNotFoundError:
  31.         raise FileNotFoundError(f"{codes_file} doesn't exist.")
  32.  
  33.     print("Accounts have been loaded.")
  34.  
  35.  
  36. @bot.command()
  37. async def reload(ctx):
  38.     """ It will reload the json file in case you have put more accounts.
  39.  
  40.     Arguments:
  41.         ctx {object} -- The context of the message.
  42.     """
  43.     embed = discord.Embed(title="Reloading accounts...", color=0xff5959)
  44.     message = await ctx.send(embed=embed)
  45.  
  46.     with open(accounts_file, 'rb') as file:
  47.         bot.accounts = json.load(file)
  48.  
  49.     with open(codes_file, "r") as file:
  50.         bot.codes = [code.strip("\n") for code in file.readlines()]
  51.  
  52.     embed = discord.Embed(title="Reloaded successfully! ✅", color=0xff5959)
  53.     await message.edit(embed=embed)
  54.  
  55.  
  56. @bot.command()
  57. async def stock(ctx):
  58.     """ Checks the current stock of the account variable, do restock if you have added more accounts.
  59.  
  60.     Arguments:
  61.         ctx {Object} -- The context of the message.
  62.     """
  63.     active_stock = {}
  64.     embed = discord.Embed(color=0xff5959)
  65.  
  66.     # It goes one by one on all the accounts and adds them to a dictionary with a counter.
  67.     for account in bot.accounts.values():
  68.         if account['Country'] not in active_stock:
  69.             active_stock[account['Country']] = 1
  70.         else:
  71.             active_stock[account['Country']] += 1
  72.  
  73.     # Prepares the string message which involves each country and their stock.
  74.     stock_information = ""
  75.     for country, stock in active_stock.items():
  76.         stock_information += f"{country}: {stock}\n"
  77.  
  78.     # Outputs the message to the place it was called.
  79.     embed.add_field(name="Current Stock:", value=stock_information)
  80.     await ctx.send(embed=embed)
  81.  
  82.  
  83. @bot.command()
  84. async def set(ctx, code: str, country: str, email: str, first_name="John", last_name="Deer"):
  85.     """ This command is used to send an invite to an account.
  86.  
  87.     Arguments:
  88.         ctx {Object} -- The context of the message.
  89.         code {str} -- The code which you have to get an invite.
  90.         country {str} -- The country from which you want an invite to be sent from.
  91.         email {str} -- The email you want the invite in.
  92.  
  93.     Keyword Arguments:
  94.         first_name {str} -- The first name of the person that gets the invite. (default: {"John"})
  95.         last_name {str} -- The last name of the person that gets the invite. (default: {"Deer"})
  96.     """
  97.     if code not in bot.codes:
  98.         embed = discord.Embed(
  99.             title="Invalid Code.", color=0xff5959)
  100.         message = await ctx.send(embed=embed)
  101.         return
  102.     else:
  103.         bot.codes.remove(code)
  104.  
  105.         with open("codes.txt", "a") as file:
  106.             file.truncate(0)
  107.  
  108.             for code in bot.codes:
  109.                 file.write(f"{code}\n")
  110.  
  111.     embed = discord.Embed(
  112.         title="Searching for an account...", color=0xff5959)
  113.     message = await ctx.send(embed=embed)
  114.  
  115.     for account in bot.accounts.values():
  116.         # Searching all the accounts for the selected country until found.
  117.         if account['Country'].lower() == country.lower():
  118.  
  119.             embed = discord.Embed(
  120.                 title="An account has been found.", color=0xff5959)
  121.             await message.edit(embed=embed)
  122.  
  123.             # Starting the process to send the invite.
  124.             async with aiohttp.ClientSession() as session:
  125.  
  126.                 url = 'https://accounts.spotify.com/en/login?continue=https://www.spotify.com/int/account/overview/'
  127.                 headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  128.                            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}
  129.  
  130.                 # Getting the CSRF token from the main website.
  131.                 response = await session.get(url, headers=headers)
  132.                 csrf_token = session.cookie_jar.filter_cookies(url)[
  133.                     'csrf_token'].value
  134.  
  135.                 headers = {
  136.                     'Accept': '*/*',
  137.                     'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1',
  138.                     'Referer': 'https://accounts.spotify.com/en/login/?continue=https://www.spotify.com/us/googlehome/register/&_locale=en-US'
  139.                 }
  140.  
  141.                 url = 'https://accounts.spotify.com/api/login'
  142.  
  143.                 login_data = {
  144.                     'remember': 'true',
  145.                     'username': account["Email"],
  146.                     'password': account["Password"],
  147.                     'csrf_token': csrf_token
  148.                 }
  149.  
  150.                 cookies = dict(
  151.                     __bon='MHwwfC0xNDAxNTMwNDkzfC01ODg2NDI4MDcwNnwxfDF8MXwx')
  152.  
  153.                 # Sending a login POST request.
  154.                 login = await session.post(url, headers=headers, data=login_data, cookies=cookies)
  155.  
  156.                 login_json = await login.json()
  157.  
  158.                 # If displayName exists then that means that we have been logged in.
  159.                 if 'displayName' in login_json:
  160.  
  161.                     url = 'https://www.spotify.com/us/account/overview/'
  162.  
  163.                     # Getting the next CSRF token.
  164.                     capture = await session.get(url, headers=headers)
  165.                     csrf = capture.headers['X-Csrf-Token']
  166.  
  167.                     url = 'https://www.spotify.com/us/family/api/master-invite-by-email/'
  168.  
  169.                     headers = {
  170.                         'Accept': '*/*',
  171.                         'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1',
  172.                         'x-csrf-token': csrf
  173.                     }
  174.  
  175.                     login_data = {
  176.                         'firstName': first_name,
  177.                         'lastName': last_name,
  178.                         'email': email}
  179.  
  180.                     # Once again sending the POST request for the invite.
  181.                     invite = await session.post(url, headers=headers, json=login_data)
  182.                     invite_json = await invite.json()
  183.  
  184.                     # Triggered if successful and sends that invite was sent.
  185.                     if invite_json["success"] is True:
  186.                         embed = discord.Embed(
  187.                             title="An invite has been sent to your email!", color=0xff5959)
  188.                         await message.edit(embed=embed)
  189.                         return
  190.  
  191.             # Triggered if an account doesn't work.
  192.             embed = discord.Embed(
  193.                 title="This account didn't work, trying next one!", color=0xff5959)
  194.             await message.edit(embed=embed)
  195.  
  196.     # Triggered if no of the accounts work or if the country doesn't exist.
  197.     embed = discord.Embed(
  198.         title="Sadly, none of the account worked it seems or we don't have stock!", color=0xff5959)
  199.     await message.edit(embed=embed)
  200.  
  201.  
  202. bot.run(token)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top