Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import fortnitepy
from discord.ext import commands
import discord
discord_bot = commands.Bot(
command_prefix='!',
description='My discord + fortnite bot!',
case_insensitive=True
)
fortnite_client = fortnitepy.Client(
email='',
password='',
loop=discord_bot.loop
)
@discord_bot.event
async def on_ready():
print('Discord bot ready')
activity = discord.Game(name="fortnite.py")
await discord_bot.change_presence(status=discord.Status.idle, activity=activity)
await fortnite_client.start()
@fortnite_client.event
async def event_ready():
print('Fortnite client ready')
filename = 'device_auths.json'
def get_device_auth_details():
if os.path.isfile(filename):
with open(filename, 'r') as fp:
return json.load(fp)
return {}
def store_device_auth_details(email, details):
existing = get_device_auth_details()
existing[email] = details
with open(filename, 'w') as fp:
json.dump(existing, fp)
class MyClient(fortnitepy.Client):
def __init__(self):
device_auth_details = get_device_auth_details().get(email, {})
super().__init__(
auth=fortnitepy.AdvancedAuth(
email=email,
password=password,
prompt_authorization_code=True,
delete_existing_device_auths=True,
**device_auth_details
)
)
self.session_event = asyncio.Event()
async def event_device_auth_generate(self, details, email):
store_device_auth_details(email, details)
filename = 'device_auths.json'
def get_device_auth_details():
if os.path.isfile(filename):
with open(filename, 'r') as fp:
return json.load(fp)
return {}
def store_device_auth_details(email, details):
existing = get_device_auth_details()
existing[email] = details
with open(filename, 'w') as fp:
json.dump(existing, fp)
class MyClient(fortnitepy.Client):
def __init__(self):
device_auth_details = get_device_auth_details().get(email, {})
super().__init__(
auth=fortnitepy.AdvancedAuth(
email=email,
password=password,
prompt_authorization_code=True,
delete_existing_device_auths=True,
**device_auth_details
)
)
self.session_event = asyncio.Event(loop=self.loop)
async def event_device_auth_generate(self, details, email):
store_device_auth_details(email, details)
async def event_ready(self):
print('Main client ready. Launching sub-accounts...')
clients = []
device_auths = get_device_auth_details()
for email, password in credentials.items():
client = fortnitepy.Client(
auth=fortnitepy.AdvancedAuth(
email=email,
password=password,
prompt_authorization_code=True,
delete_existing_device_auths=True,
**device_auths.get(email, {})
),
default_party_member_config=fortnitepy.DefaultPartyMemberConfig(
meta=(
functools.partial(fortnitepy.ClientPartyMember.set_outfit, 'CID_175_Athena_Commando_M_Celestial'), # galaxy skin
)
)
)
# register events here
client.add_event_handler('device_auth_generate', self.event_sub_device_auth_generate)
async def event_sub_party_member_join(member):
print("{0.display_name} joined {0.client.user.display_name}'s party.".format(member))
clients = []
device_auths = get_device_auth_details()
for email, password in credentials.items():
authentication = fortnitepy.AdvancedAuth(
email=email,
password=password,
prompt_authorization_code=True,
delete_existing_device_auths=True,
**device_auths.get(email, {})
)
client = fortnitepy.Client(
auth=authentication,
default_party_member_config=fortnitepy.DefaultPartyMemberConfig(
meta=(
functools.partial(fortnitepy.ClientPartyMember.set_outfit, 'CID_175_Athena_Commando_M_Celestial'), # galaxy skin
)
)
)
# register events here
client.add_event_handler('device_auth_generate', event_sub_device_auth_generate)
client.add_event_handler('friend_request', event_sub_friend_request)
client.add_event_handler('party_member_join', event_sub_party_member_join)
clients.append(client)
fortnitepy.run_multiple(
}
def get_device_auth_details():
if os.path.isfile(filename):
with open(filename, 'r') as fp:
return json.load(fp)
return {}
def store_device_auth_details(email, details):
existing = get_device_auth_details()
existing[email] = details
with open(filename, 'w') as fp:
json.dump(existing, fp)
class MyClient(fortnitepy.Client):
def __init__(self):
device_auths = get_device_auth_details()
super().__init__(
auth=fortnitepy.AdvancedAuth(
email=email,
password=password,
authorization=True,
delete_existing_device_auths=True,
**device_auths.get(email, {})
)
)
self.instances = {}
async def event_sub_device_auth_generate(self, details, email):
store_device_auth_details(email, details)