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,6 +57,7 @@ class Titan(discord.Client):
|
|||||||
await self.logout()
|
await self.logout()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if "no-init" not in sys.argv:
|
||||||
for server in self.servers:
|
for server in self.servers:
|
||||||
await self.database.update_guild(server)
|
await self.database.update_guild(server)
|
||||||
if server.large:
|
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_guild_members(server.id, server.members)
|
||||||
await self.database.flag_unactive_bans(server.id, server_bans)
|
await self.database.flag_unactive_bans(server.id, server_bans)
|
||||||
await self.database.remove_unused_guilds(self.servers)
|
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