-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement missing stuff for scheduled events (#1507)
* feat: Implement gateway support for scheduled events * fix: add optional to user add/remove * refactor: pre-commit'ed * refactor: change attrs to props and add `attrs.field` * refactor: set repr to True * feat(client): add `get_scheduled_event` helper method * refactor: use cache helpers in methods * chore: replace typing
- Loading branch information
Showing
7 changed files
with
193 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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