mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-14 18:11:23 +01:00
Fixed some discord bot issues and added no-init flag to not index at start
This commit is contained in:
parent
c63ce42524
commit
2ab18abc11
@ -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)
|
@ -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:
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user