Compare commits
28
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc10bb518c | ||
|
|
90131f6395 | ||
|
|
1814867c09 | ||
|
|
307f61934e | ||
|
|
00265f2f58 | ||
|
|
93d558edbc | ||
|
|
0f2b1aa2e6 | ||
|
|
3f6bac99ab | ||
|
|
46e2955642 | ||
|
|
ac9bf6b35f | ||
|
|
869b2ccb82 | ||
|
|
3ddfdfe9b0 | ||
|
|
3860e74579 | ||
|
|
3b49a6ec2a | ||
|
|
2f89588358 | ||
|
|
0513df944f | ||
|
|
ddf319b9d5 | ||
|
|
13f5bc0aab | ||
|
|
e6f3fcb604 | ||
|
|
eaa342d479 | ||
|
|
ac11f3e462 | ||
|
|
106b394c44 | ||
|
|
6c1505685b | ||
|
|
2e681be690 | ||
|
|
5448f2a426 | ||
|
|
7647c355af | ||
|
|
a95fca40f9 | ||
|
|
148ba253cf |
@@ -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:
|
||||||
|
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)
|
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user