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 6 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 <[email protected]>
nextcord/cache.py Outdated Show resolved Hide resolved
@EmmmaTech EmmmaTech 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 <[email protected]>
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 <[email protected]>
@EmmmaTech EmmmaTech added t: enhancement Type: enhancement - new feature or request s: in progress Status: the issue or PR is in development/progress p: high Priority: high - should be worked on as soon as reasonable t: refactor Type: refactor - this is a code change but does not fix a bug/add features 3.0 The issue/PR should go for the 3.0 release labels Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 The issue/PR should go for the 3.0 release p: high Priority: high - should be worked on as soon as reasonable s: in progress Status: the issue or PR is in development/progress t: enhancement Type: enhancement - new feature or request t: refactor Type: refactor - this is a code change but does not fix a bug/add features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants