-
Notifications
You must be signed in to change notification settings - Fork 43
[FAQ] migrate from 0.2 to 0.3
Housa Hitomi edited this page Aug 19, 2022
·
3 revisions
almost all methods is deprecated, should alter to methods in Bot.client
e.g.
- v0.2:
bot.send()-> v0.3:bot.client.send() - v0.2:
bot.fetch_guild()-> v0.3:bot.client.fetch_guild()
Bot is redesigned in combination pattern, which was designed with a fake-inheritance pattern in v0.2
fake-inheritance:
Bot has same methods as Client but not inherited from Client,
this is implemented by copy-paste signature from Client to Bot,
and delegate method call to embedded client
for example:
# client.py
async def list_guild(self) -> List[Guild]:
"""list guilds which the client joined"""
guilds_data = (await self.gate.exec_pagination_req(api.Guild.list()))
return [Guild(_gate_=self.gate, _lazy_loaded_=True, **i) for i in guilds_data]
# bot.py
async def list_guild(self) -> List[Guild]:
"""list guilds the bot joined"""
return await self.client.list_guild()this implementation couples client and bot deeply, and make code duplicated and hard to maintain, a bad approach
some methods' name changed:
| v0.2.x | v0.3.x |
|---|---|
| list_guild | fetch_guild_list |
| list_game | fetch_game_list |
| create_game | register_game |
| delete_game | unregister_game |
for semantic unification: fetch means communicates with khl server and get data from khl server
for disambiguating: create_game can be explained as make a game rather than register a game process on khl, delete_game is in the same