mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-15 02:21:21 +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 discord
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import sys
|
||||||
|
|
||||||
class Titan(discord.Client):
|
class Titan(discord.Client):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -56,21 +57,24 @@ class Titan(discord.Client):
|
|||||||
await self.logout()
|
await self.logout()
|
||||||
return
|
return
|
||||||
|
|
||||||
for server in self.servers:
|
if "no-init" not in sys.argv:
|
||||||
await self.database.update_guild(server)
|
for server in self.servers:
|
||||||
if server.large:
|
await self.database.update_guild(server)
|
||||||
await request_offline_members(server)
|
if server.large:
|
||||||
server_bans = await self.get_bans(server)
|
await request_offline_members(server)
|
||||||
for member in server.members:
|
server_bans = await self.get_bans(server)
|
||||||
banned = member.id in [u.id for u in server_bans]
|
for member in server.members:
|
||||||
await self.database.update_guild_member(
|
banned = member.id in [u.id for u in server_bans]
|
||||||
member,
|
await self.database.update_guild_member(
|
||||||
True,
|
member,
|
||||||
banned
|
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.flag_unactive_guild_members(server.id, server.members)
|
||||||
await self.database.remove_unused_guilds(self.servers)
|
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):
|
async def on_message(self, message):
|
||||||
await self.database.push_message(message)
|
await self.database.push_message(message)
|
||||||
@ -131,9 +135,9 @@ class Titan(discord.Client):
|
|||||||
await self.database.update_guild_member(memberafter)
|
await self.database.update_guild_member(memberafter)
|
||||||
|
|
||||||
async def on_member_ban(self, member):
|
async def on_member_ban(self, member):
|
||||||
if role.server.me not in role.server.members:
|
if self.user.id == member.id:
|
||||||
return
|
return
|
||||||
await self.database.update_guild_member(member, active=False, banned=True)
|
await self.database.update_guild_member(member, active=False, banned=True)
|
||||||
|
|
||||||
async def on_member_unban(self, member):
|
async def on_member_unban(self, server, user):
|
||||||
await self.database.update_guild_member(member, active=False, banned=False)
|
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))
|
dbmember.roles = json.dumps(self.list_role_ids(member.roles))
|
||||||
session.commit()
|
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 def flag_unactive_guild_members(self, guild_id, guild_members):
|
||||||
async with threadpool():
|
async with threadpool():
|
||||||
with self.get_session() as session:
|
with self.get_session() as session:
|
||||||
|
@ -28,7 +28,7 @@ def checkUserRevoke(guild_id, user_key=None):
|
|||||||
if banned:
|
if banned:
|
||||||
return revoked
|
return revoked
|
||||||
dbUser = GuildMembers.query.filter(GuildMembers.guild_id == guild_id).filter(GuildMembers.user_id == session["user_id"]).first()
|
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
|
return revoked
|
||||||
|
|
||||||
def checkUserBanned(guild_id, ip_address=None):
|
def checkUserBanned(guild_id, ip_address=None):
|
||||||
|
Loading…
Reference in New Issue
Block a user