A-0.3 - Basismodul #36
@ -187,15 +187,15 @@ class Database(ModuleABC, OnReadyABC):
|
|||||||
|
|
||||||
def _check_user_joins(self):
|
def _check_user_joins(self):
|
||||||
self._logger.debug(__name__, f'Start checking UserJoinedServers table')
|
self._logger.debug(__name__, f'Start checking UserJoinedServers table')
|
||||||
for g in self._bot.guilds:
|
for guild in self._bot.guilds:
|
||||||
g: discord.Guild = g
|
guild: discord.Guild = guild
|
||||||
|
|
||||||
try:
|
server = self._servers.find_server_by_discord_id(guild.id)
|
||||||
server = self._servers.find_server_by_discord_id(g.id)
|
if server is None:
|
||||||
if server is None:
|
self._logger.fatal(__name__, f'Server not found in database: {guild.id}')
|
||||||
self._logger.fatal(__name__, f'Server not found in database: {g.id}')
|
|
||||||
|
try:
|
||||||
for u in g.members:
|
for u in guild.members:
|
||||||
u: discord.User = u
|
u: discord.User = u
|
||||||
if u.bot:
|
if u.bot:
|
||||||
self._logger.trace(__name__, f'User {u.id} is ignored, because its a bot')
|
self._logger.trace(__name__, f'User {u.id} is ignored, because its a bot')
|
||||||
@ -210,8 +210,8 @@ class Database(ModuleABC, OnReadyABC):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
m: discord.Member = u
|
m: discord.Member = u
|
||||||
self._logger.warn(__name__, f'Active UserJoinedServer not found in database: {g.id}:{u.id}@{m.joined_at}')
|
self._logger.warn(__name__, f'Active UserJoinedServer not found in database: {guild.id}:{u.id}@{m.joined_at}')
|
||||||
self._logger.debug(__name__, f'Add UserJoinedServer: {g.id}:{u.id}@{m.joined_at}')
|
self._logger.debug(__name__, f'Add UserJoinedServer: {guild.id}:{u.id}@{m.joined_at}')
|
||||||
self._user_joins.add_user_joined_server(UserJoinedServer(user, m.joined_at, None))
|
self._user_joins.add_user_joined_server(UserJoinedServer(user, m.joined_at, None))
|
||||||
self._db_context.save_changes()
|
self._db_context.save_changes()
|
||||||
|
|
||||||
@ -223,6 +223,24 @@ class Database(ModuleABC, OnReadyABC):
|
|||||||
if results is None or len(results) == 0:
|
if results is None or len(results) == 0:
|
||||||
self._logger.error(__name__, f'Table Users is empty!')
|
self._logger.error(__name__, f'Table Users is empty!')
|
||||||
|
|
||||||
|
|
||||||
|
joins = self._user_joins.get_user_joined_servers()
|
||||||
|
for join in joins:
|
||||||
|
join: UserJoinedServer = join
|
||||||
|
if join.user.server.discord_server_id != guild.id:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if join.leaved_on is not None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
dc_user = guild.get_member(join.user.discord_id)
|
||||||
|
if dc_user is None:
|
||||||
|
self._logger.warn(__name__, f'User {join.user.discord_id} already left the server.')
|
||||||
|
join.leaved_on = datetime.now()
|
||||||
|
self._user_joins.update_user_joined_server(join)
|
||||||
|
|
||||||
|
self._db_context.save_changes()
|
||||||
|
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
self._logger.debug(__name__, f'Module {type(self)} started')
|
self._logger.debug(__name__, f'Module {type(self)} started')
|
||||||
|
|
||||||
@ -234,3 +252,4 @@ class Database(ModuleABC, OnReadyABC):
|
|||||||
|
|
||||||
self._validate_init_time()
|
self._validate_init_time()
|
||||||
self._logger.trace(__name__, f'Module {type(self)} stopped')
|
self._logger.trace(__name__, f'Module {type(self)} stopped')
|
||||||
|
exit()
|
||||||
|
Reference in New Issue
Block a user