This repository has been archived by the owner on May 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sync utilities * split some utils from tag cogs * splitting help and event to each cogs * [pre-commit] auto fixes Co-authored-by: clemiee <clemiee@users.noreply.github.com>
- Loading branch information
Clemie McCartney
and
clemiee
authored
Sep 8, 2022
1 parent
da48c87
commit 451b6d4
Showing
5 changed files
with
124 additions
and
100 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import datetime | ||
import os | ||
|
||
import aiohttp | ||
from dotenv import load_dotenv | ||
from naff import ( | ||
Activity, | ||
ActivityType, | ||
Embed, | ||
Extension, | ||
IntervalTrigger, | ||
Status, | ||
Task, | ||
listen, | ||
) | ||
from naff.api.events.discord import GuildJoin, GuildLeft | ||
|
||
from core.base import CustomClient | ||
from utilities.events import * | ||
|
||
load_dotenv() | ||
|
||
|
||
class events(Extension): | ||
bot: CustomClient | ||
|
||
@listen() | ||
async def on_guild_join(self, event: GuildJoin): | ||
if self.bot.is_ready: | ||
guild = event.guild | ||
e = Embed(color=0x53DDA4, title="Joined a Guild") | ||
await send_guild_stats(self, e, guild, 997921447701921953) | ||
|
||
@listen() | ||
async def on_guild_left(self, event: GuildLeft): | ||
guild = event.guild | ||
e = Embed(color=0x53DDA4, title="Left a Guild") | ||
await send_guild_stats(self, e, guild, 997921473861799976) | ||
|
||
@Task.create(IntervalTrigger(seconds=30)) | ||
async def presence_changes(self): | ||
await self.bot.change_presence( | ||
status=Status.ONLINE, | ||
activity=Activity( | ||
name=f"{len(self.bot.guilds)} servers | /help", | ||
type=ActivityType.COMPETING, | ||
), | ||
) | ||
|
||
@listen() | ||
async def on_startup(self): | ||
"""Gets triggered on startup""" | ||
|
||
self.presence_changes.start() | ||
|
||
@Task.create(IntervalTrigger(minutes=30)) | ||
async def upload_stats(self): | ||
payload = { | ||
"server_count": len(self.bot.guilds), | ||
} | ||
headers = { | ||
"Authorization": str(os.getenv("TOPGG_TOKEN")), | ||
"Content-Type": "application/json", | ||
} | ||
async with aiohttp.ClientSession() as session: | ||
await session.post( | ||
f"https://top.gg/api/bots/{self.bot.user.id}/stats", | ||
json=payload, | ||
headers=headers, | ||
) | ||
|
||
|
||
def setup(bot: CustomClient): | ||
"""Let naff load the extension""" | ||
|
||
events(bot) |
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,17 @@ | ||
async def send_guild_stats(self, e, guild, r_channel): | ||
owner = await self.bot.fetch_user(guild._owner_id) | ||
e.add_field(name="Name", value=guild.name) | ||
e.add_field(name="ID", value=guild.id) | ||
e.add_field(name="Owner", value=f"{owner.mention} (ID: {owner.id})") | ||
|
||
total = guild.member_count | ||
e.add_field(name="Members", value=str(total)) | ||
|
||
if guild.icon: | ||
e.set_thumbnail(url=guild.icon.url) | ||
|
||
if guild.me: | ||
e.timestamp = guild.me.joined_at | ||
|
||
ch = self.bot.get_channel(r_channel) | ||
await ch.send(embed=e) |