Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- from discord.ext import commands
- import json
- import asyncio
- import aiohttp
- client = discord.Client()
- bot = commands.Bot(command_prefix='.')
- token = "NTk5MjExNjE3OTk3MTYwNDY5.XSi6OQ.E84Y-3kATL-rT1zNf3nwztyck7A"
- accounts_file = "accounts.json"
- codes_file = "codes.txt"
- @bot.event
- async def on_ready():
- print("Logged in as:")
- print(bot.user.name)
- print(bot.user.id)
- print("-----------")
- try:
- with open(accounts_file) as file:
- bot.accounts = json.load(file)
- except FileNotFoundError:
- raise FileNotFoundError(f"{accounts_file} doesn't exist.")
- try:
- with open(codes_file, "r") as file:
- bot.codes = [code.strip("\n") for code in file.readlines()]
- except FileNotFoundError:
- raise FileNotFoundError(f"{codes_file} doesn't exist.")
- print("Accounts have been loaded.")
- @bot.command()
- async def reload(ctx):
- """ It will reload the json file in case you have put more accounts.
- Arguments:
- ctx {object} -- The context of the message.
- """
- embed = discord.Embed(title="Reloading accounts...", color=0xff5959)
- message = await ctx.send(embed=embed)
- with open(accounts_file, 'rb') as file:
- bot.accounts = json.load(file)
- with open(codes_file, "r") as file:
- bot.codes = [code.strip("\n") for code in file.readlines()]
- embed = discord.Embed(title="Reloaded successfully! ✅", color=0xff5959)
- await message.edit(embed=embed)
- @bot.command()
- async def stock(ctx):
- """ Checks the current stock of the account variable, do restock if you have added more accounts.
- Arguments:
- ctx {Object} -- The context of the message.
- """
- active_stock = {}
- embed = discord.Embed(color=0xff5959)
- # It goes one by one on all the accounts and adds them to a dictionary with a counter.
- for account in bot.accounts.values():
- if account['Country'] not in active_stock:
- active_stock[account['Country']] = 1
- else:
- active_stock[account['Country']] += 1
- # Prepares the string message which involves each country and their stock.
- stock_information = ""
- for country, stock in active_stock.items():
- stock_information += f"{country}: {stock}\n"
- # Outputs the message to the place it was called.
- embed.add_field(name="Current Stock:", value=stock_information)
- await ctx.send(embed=embed)
- @bot.command()
- async def set(ctx, code: str, country: str, email: str, first_name="John", last_name="Deer"):
- """ This command is used to send an invite to an account.
- Arguments:
- ctx {Object} -- The context of the message.
- code {str} -- The code which you have to get an invite.
- country {str} -- The country from which you want an invite to be sent from.
- email {str} -- The email you want the invite in.
- Keyword Arguments:
- first_name {str} -- The first name of the person that gets the invite. (default: {"John"})
- last_name {str} -- The last name of the person that gets the invite. (default: {"Deer"})
- """
- if code not in bot.codes:
- embed = discord.Embed(
- title="Invalid Code.", color=0xff5959)
- message = await ctx.send(embed=embed)
- return
- else:
- bot.codes.remove(code)
- with open("codes.txt", "a") as file:
- file.truncate(0)
- for code in bot.codes:
- file.write(f"{code}\n")
- embed = discord.Embed(
- title="Searching for an account...", color=0xff5959)
- message = await ctx.send(embed=embed)
- for account in bot.accounts.values():
- # Searching all the accounts for the selected country until found.
- if account['Country'].lower() == country.lower():
- embed = discord.Embed(
- title="An account has been found.", color=0xff5959)
- await message.edit(embed=embed)
- # Starting the process to send the invite.
- async with aiohttp.ClientSession() as session:
- url = 'https://accounts.spotify.com/en/login?continue=https://www.spotify.com/int/account/overview/'
- headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- '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'}
- # Getting the CSRF token from the main website.
- response = await session.get(url, headers=headers)
- csrf_token = session.cookie_jar.filter_cookies(url)[
- 'csrf_token'].value
- headers = {
- 'Accept': '*/*',
- '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',
- 'Referer': 'https://accounts.spotify.com/en/login/?continue=https://www.spotify.com/us/googlehome/register/&_locale=en-US'
- }
- url = 'https://accounts.spotify.com/api/login'
- login_data = {
- 'remember': 'true',
- 'username': account["Email"],
- 'password': account["Password"],
- 'csrf_token': csrf_token
- }
- cookies = dict(
- __bon='MHwwfC0xNDAxNTMwNDkzfC01ODg2NDI4MDcwNnwxfDF8MXwx')
- # Sending a login POST request.
- login = await session.post(url, headers=headers, data=login_data, cookies=cookies)
- login_json = await login.json()
- # If displayName exists then that means that we have been logged in.
- if 'displayName' in login_json:
- url = 'https://www.spotify.com/us/account/overview/'
- # Getting the next CSRF token.
- capture = await session.get(url, headers=headers)
- csrf = capture.headers['X-Csrf-Token']
- url = 'https://www.spotify.com/us/family/api/master-invite-by-email/'
- headers = {
- 'Accept': '*/*',
- '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',
- 'x-csrf-token': csrf
- }
- login_data = {
- 'firstName': first_name,
- 'lastName': last_name,
- 'email': email}
- # Once again sending the POST request for the invite.
- invite = await session.post(url, headers=headers, json=login_data)
- invite_json = await invite.json()
- # Triggered if successful and sends that invite was sent.
- if invite_json["success"] is True:
- embed = discord.Embed(
- title="An invite has been sent to your email!", color=0xff5959)
- await message.edit(embed=embed)
- return
- # Triggered if an account doesn't work.
- embed = discord.Embed(
- title="This account didn't work, trying next one!", color=0xff5959)
- await message.edit(embed=embed)
- # Triggered if no of the accounts work or if the country doesn't exist.
- embed = discord.Embed(
- title="Sadly, none of the account worked it seems or we don't have stock!", color=0xff5959)
- await message.edit(embed=embed)
- bot.run(token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement