mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-14 18:11:23 +01:00
Populate msgs on server join and remove on leave
This commit is contained in:
parent
4bb559420f
commit
a621fa8b0a
@ -84,6 +84,9 @@ class Titan(discord.Client):
|
||||
|
||||
async def on_server_join(self, guild):
|
||||
await self.database.update_guild(guild)
|
||||
for channel in guild.channels:
|
||||
async for message in self.logs_from(channel, limit=50, reverse=True):
|
||||
await self.database.push_message(message)
|
||||
|
||||
async def on_server_remove(self, guild):
|
||||
await self.database.remove_guild(guild)
|
||||
|
@ -188,6 +188,9 @@ class DatabaseInterface(object):
|
||||
disguild = discord.utils.get(guilds, id=guild.guild_id)
|
||||
if not disguild:
|
||||
changed = True
|
||||
dbmsgs = session.query(Messages).filter(Messages.guild_id == guild.guild_id).all()
|
||||
for msg in dbmsgs:
|
||||
session.delete(msg)
|
||||
session.delete(guild)
|
||||
if changed:
|
||||
session.commit()
|
||||
@ -197,6 +200,9 @@ class DatabaseInterface(object):
|
||||
with self.get_session() as session:
|
||||
gui = session.query(Guilds).filter(Guilds.guild_id == guild.id).first()
|
||||
if gui:
|
||||
dbmsgs = session.query(Messages).filter(Messages.guild_id == guild.id).all()
|
||||
for msg in dbmsgs:
|
||||
session.delete(msg)
|
||||
session.delete(gui)
|
||||
session.commit()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user