Skip to content

Commit

Permalink
✨ [Feature] Cache Guild Info At Start
Browse files Browse the repository at this point in the history
  • Loading branch information
foxwhite25 committed May 3, 2023
1 parent 145bf78 commit f67c02e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
6 changes: 3 additions & 3 deletions qq/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ def image(self) -> _EmbedMediaProxy:
"""
return EmbedProxy(getattr(self, '_image', {})) # type: ignore
return EmbedProxy(getattr(self, '_thumbnail', {})) # type: ignore

def set_image(self: E, *, url: MaybeEmpty[Any]) -> E:
"""设置嵌入内容的图像。
Expand All @@ -620,11 +620,11 @@ def set_image(self: E, *, url: MaybeEmpty[Any]) -> E:

if url is EmptyEmbed:
try:
del self._image
del self._thumbnail
except AttributeError:
pass
else:
self._image = {
self._thumbnail = {
'url': str(url),
}

Expand Down
10 changes: 3 additions & 7 deletions qq/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,7 @@ def _from_data(self, guild: GuildPayload) -> None:
self.max_members = guild.get('max_members')
self.description = guild.get('description')
self.joined_at = guild.get('joined_at')
self.unavailable: bool = guild.get('unavailable', False)
self._roles: Dict[int, Role] = {}
self._permission: List[Permission] = []
state = self._state # speed up attribute access
self._large: Optional[bool] = None if self._member_count is None else self._member_count >= 250
for r in guild.get('roles', []):
role = Role(guild=self, data=r, state=state)
self._roles[role.id] = role

def _add_channel(self, channel: GuildChannel, /) -> None:
self._channels[channel.id] = channel
Expand All @@ -171,6 +164,9 @@ def __repr__(self) -> str:
return f'<Guild {inner}>'

async def fill_in(self):
data = await self._state.http.get_guild(self.id)
self._from_data(data)

try:
channels = await self._state.http.get_guild_channels(self.id)
except HTTPException:
Expand Down
6 changes: 3 additions & 3 deletions qq/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def handle_message_parameters(
else:
pass

if replace_url:
if replace_url and 'content' in payload:
payload['content'] = payload['content'].replace(".", "\ufeff.")

if message_reference is not MISSING:
Expand Down Expand Up @@ -475,8 +475,8 @@ def edit_channel(
'parent_id',
'position',
'type',
'private_type'
'speak_permission'
'private_type',
'speak_permission',
)
payload = {k: v for k, v in options.items() if k in valid_keys}
return self.request(r, reason=reason, json=payload)
Expand Down

0 comments on commit f67c02e

Please sign in to comment.