diff --git a/discordbot/titanembeds/bot.py b/discordbot/titanembeds/bot.py index 7e58ce4..598e65b 100644 --- a/discordbot/titanembeds/bot.py +++ b/discordbot/titanembeds/bot.py @@ -3,6 +3,7 @@ from titanembeds.database import DatabaseInterface import discord import aiohttp import asyncio +import sys class Titan(discord.Client): def __init__(self): @@ -55,22 +56,25 @@ class Titan(discord.Client): traceback.print_exc() await self.logout() return - - for server in self.servers: - await self.database.update_guild(server) - if server.large: - await request_offline_members(server) - server_bans = await self.get_bans(server) - for member in server.members: - banned = member.id in [u.id for u in server_bans] - await self.database.update_guild_member( - member, - True, - banned - ) - await self.database.flag_unactive_guild_members(server.id, server.members) - await self.database.flag_unactive_bans(server.id, server_bans) - await self.database.remove_unused_guilds(self.servers) + + if "no-init" not in sys.argv: + for server in self.servers: + await self.database.update_guild(server) + if server.large: + await request_offline_members(server) + server_bans = await self.get_bans(server) + for member in server.members: + banned = member.id in [u.id for u in server_bans] + await self.database.update_guild_member( + member, + True, + banned + ) + await self.database.flag_unactive_guild_members(server.id, server.members) + await self.database.flag_unactive_bans(server.id, server_bans) + await self.database.remove_unused_guilds(self.servers) + else: + print("Skipping indexing server due to no-init flag") async def on_message(self, message): await self.database.push_message(message) @@ -131,9 +135,9 @@ class Titan(discord.Client): await self.database.update_guild_member(memberafter) async def on_member_ban(self, member): - if role.server.me not in role.server.members: + if self.user.id == member.id: return await self.database.update_guild_member(member, active=False, banned=True) - async def on_member_unban(self, member): - await self.database.update_guild_member(member, active=False, banned=False) + async def on_member_unban(self, server, user): + await self.database.unban_server_user(user, server) \ No newline at end of file diff --git a/discordbot/titanembeds/database/__init__.py b/discordbot/titanembeds/database/__init__.py index d5fefb5..3f806d0 100644 --- a/discordbot/titanembeds/database/__init__.py +++ b/discordbot/titanembeds/database/__init__.py @@ -235,6 +235,16 @@ class DatabaseInterface(object): dbmember.roles = json.dumps(self.list_role_ids(member.roles)) session.commit() + async def unban_server_user(self, user, server): + async with threadpool(): + with self.get_session() as session: + dbmember = session.query(GuildMembers) \ + .filter(GuildMembers.guild_id == server.id) \ + .filter(GuildMembers.user_id == user.id).first() + if dbmember: + dbmember.banned = False + session.commit() + async def flag_unactive_guild_members(self, guild_id, guild_members): async with threadpool(): with self.get_session() as session: diff --git a/webapp/titanembeds/blueprints/api/api.py b/webapp/titanembeds/blueprints/api/api.py index d21c69e..6fbab52 100644 --- a/webapp/titanembeds/blueprints/api/api.py +++ b/webapp/titanembeds/blueprints/api/api.py @@ -28,7 +28,7 @@ def checkUserRevoke(guild_id, user_key=None): if banned: return revoked dbUser = GuildMembers.query.filter(GuildMembers.guild_id == guild_id).filter(GuildMembers.user_id == session["user_id"]).first() - revoked = not dbUser.active + revoked = not dbUser or not dbUser.active return revoked def checkUserBanned(guild_id, ip_address=None):