Merge branch '62-dm-on-join'
build

This commit is contained in:
2023-03-29 16:42:41 -04:00
+16 -3
View File
@@ -4,6 +4,7 @@ Defines cog for guild listeners. Contains functions for various guild events.
import nextcord import nextcord
from nextcord.ext import commands from nextcord.ext import commands
from sqlalchemy import select
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
# pylint: disable=import-error # pylint: disable=import-error
@@ -20,12 +21,24 @@ class GuildListener(commands.Cog, name="Guild Listener"):
async def on_guild_join(self, guild: nextcord.Guild): async def on_guild_join(self, guild: nextcord.Guild):
"""Listener for Guild Join. Adds guild to database.""" """Listener for Guild Join. Adds guild to database."""
new_guild = Guild(GuildId=guild.id, GuildName=guild.name)
with Session(engine) as session: with Session(engine) as session:
session.add(new_guild) stmt = select(Guild).where(Guild.GuildId == guild.id)
guild_data = session.scalar(stmt)
# just in case check if the guild already exists
if guild_data is None:
new_guild = Guild(GuildId=guild.id, GuildName=guild.name)
session.add(new_guild)
else:
guild_data.GuildName = guild.name
session.commit() session.commit()
# let imcompiling#2272 know about a new server joining!
# staying with fetch due to intents not being set up correctly. Maybe change to get eventually.
imcompiling: nextcord.User = await self.bot.fetch_user(206602713511886849)
await imcompiling.send(f'Agon has joined server "{guild.name}"!')
# This function will be called when this extension is loaded. # This function will be called when this extension is loaded.
# It is necessary to add these functions to the bot. # It is necessary to add these functions to the bot.