summaryrefslogtreecommitdiff
path: root/FortniteClient.py
diff options
context:
space:
mode:
Diffstat (limited to 'FortniteClient.py')
-rwxr-xr-xFortniteClient.py85
1 files changed, 85 insertions, 0 deletions
diff --git a/FortniteClient.py b/FortniteClient.py
new file mode 100755
index 0000000..f426fa7
--- /dev/null
+++ b/FortniteClient.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python3
+
+import fortnitepy
+import json
+import os
+import typing
+from DeviceAuth import DeviceAuth
+from FortniteEvents import *
+
+__fortnite_account_key__ = 'fornite-account-key'
+
+class FortniteClient(fortnitepy.Client):
+
+ device_auth = DeviceAuth()
+ observers = []
+
+ def __init__(self):
+ if self.device_auth.device_auth_file_exists():
+ self.__auth_device_auth()
+ else:
+ self.__auth_authorization_code()
+
+ def attach(self, observer: any):
+ self.observers.append(observer)
+
+ def __auth_authorization_code(self):
+ code = input("Enter authorization code (https://www.epicgames.com/id/api/redirect?clientId=3446cd72694c4a4485d81b77adbb2141&responseType=code):")
+ super().__init__(
+ auth=fortnitepy.AuthorizationCodeAuth(
+ code = code
+ )
+ )
+
+ def __auth_device_auth(self):
+ device_auth_details = self.device_auth.get_device_auth_details().get(__fortnite_account_key__, {})
+ super().__init__(
+ auth=fortnitepy.DeviceAuth(
+ **device_auth_details
+ )
+ )
+
+ async def event_device_auth_generate(self, details, email):
+ self.device_auth.store_device_auth_details(email, details)
+
+ # Generate auth details if none were supplied yet
+ async def generate_auth_details(self):
+ if not self.device_auth.device_auth_file_exists():
+ device_auth_data = await self.auth.generate_device_auth()
+ details = {
+ 'device_id': device_auth_data['deviceId'],
+ 'account_id': device_auth_data['accountId'],
+ 'secret': device_auth_data['secret'],
+ }
+ self.auth.__dict__.update(details)
+ self.dispatch_event(
+ 'device_auth_generate',
+ details,
+ __fortnite_account_key__
+ )
+
+ async def event_ready(self):
+ print('----------------')
+ print('FortniteClient ready as:')
+ print(self.user.display_name)
+ print(self.user.id)
+ print('----------------')
+
+ await self.generate_auth_details()
+
+ # Accept pending friends
+ for friend_request in self.incoming_pending_friends:
+ await self.event_friend_request(friend_request)
+
+ async def event_party_invite(self, invitation: fortnitepy.ReceivedPartyInvitation):
+ await PartyInvite.on_event(invitation = invitation)
+
+ async def event_friend_request(self, request: typing.Union[fortnitepy.friend.IncomingPendingFriend, fortnitepy.friend.OutgoingPendingFriend]):
+ await IncomingFriendRequest.on_event(request)
+
+ async def event_friend_presence(self, before, after: fortnitepy.Presence):
+ await FriendPresence.on_event(before, after, self.observers)
+
+# Debug
+#client = FortniteClient()
+#client.run() \ No newline at end of file