1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/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()
observer = None
def __init__(self, friendPresenceObserver: PresenceObserver):
self.observer = friendPresenceObserver
if self.device_auth.device_auth_file_exists():
self.__auth_device_auth()
else:
self.__auth_authorization_code()
def get_friends(self):
return self.friends
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_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.observer)
|