-
Notifications
You must be signed in to change notification settings - Fork 188
feat: Implement missing stuff for scheduled events #1507
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
Merged
LordOfPolls
merged 8 commits into
interactions-py:unstable
from
Damego:events-for-scheduled-events
Aug 3, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
44ef33f
feat: Implement gateway support for scheduled events
Damego 44ee959
fix: add optional to user add/remove
Damego d0dbd03
refactor: pre-commit'ed
Damego 08d3aa7
refactor: change attrs to props and add `attrs.field`
Damego 1e35818
refactor: set repr to True
Damego 1226777
feat(client): add `get_scheduled_event` helper method
Damego 2af947f
refactor: use cache helpers in methods
Damego f4f9152
chore: replace typing
Damego File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import copy | ||
from typing import TYPE_CHECKING | ||
|
||
import interactions.api.events as events | ||
from interactions.client.const import MISSING | ||
from interactions.models import ScheduledEvent | ||
from ._template import EventMixinTemplate, Processor | ||
|
||
if TYPE_CHECKING: | ||
from interactions.api.events import RawGatewayEvent | ||
|
||
__all__ = ("ScheduledEvents",) | ||
|
||
|
||
class ScheduledEvents(EventMixinTemplate): | ||
@Processor.define() | ||
async def _on_raw_guild_scheduled_event_create(self, event: "RawGatewayEvent") -> None: | ||
scheduled_event = self.cache.place_scheduled_event_data(event.data) | ||
|
||
self.dispatch(events.GuildScheduledEventCreate(scheduled_event)) | ||
|
||
@Processor.define() | ||
async def _on_raw_guild_scheduled_event_update(self, event: "RawGatewayEvent") -> None: | ||
before = copy.copy(self.cache.get_scheduled_event(event.data.get("id"))) | ||
after = self.cache.place_scheduled_event_data(event.data) | ||
|
||
self.dispatch(events.GuildScheduledEventUpdate(before or MISSING, after)) | ||
|
||
@Processor.define() | ||
async def _on_raw_guild_scheduled_event_delete(self, event: "RawGatewayEvent") -> None: | ||
# for some reason this event returns the deleted scheduled event data? | ||
# so we create an object from it | ||
scheduled_event = ScheduledEvent.from_dict(event.data, self) | ||
self.cache.delete_scheduled_event(event.data.get("id")) | ||
|
||
self.dispatch(events.GuildScheduledEventDelete(scheduled_event)) | ||
|
||
@Processor.define() | ||
async def _on_raw_guild_scheduled_event_user_add(self, event: "RawGatewayEvent") -> None: | ||
scheduled_event = self.cache.get_scheduled_event(event.data.get("guild_scheduled_event_id")) | ||
user = self.cache.get_user(event.data.get("user_id")) | ||
|
||
self.dispatch(events.GuildScheduledEventUserAdd(event.data.get("guild_id"), scheduled_event, user)) | ||
|
||
@Processor.define() | ||
async def _on_raw_guild_scheduled_event_user_remove(self, event: "RawGatewayEvent") -> None: | ||
scheduled_event = self.cache.get_scheduled_event(event.data.get("guild_scheduled_event_id")) | ||
user = self.cache.get_user(event.data.get("user_id")) | ||
|
||
self.dispatch(events.GuildScheduledEventUserRemove(event.data.get("guild_id"), scheduled_event, user)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.