Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Use GuildJoinEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
norinorin committed Oct 1, 2021
1 parent c7925bc commit f73b2ca
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions nokari/plugins/extras/events.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import asyncio
import logging
from contextlib import suppress
from functools import partial
Expand All @@ -13,8 +12,7 @@
Message,
)
from hikari.colors import Color
from hikari.events.guild_events import GuildLeaveEvent
from hikari.events.shard_events import ShardPayloadEvent
from hikari.events.guild_events import GuildJoinEvent, GuildLeaveEvent
from hikari.guilds import GatewayGuild
from lightbulb import Bot, errors, plugins

Expand Down Expand Up @@ -53,7 +51,7 @@ def __init__(self, bot: Bot):
@property
def optional_events(self):
return (
(ShardPayloadEvent, "on_guild_join"),
(GuildJoinEvent, "on_guild_join"),
(GuildLeaveEvent, "on_guild_leave"),
)

Expand Down Expand Up @@ -147,19 +145,8 @@ async def execute_guild_webhook(
embed=embed, username=f"{self.bot.get_me()} {suffix}"
)

async def on_guild_join(self, event: ShardPayloadEvent) -> None:
if event.name == "GUILD_CREATE" and event.payload.get("unavailable") is None:
for _ in range(5):
if not (guild := self.bot.cache.get_guild(int(event.payload["id"]))):
await asyncio.sleep(0.5) # wait for Hikari to cache the guild, kekw
continue

await self.execute_guild_webhook(
guild,
Color.of("#00FF00"),
"(+)",
)
break
async def on_guild_join(self, event: GuildJoinEvent) -> None:
await self.execute_guild_webhook(event.guild, Color.of("#00FF00"), "(+)")

async def on_guild_leave(self, _: GuildLeaveEvent) -> None:
# TODO: event.old_guild
Expand Down

0 comments on commit f73b2ca

Please sign in to comment.