mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-15 02:21:21 +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):
|
async def on_server_join(self, guild):
|
||||||
await self.database.update_guild(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):
|
async def on_server_remove(self, guild):
|
||||||
await self.database.remove_guild(guild)
|
await self.database.remove_guild(guild)
|
||||||
|
@ -188,6 +188,9 @@ class DatabaseInterface(object):
|
|||||||
disguild = discord.utils.get(guilds, id=guild.guild_id)
|
disguild = discord.utils.get(guilds, id=guild.guild_id)
|
||||||
if not disguild:
|
if not disguild:
|
||||||
changed = True
|
changed = True
|
||||||
|
dbmsgs = session.query(Messages).filter(Messages.guild_id == guild.guild_id).all()
|
||||||
|
for msg in dbmsgs:
|
||||||
|
session.delete(msg)
|
||||||
session.delete(guild)
|
session.delete(guild)
|
||||||
if changed:
|
if changed:
|
||||||
session.commit()
|
session.commit()
|
||||||
@ -197,6 +200,9 @@ class DatabaseInterface(object):
|
|||||||
with self.get_session() as session:
|
with self.get_session() as session:
|
||||||
gui = session.query(Guilds).filter(Guilds.guild_id == guild.id).first()
|
gui = session.query(Guilds).filter(Guilds.guild_id == guild.id).first()
|
||||||
if gui:
|
if gui:
|
||||||
|
dbmsgs = session.query(Messages).filter(Messages.guild_id == guild.id).all()
|
||||||
|
for msg in dbmsgs:
|
||||||
|
session.delete(msg)
|
||||||
session.delete(gui)
|
session.delete(gui)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user