Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: async cache and object rewrite #1185

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

alentoghostflame
Copy link
Collaborator

Summary

This PR aims to

  • make accesses to the cache asynchronous,
  • allow the cache to be modified and replaced by users,
  • refine how Discord objects are created,
  • centralize the creation of Discord objects in a way that is modifiable and replaceable by users,
  • reduce the dependency on guild intents,
  • and allow bots to be closer to stateless.

To say this is in progress is an understatement. It will likely be quite a while before anything here is relatively usable, let alone useful. This is being published so people can monitor this and raise issues about the architecture before I dive too far into the wrong direction.

This is a Code Change

  • I have tested my changes.
  • I have updated the documentation to reflect the changes.
  • I have run task pyright and fixed the relevant issues.

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
nextcord/cache.py Outdated Show resolved Hide resolved
@EmreTech EmreTech changed the title !feat: async cache and object rewrite feat!: async cache and object rewrite May 21, 2024
nextcord/cache.py Outdated Show resolved Hide resolved

def __repr__(self) -> str:
name = self.__class__.__name__
return f"<{name} id={self.id} channel_id={self.channel_id} type={self.type}>"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return f"<{name} id={self.id} channel_id={self.channel_id} type={self.type}>"
return f"<{name} id={self.id!r} channel_id={self.channel_id!r} type={self.type!r}>"

Comment on lines +551 to +554
if inspect.iscoroutinefunction(func):
await func(data)
else:
func(data)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this just utils.maybe_coro?

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
nextcord/cache.py Outdated Show resolved Hide resolved
return self._members.pop((member_id, guild_id)) is not None

async def get_member(self, member_id: int, guild_id: int) -> Optional[MemberData]:
return self._members.get((member_id, guild_id), None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually None is the default for dict.get.

Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
Signed-off-by: Alex Schoenhofen <alexanderschoenhofen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants