|
44 | 44 | cast, |
45 | 45 | ) |
46 | 46 |
|
| 47 | +from discord.soundboard import SoundboardSound |
| 48 | + |
47 | 49 | from .. import utils |
48 | 50 | from ..activity import BaseActivity |
49 | 51 | from ..automod import AutoModRule |
@@ -237,7 +239,7 @@ def __init__( |
237 | 239 | self._voice_clients: dict[int, VoiceClient] = {} |
238 | 240 |
|
239 | 241 | if not intents.members or cache_flags._empty: |
240 | | - self.store_user = self.create_user # type: ignore |
| 242 | + self.store_user = self.create_user_async # type: ignore |
241 | 243 | self.deref_user = self.deref_user_no_intents # type: ignore |
242 | 244 |
|
243 | 245 | self.cache_app_emojis: bool = options.get("cache_app_emojis", False) |
@@ -320,6 +322,9 @@ async def deref_user(self, user_id: int) -> None: |
320 | 322 | def create_user(self, data: UserPayload) -> User: |
321 | 323 | return User(state=self, data=data) |
322 | 324 |
|
| 325 | + async def create_user_async(self, data: UserPayload) -> User: |
| 326 | + return User(state=self, data=data) |
| 327 | + |
323 | 328 | def deref_user_no_intents(self, user_id: int) -> None: |
324 | 329 | return |
325 | 330 |
|
@@ -373,6 +378,21 @@ async def _remove_guild(self, guild: Guild) -> None: |
373 | 378 |
|
374 | 379 | del guild |
375 | 380 |
|
| 381 | + async def _add_default_sounds(self) -> None: |
| 382 | + default_sounds = await self.http.get_default_sounds() |
| 383 | + for default_sound in default_sounds: |
| 384 | + sound = SoundboardSound(state=self, http=self.http, data=default_sound) |
| 385 | + await self._add_sound(sound) |
| 386 | + |
| 387 | + async def _add_sound(self, sound: SoundboardSound) -> None: |
| 388 | + await self.cache.store_sound(sound) |
| 389 | + |
| 390 | + async def _remove_sound(self, sound: SoundboardSound) -> None: |
| 391 | + await self.cache.delete_sound(sound.id) |
| 392 | + |
| 393 | + async def get_sounds(self) -> list[SoundboardSound]: |
| 394 | + return list(await self.cache.get_all_sounds()) |
| 395 | + |
376 | 396 | async def get_emojis(self) -> list[GuildEmoji | AppEmoji]: |
377 | 397 | return await self.cache.get_all_emojis() |
378 | 398 |
|
@@ -487,15 +507,15 @@ async def query_members( |
487 | 507 | ) |
488 | 508 | raise |
489 | 509 |
|
490 | | - def _get_create_guild(self, data): |
| 510 | + async def _get_create_guild(self, data): |
491 | 511 | if data.get("unavailable") is False: |
492 | 512 | # GUILD_CREATE with unavailable in the response |
493 | 513 | # usually means that the guild has become available |
494 | 514 | # and is therefore in the cache |
495 | | - guild = self._get_guild(int(data["id"])) |
| 515 | + guild = await self._get_guild(int(data["id"])) |
496 | 516 | if guild is not None: |
497 | 517 | guild.unavailable = False |
498 | | - guild._from_data(data) |
| 518 | + await guild._from_data(data, self) |
499 | 519 | return guild |
500 | 520 |
|
501 | 521 | return self._add_guild_from_data(data) |
@@ -660,6 +680,7 @@ async def _delay_ready(self) -> None: |
660 | 680 | future = asyncio.ensure_future(self.chunk_guild(guild)) |
661 | 681 | current_bucket.append(future) |
662 | 682 | else: |
| 683 | + await self._add_default_sounds() |
663 | 684 | future = self.loop.create_future() |
664 | 685 | future.set_result([]) |
665 | 686 |
|
|
0 commit comments