Compare commits

...
2 changed files with 28 additions and 1 deletions
+27 -1
View File
@@ -19,7 +19,12 @@ class GuildListener(commands.Cog, name="Guild Listener"):
@commands.Cog.listener() @commands.Cog.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.
Args:
guild (nextcord.Guild): Guild that was joined.
"""
with Session(engine) as session: with Session(engine) as session:
stmt = select(Guild).where(Guild.GuildId == guild.id) stmt = select(Guild).where(Guild.GuildId == guild.id)
@@ -31,6 +36,7 @@ class GuildListener(commands.Cog, name="Guild Listener"):
session.add(new_guild) session.add(new_guild)
else: else:
guild_data.GuildName = guild.name guild_data.GuildName = guild.name
guild_data.Active = True
session.commit() session.commit()
@@ -39,6 +45,26 @@ class GuildListener(commands.Cog, name="Guild Listener"):
imcompiling: nextcord.User = await self.bot.fetch_user(206602713511886849) imcompiling: nextcord.User = await self.bot.fetch_user(206602713511886849)
await imcompiling.send(f'Agon has joined server "{guild.name}"!') await imcompiling.send(f'Agon has joined server "{guild.name}"!')
@commands.Cog.listener()
async def on_guild_remove(self, guild: nextcord.Guild):
"""
Listens to when the bot has been removed from a guild. Update's the database to record the active flag as false.
Args:
guild (nextcord.Guild): Guild that was left.
"""
with Session(engine) as session:
stmt = select(Guild).where(Guild.GuildId == guild.id)
guild_data = session.scalar(stmt)
guild_data.Active = False
session.commit()
# let imcompiling#2272 know about leaving a server.
# 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 been removed from "{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.
+1
View File
@@ -6,6 +6,7 @@ CREATE TABLE Guilds(
GuildName varchar(95) not null, GuildName varchar(95) not null,
SubmissionChannel bigint unsigned, SubmissionChannel bigint unsigned,
VerificationChannel bigint unsigned, VerificationChannel bigint unsigned,
Active boolean DEFAULT true,
PRIMARY KEY (GuildId) PRIMARY KEY (GuildId)
); );