Fixed some discord bot issues and added no-init flag to not index at start

This commit is contained in:
Jeremy Zhang 2017-05-14 21:05:51 +00:00
parent c63ce42524
commit 2ab18abc11
3 changed files with 34 additions and 20 deletions

View File

@ -3,6 +3,7 @@ from titanembeds.database import DatabaseInterface
import discord
import aiohttp
import asyncio
import sys
class Titan(discord.Client):
def __init__(self):
@ -56,6 +57,7 @@ class Titan(discord.Client):
await self.logout()
return
if "no-init" not in sys.argv:
for server in self.servers:
await self.database.update_guild(server)
if server.large:
@ -71,6 +73,8 @@ class Titan(discord.Client):
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)

View File

@ -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:

View File

@ -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):