77
88from collections import namedtuple
99from datetime import datetime
10- from typing import List , Optional , Union
10+ from typing import List , Optional , Union , Any , Generator
1111
1212import aiohttp
1313
14+ from ... import ClanWar
1415from ...http import json_or_text
1516from ...utils import correct_tag
1617from ...wars import ClanWar
@@ -45,7 +46,7 @@ def extract_expiry_from_jwt_token(token: Union[str, bytes]) -> Optional[datetime
4546 return None
4647
4748
48- async def login (username : str , password : str , clash_client ) -> "FullWarClient" :
49+ async def login (username : str , password : str , coc_client ) -> "FullWarClient" :
4950 """Eases logging into the API client.
5051
5152 For more information on this project, please join the discord server - <discord.gg/Eaja7gJ>
@@ -59,17 +60,16 @@ async def login(username: str, password: str, clash_client) -> "FullWarClient":
5960 Your username as given on the discord server.
6061 password : str
6162 Your password as given on the discord server
62- loop : Optional[:class:`asyncio.AbstractEventLoop`]
63- The :class:`asyncio.AbstractEventLoop` to use for HTTP requests.
64- An :func:`asyncio.get_event_loop()` will be used if ``None`` is passed
63+ coc_client: coc.Client
64+ Client to use
6565 """
6666 if not isinstance (username , str ) or not isinstance (password , str ):
6767 raise TypeError ("username and password must both be a string" )
6868 if not username or not password :
6969 raise ValueError ("username or password must not be an empty string." )
7070
7171 loop = asyncio .get_running_loop ()
72- return FullWarClient (username , password , clash_client , loop )
72+ return FullWarClient (username , password , coc_client , loop )
7373
7474
7575class FullWarClient :
@@ -86,7 +86,7 @@ class FullWarClient:
8686 Your username as given on the discord server.
8787 password : str
8888 Your password as given on the discord server
89- clash_client : coc.Client
89+ coc_client : coc.Client
9090 Client to use
9191
9292 loop : Optional[:class:`asyncio.AbstractEventLoop`]
@@ -97,12 +97,12 @@ class FullWarClient:
9797
9898 BASE_URL = "https://fw-api.teamutils.com"
9999
100- __slots__ = ("username" , "password" , "clash_client " , "loop" , "key" , "http_session" )
100+ __slots__ = ("username" , "password" , "coc_client " , "loop" , "key" , "http_session" )
101101
102- def __init__ (self , username : str , password : str , clash_client , loop : asyncio .AbstractEventLoop = None ):
102+ def __init__ (self , username : str , password : str , coc_client , loop : asyncio .AbstractEventLoop = None ):
103103 self .username = username
104104 self .password = password
105- self .clash_client = clash_client
105+ self .coc_client = coc_client
106106
107107 self .loop = loop or asyncio .get_event_loop ()
108108 self .key = None # set in get_key()
@@ -150,13 +150,11 @@ async def _refresh_key(self):
150150 payload = await self ._request ("POST" , "/login" , token_request = True , json = data )
151151 self .key = AccessToken (payload ["access_token" ], extract_expiry_from_jwt_token (payload ["access_token" ]))
152152
153- async def war_result (self , clan_tag : str , preparation_start : int = 0 ) -> ClanWar :
153+ async def war_result (self , clan_tag : str , preparation_start : int = 0 ) -> ClanWar | None :
154154 """Get a stored war result.
155155
156156 Parameters
157157 ----------
158- client: coc.Client
159- instance of the clash client
160158 clan_tag: str
161159 The clan tag to find war result for.
162160 preparation_start: int
@@ -172,21 +170,17 @@ async def war_result(self, clan_tag: str, preparation_start: int = 0) -> ClanWar
172170 f"/war_result?clan_tag={ correct_tag (clan_tag , '%23' )} "
173171 f"&prep_start={ str (preparation_start )} " )
174172 try :
175- return ClanWar (data = data ["response" ], client = self .clash_client )
173+ return ClanWar (data = data ["response" ], client = self .coc_client )
176174 except (IndexError , KeyError , TypeError , ValueError ):
177175 return None
178176
179- async def war_result_log (self , clan_tag : str , preparation_start : int = 0 ) -> List [ClanWar ] :
177+ async def war_result_log (self , clan_tag : str ) -> Generator [ClanWar , Any , None ] | None :
180178 """Get all stored war results for a clan.
181179
182180 Parameters
183181 ----------
184- client: coc.Client
185- instance of the clash client
186182 clan_tag: str
187183 The clan tag to find war result for.
188- preparation_start: int
189- Preparation start of a specific war result to find.
190184
191185 Returns
192186 --------
@@ -199,12 +193,11 @@ async def war_result_log(self, clan_tag: str, preparation_start: int = 0) -> Lis
199193 try :
200194 responses = data ["log" ]
201195
202- generator = (ClanWar (data = response ["response" ], client = self .clash_client ) for response in responses )
196+ generator = (ClanWar (data = response ["response" ], client = self .coc_client ) for response in responses )
203197 return generator
204198 except (IndexError , KeyError , TypeError , ValueError ):
205199 return None
206200
207-
208201 async def register_war (self , clan_tag : str , preparation_start : int = 0 ):
209202 """Registers a war.
210203
@@ -218,4 +211,3 @@ async def register_war(self, clan_tag: str, preparation_start: int = 0):
218211 return await self ._request ("POST" ,
219212 f"/register_war?clan_tag={ correct_tag (clan_tag , '%23' )} "
220213 f"&prep_start={ str (preparation_start )} " )
221-
0 commit comments