Renamed type_id to id for sorting #130
This commit is contained in:
parent
85452c9a74
commit
fea259fa3b
@ -81,7 +81,7 @@ class UserDTO(DtoABC):
|
||||
"dcId": self._discord_id,
|
||||
"xp": self._xp,
|
||||
"minecraftId": self._minecraft_id,
|
||||
"server": self._server.server_id,
|
||||
"server": self._server.id,
|
||||
"isTechnician": self.is_technician,
|
||||
"isAdmin": self.is_admin,
|
||||
"isModerator": self.is_moderator,
|
||||
|
@ -2,7 +2,6 @@ from typing import Optional
|
||||
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
from flask import jsonify
|
||||
|
||||
from bot_api.abc.auth_service_abc import AuthServiceABC
|
||||
from bot_api.exception.service_error_code_enum import ServiceErrorCode
|
||||
@ -10,7 +9,6 @@ from bot_api.exception.service_exception import ServiceException
|
||||
from bot_api.filter.discord.server_select_criteria import ServerSelectCriteria
|
||||
from bot_api.model.discord.server_dto import ServerDTO
|
||||
from bot_api.model.discord.server_filtered_result_dto import ServerFilteredResultDTO
|
||||
from bot_api.model.error_dto import ErrorDTO
|
||||
from bot_api.transformer.server_transformer import ServerTransformer
|
||||
from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
@ -35,7 +33,7 @@ class DiscordService:
|
||||
self._users = users
|
||||
|
||||
def _to_dto(self, x: Server) -> Optional[ServerDTO]:
|
||||
guild = self._bot.get_guild(x.discord_server_id)
|
||||
guild = self._bot.get_guild(x.discord_id)
|
||||
if guild is None:
|
||||
return ServerTransformer.to_dto(x, "", 0, None)
|
||||
|
||||
@ -55,8 +53,8 @@ class DiscordService:
|
||||
if role != AuthRoleEnum.admin:
|
||||
auth_user = self._auth_users.find_auth_user_by_email(token["email"])
|
||||
if auth_user is not None:
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.server_id)
|
||||
servers = servers.where(lambda x: x.server_id in user_ids)
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.id)
|
||||
servers = servers.where(lambda x: x.id in user_ids)
|
||||
|
||||
servers = List(ServerDTO, servers)
|
||||
return servers.select(self._to_dto).where(lambda x: x.name != "")
|
||||
@ -72,8 +70,8 @@ class DiscordService:
|
||||
if role != AuthRoleEnum.admin:
|
||||
auth_user = self._auth_users.find_auth_user_by_email(token["email"])
|
||||
if auth_user is not None:
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.server_id)
|
||||
filtered_result.result = filtered_result.result.where(lambda x: x.server_id in user_ids)
|
||||
user_ids = auth_user.users.select(lambda x: x.server is not None and x.server.id)
|
||||
filtered_result.result = filtered_result.result.where(lambda x: x.id in user_ids)
|
||||
|
||||
servers: List = filtered_result.result.select(self._to_dto).where(lambda x: x.name != "")
|
||||
result = List(ServerDTO, servers)
|
||||
@ -87,7 +85,7 @@ class DiscordService:
|
||||
|
||||
async def get_server_by_id_async(self, id: int) -> ServerDTO:
|
||||
server = self._servers.get_server_by_id(id)
|
||||
guild = self._bot.get_guild(server.discord_server_id)
|
||||
guild = self._bot.get_guild(server.discord_id)
|
||||
|
||||
server_dto = ServerTransformer.to_dto(server, guild.name, guild.member_count, guild.icon)
|
||||
return server_dto
|
||||
|
@ -34,21 +34,21 @@ class AuthUserTransformer(TransformerABC):
|
||||
@staticmethod
|
||||
@ServiceProviderABC.inject
|
||||
def _is_technician(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_server_id)
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
return permissions.is_member_technician(member)
|
||||
|
||||
@staticmethod
|
||||
@ServiceProviderABC.inject
|
||||
def _is_admin(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_server_id)
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
return permissions.is_member_technician(member)
|
||||
|
||||
@staticmethod
|
||||
@ServiceProviderABC.inject
|
||||
def _is_moderator(user: User, bot: DiscordBotServiceABC, permissions: PermissionServiceABC):
|
||||
guild = bot.get_guild(user.server.discord_server_id)
|
||||
guild = bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
return permissions.is_member_technician(member)
|
||||
|
||||
@ -66,7 +66,7 @@ class AuthUserTransformer(TransformerABC):
|
||||
UserDTO,
|
||||
db.users.select(
|
||||
lambda u: UserDTO(
|
||||
u.user_id,
|
||||
u.id,
|
||||
u.discord_id,
|
||||
u.xp,
|
||||
u.minecraft_id,
|
||||
|
@ -15,8 +15,8 @@ class ServerTransformer(TransformerABC):
|
||||
@staticmethod
|
||||
def to_dto(db: Server, name: str, member_count: int, icon_url: Optional[discord.Asset]) -> ServerDTO:
|
||||
return ServerDTO(
|
||||
db.server_id,
|
||||
db.discord_server_id,
|
||||
db.id,
|
||||
db.discord_id,
|
||||
name,
|
||||
member_count,
|
||||
icon_url.url if icon_url is not None else None,
|
||||
|
@ -60,28 +60,28 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
def received_command(self, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
client.received_command_count += 1
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def moved_user(self, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
client.moved_users_count += 1
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def moved_users(self, guild_id: int, count: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
client.moved_users_count += count
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def get_client(self, dc_ic: int, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.id)
|
||||
return client
|
||||
|
||||
async def check_if_bot_is_ready_yet(self) -> bool:
|
||||
@ -138,7 +138,7 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
) -> bool:
|
||||
umcph = None
|
||||
try:
|
||||
umcph = self._umcphs.find_user_message_count_per_hour_by_user_id_and_date(user.user_id, created_at)
|
||||
umcph = self._umcphs.find_user_message_count_per_hour_by_user_id_and_date(user.id, created_at)
|
||||
if umcph is None:
|
||||
self._umcphs.add_user_message_count_per_hour(
|
||||
UserMessageCountPerHour(
|
||||
@ -151,7 +151,7 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
self._db.save_changes()
|
||||
|
||||
umcph = self._umcphs.get_user_message_count_per_hour_by_user_id_and_date(user.user_id, created_at)
|
||||
umcph = self._umcphs.get_user_message_count_per_hour_by_user_id_and_date(user.id, created_at)
|
||||
except Exception as e:
|
||||
self._logger.error(
|
||||
__name__,
|
||||
@ -183,7 +183,7 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
def get_ontime_for_user(self, user: User) -> float:
|
||||
return round(
|
||||
self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.user_id)
|
||||
self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.id)
|
||||
.where(lambda x: x.leaved_on is not None and x.joined_on is not None)
|
||||
.sum(lambda join: (join.leaved_on - join.joined_on).total_seconds() / 3600),
|
||||
2,
|
||||
|
@ -73,7 +73,7 @@ class ApiKey(TableABC):
|
||||
) VALUES (
|
||||
'{self._identifier}',
|
||||
'{self._key}',
|
||||
{"NULL" if self._creator is None else self._creator.user_id},
|
||||
{"NULL" if self._creator is None else self._creator.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
|
@ -71,7 +71,7 @@ class AuthUserUsersRelation(TableABC):
|
||||
`AuthUserId`, `UserId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._auth_user.id},
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
@ -84,10 +84,10 @@ class AuthUserUsersRelation(TableABC):
|
||||
f"""
|
||||
UPDATE `AuthUserUsersRelations`
|
||||
SET `AuthUserId` = '{self._auth_user.id}',,
|
||||
`UserId` = '{self._user.user_id}'
|
||||
`UserId` = '{self._user.id}'
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.user_id};
|
||||
AND `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
||||
|
||||
@ -97,6 +97,6 @@ class AuthUserUsersRelation(TableABC):
|
||||
f"""
|
||||
DELETE FROM `AuthUserUsersRelations`
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.user_id};
|
||||
AND `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
||||
|
@ -26,7 +26,7 @@ class AutoRole(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def auto_role_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._auto_role_id
|
||||
|
||||
@property
|
||||
@ -91,7 +91,7 @@ class AutoRole(TableABC):
|
||||
INSERT INTO `AutoRoles` (
|
||||
`ServerId`, `DiscordChannelId`, `DiscordMessageId`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
{self._discord_channel_id},
|
||||
{self._discord_message_id},
|
||||
'{self._created_at}',
|
||||
@ -105,7 +105,7 @@ class AutoRole(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AutoRoles`
|
||||
SET `ServerId` = {self._server.server_id},
|
||||
SET `ServerId` = {self._server.id},
|
||||
`DiscordChannelId` = {self._discord_channel_id},
|
||||
`DiscordMessageId` = {self._discord_message_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
|
@ -25,7 +25,7 @@ class AutoRoleRule(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def auto_role_rule_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._auto_role_rule_id
|
||||
|
||||
@property
|
||||
|
@ -1,4 +1,5 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
@ -32,7 +33,7 @@ class Client(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def client_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._client_id
|
||||
|
||||
@property
|
||||
@ -154,7 +155,7 @@ class Client(TableABC):
|
||||
{self._deleted_message_count},
|
||||
{self._received_message_count},
|
||||
{self._moved_users_count},
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
|
@ -19,7 +19,7 @@ class KnownUser(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def known_user_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._known_user_id
|
||||
|
||||
@property
|
||||
|
@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
@ -114,7 +115,7 @@ class Level(TableABC):
|
||||
'{self._color}',
|
||||
{self._min_xp},
|
||||
{self._permissions},
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
|
@ -1,5 +1,4 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
@ -20,11 +19,11 @@ class Server(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def server_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._server_id
|
||||
|
||||
@property
|
||||
def discord_server_id(self) -> int:
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_server_id
|
||||
|
||||
@staticmethod
|
||||
|
@ -101,7 +101,7 @@ class Statistic(TableABC):
|
||||
'{self._name}',
|
||||
'{self._description}',
|
||||
'{self._code}',
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
|
@ -28,7 +28,7 @@ class User(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def user_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._user_id
|
||||
|
||||
@property
|
||||
@ -111,7 +111,7 @@ class User(TableABC):
|
||||
{self._discord_id},
|
||||
{self._xp},
|
||||
'{"NULL" if self._minecraft_id is None else self._minecraft_id}',
|
||||
{self._server.server_id},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
);
|
||||
|
@ -100,7 +100,7 @@ class UserJoinedGameServer(TableABC):
|
||||
INSERT INTO `UserJoinedGameServer` (
|
||||
`UserId`, `GameServer`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._game_server}',
|
||||
'{self._joined_on}',
|
||||
'{self._leaved_on}',
|
||||
@ -115,7 +115,7 @@ class UserJoinedGameServer(TableABC):
|
||||
INSERT INTO `UserJoinedGameServer` (
|
||||
`UserId`, `GameServer`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._game_server}',
|
||||
'{self._joined_on}',
|
||||
'{self._created_at}',
|
||||
|
@ -25,7 +25,7 @@ class UserJoinedServer(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def join_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._join_id
|
||||
|
||||
@property
|
||||
@ -103,7 +103,7 @@ class UserJoinedServer(TableABC):
|
||||
INSERT INTO `UserJoinedServers` (
|
||||
`UserId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._joined_on}',
|
||||
'{self._leaved_on}',
|
||||
'{self._created_at}',
|
||||
@ -117,7 +117,7 @@ class UserJoinedServer(TableABC):
|
||||
INSERT INTO `UserJoinedServers` (
|
||||
`UserId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._joined_on}',
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
@ -132,7 +132,7 @@ class UserJoinedServer(TableABC):
|
||||
UPDATE `UserJoinedServers`
|
||||
SET `LeavedOn` = '{self._leaved_on}',
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `UserId` = {self._user.user_id};
|
||||
WHERE `UserId` = {self._user.id};
|
||||
"""
|
||||
)
|
||||
|
||||
|
@ -27,7 +27,7 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
self._modified_at = modified_at if modified_at is not None else self._modified_at
|
||||
|
||||
@property
|
||||
def join_id(self) -> int:
|
||||
def id(self) -> int:
|
||||
return self._join_id
|
||||
|
||||
@property
|
||||
@ -100,7 +100,7 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
INSERT INTO `UserJoinedVoiceChannel` (
|
||||
`UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
{self._dc_channel_id},
|
||||
'{self._joined_on}',
|
||||
'{self._leaved_on}',
|
||||
@ -115,7 +115,7 @@ class UserJoinedVoiceChannel(TableABC):
|
||||
INSERT INTO `UserJoinedVoiceChannel` (
|
||||
`UserId`, `DiscordChannelId`, `JoinedOn`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
{self._dc_channel_id},
|
||||
'{self._joined_on}',
|
||||
'{self._created_at}',
|
||||
|
@ -97,7 +97,7 @@ class UserMessageCountPerHour(TableABC):
|
||||
INSERT INTO `UserMessageCountPerHour` (
|
||||
`UserId`, `Date`, `Hour`, `XPCount`, `CreatedAt`, `LastModifiedAt`
|
||||
) VALUES (
|
||||
{self._user.user_id},
|
||||
{self._user.id},
|
||||
'{self._date}',
|
||||
{self._hour},
|
||||
{self._xp_count},
|
||||
|
@ -193,9 +193,9 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
self._logger.warn(__name__, f"Cannot find server by id {server_id}")
|
||||
raise Exception("Value not found")
|
||||
|
||||
client = self.find_client_by_discord_id_and_server_id(id, server.server_id)
|
||||
client = self.find_client_by_discord_id_and_server_id(id, server.id)
|
||||
if client is None:
|
||||
self._logger.warn(__name__, f"Cannot find client by ids {id}@{server.server_id}")
|
||||
self._logger.warn(__name__, f"Cannot find client by ids {id}@{server.id}")
|
||||
raise Exception("Value not found")
|
||||
|
||||
return client
|
||||
|
@ -75,9 +75,9 @@ class QueryABC(ObjectType):
|
||||
element: AutoRole = element
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
guild = bot.get_guild(u.server.discord_server_id)
|
||||
guild = bot.get_guild(u.server.discord_id)
|
||||
member = guild.get_member(u.discord_id)
|
||||
if permissions.is_member_moderator(member) and u.server.server_id == element.server.server_id:
|
||||
if permissions.is_member_moderator(member) and u.server.id == element.server.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
@ -85,23 +85,23 @@ class QueryABC(ObjectType):
|
||||
element: AutoRole = element.auto_role
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
guild = bot.get_guild(u.server.discord_server_id)
|
||||
guild = bot.get_guild(u.server.discord_id)
|
||||
member = guild.get_member(u.discord_id)
|
||||
if permissions.is_member_moderator(member) and u.server.server_id == element.server.server_id:
|
||||
if permissions.is_member_moderator(member) and u.server.id == element.server.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == Client:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.server.server_id == element.server.server_id:
|
||||
if u.server.id == element.server.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == KnownUser:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
guild = bot.get_guild(u.server.discord_server_id)
|
||||
guild = bot.get_guild(u.server.discord_id)
|
||||
member = guild.get_member(u.discord_id)
|
||||
if permissions.is_member_moderator(member):
|
||||
access = True
|
||||
@ -110,42 +110,42 @@ class QueryABC(ObjectType):
|
||||
elif type(element) == Level:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.server.server_id == element.server.server_id:
|
||||
if u.server.id == element.server.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == Server:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.server.server_id == element.server_id:
|
||||
if u.server.id == element.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == User:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.user_id == element.user_id:
|
||||
if u.id == element.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == UserJoinedServer:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.user_id == element.user.user_id:
|
||||
if u.id == element.user.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == UserJoinedVoiceChannel:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.user_id == element.user.user_id:
|
||||
if u.id == element.user.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
elif type(element) == UserJoinedGameServer:
|
||||
for u in user.users:
|
||||
u: User = u
|
||||
if u.user_id == element.user.user_id:
|
||||
if u.id == element.user.id:
|
||||
access = True
|
||||
break
|
||||
|
||||
@ -160,8 +160,8 @@ class QueryABC(ObjectType):
|
||||
if auth_user == "system" or auth_user.auth_role == AuthRoleEnum.admin:
|
||||
return
|
||||
|
||||
member = bot.get_guild(server.discord_server_id).get_member(
|
||||
auth_user.users.where(lambda x: x.server.server_id == server.server_id).single().discord_id
|
||||
member = bot.get_guild(server.discord_id).get_member(
|
||||
auth_user.users.where(lambda x: x.server.id == server.id).single().discord_id
|
||||
)
|
||||
|
||||
check_perm = lambda x: True
|
||||
|
@ -42,7 +42,7 @@ class AutoRoleFilter(FilterABC):
|
||||
|
||||
def filter(self, query: List[AutoRole]) -> List[AutoRole]:
|
||||
if self._id is not None:
|
||||
query = query.where(lambda x: x.auto_role_id == self._id)
|
||||
query = query.where(lambda x: x.id == self._id)
|
||||
|
||||
if self._channel_id is not None:
|
||||
query = query.where(lambda x: x.discord_channel_id == self._channel_id)
|
||||
@ -57,7 +57,7 @@ class AutoRoleFilter(FilterABC):
|
||||
query = query.where(lambda x: x.discord_message_id == self._message_id)
|
||||
|
||||
if self._server is not None:
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id)
|
||||
query = query.where(lambda x: x.server.server_id in servers)
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.server.id in servers)
|
||||
|
||||
return query
|
||||
|
@ -39,7 +39,7 @@ class AutoRoleRuleFilter(FilterABC):
|
||||
|
||||
def filter(self, query: List[AutoRoleRule]) -> List[AutoRoleRule]:
|
||||
if self._id is not None:
|
||||
query = query.where(lambda x: x.auto_role_rule_id == self._id)
|
||||
query = query.where(lambda x: x.id == self._id)
|
||||
|
||||
if self._emoji_name is not None:
|
||||
query = query.where(lambda x: x.emoji_name == self._emoji_name)
|
||||
@ -50,14 +50,14 @@ class AutoRoleRuleFilter(FilterABC):
|
||||
if self._role_name is not None and self._role_id is not None:
|
||||
|
||||
def get_role_name(x: AutoRoleRule):
|
||||
guild = self._bot.get_guild(x.auto_role.server.discord_server_id)
|
||||
guild = self._bot.get_guild(x.auto_role.server.discord_id)
|
||||
name = guild.get_role(x.role_id).name
|
||||
return name == self._role_name or self._role_name in name
|
||||
|
||||
query = query.where(get_role_name)
|
||||
|
||||
if self._auto_role is not None:
|
||||
auto_roles = self._auto_role.filter(query.select(lambda x: x.auto_role)).select(lambda x: x.auto_role_id)
|
||||
query = query.where(lambda x: x.auto_role.auto_role_id in auto_roles)
|
||||
auto_roles = self._auto_role.filter(query.select(lambda x: x.auto_role)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.auto_role.id in auto_roles)
|
||||
|
||||
return query
|
||||
|
@ -32,16 +32,16 @@ class ClientFilter(FilterABC):
|
||||
|
||||
def filter(self, query: List[Client]) -> List[Client]:
|
||||
if self._id is not None:
|
||||
query = query.where(lambda x: x.client_id == self._id)
|
||||
query = query.where(lambda x: x.id == self._id)
|
||||
|
||||
if self._discord_id is not None:
|
||||
query = query.where(lambda x: x.client_id == self._discord_id)
|
||||
query = query.where(lambda x: x.id == self._discord_id)
|
||||
|
||||
if self._name is not None:
|
||||
query = query.where(lambda x: self._name.lower() == x.name.lower() or self._name.lower() in x.name.lower())
|
||||
|
||||
if self._server is not None:
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id)
|
||||
query = query.where(lambda x: x.server.server_id in servers)
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.server.id in servers)
|
||||
|
||||
return query
|
||||
|
@ -36,7 +36,7 @@ class LevelFilter(FilterABC):
|
||||
query = query.where(lambda x: self._name.lower() == x.name.lower() or self._name.lower() in x.name.lower())
|
||||
|
||||
if self._server is not None:
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id)
|
||||
query = query.where(lambda x: x.server.server_id in servers)
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.server.id in servers)
|
||||
|
||||
return query
|
||||
|
@ -28,10 +28,10 @@ class ServerFilter(FilterABC):
|
||||
@ServiceProviderABC.inject
|
||||
def filter(self, query: List[Server], bot: DiscordBotServiceABC) -> List[Server]:
|
||||
if self._id is not None:
|
||||
query = query.where(lambda x: x.server_id == self._id)
|
||||
query = query.where(lambda x: x.id == self._id)
|
||||
|
||||
if self._discord_id is not None:
|
||||
query = query.where(lambda x: x.discord_server_id == self._discord_id)
|
||||
query = query.where(lambda x: x.discord_id == self._discord_id)
|
||||
|
||||
if self._name is not None:
|
||||
|
||||
|
@ -16,5 +16,18 @@ class Sort(FilterABC):
|
||||
if "sortColumn" in values:
|
||||
self._sort_column = values["sortColumn"]
|
||||
|
||||
def _by_column(self, x):
|
||||
atr = getattr(x, self._sort_column, None)
|
||||
return atr
|
||||
|
||||
def filter(self, query: List, *args) -> List:
|
||||
if self._sort_column is None:
|
||||
return query
|
||||
|
||||
match self._sort_direction.lower() if self._sort_direction is not None else "ASC":
|
||||
case "asc":
|
||||
query = query.order_by(self._by_column)
|
||||
case "desc":
|
||||
query = query.order_by_descending(self._by_column)
|
||||
|
||||
return query
|
||||
|
@ -73,7 +73,7 @@ class UserFilter(FilterABC):
|
||||
|
||||
def filter(self, query: List[User]) -> List[User]:
|
||||
if self._id is not None:
|
||||
query = query.where(lambda x: x.user_id == self._id or str(self._id) in str(x.user_id))
|
||||
query = query.where(lambda x: x.id == self._id or str(self._id) in str(x.id))
|
||||
|
||||
if self._discord_id is not None:
|
||||
query = query.where(
|
||||
@ -83,7 +83,7 @@ class UserFilter(FilterABC):
|
||||
if self._name is not None:
|
||||
|
||||
def _get_member(user: User):
|
||||
guild = self._bot.get_guild(user.server.discord_server_id)
|
||||
guild = self._bot.get_guild(user.server.discord_id)
|
||||
member = guild.get_member(user.discord_id)
|
||||
return member is not None and (member.name == self._name or self._name in member.name)
|
||||
|
||||
@ -103,13 +103,13 @@ class UserFilter(FilterABC):
|
||||
query = query.where(lambda x: self._levels.get_level(x).id in levels)
|
||||
|
||||
if self._server is not None:
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.server_id)
|
||||
query = query.where(lambda x: x.server.server_id in servers)
|
||||
servers = self._server.filter(query.select(lambda x: x.server)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.server.id in servers)
|
||||
|
||||
if self._left_server is not None:
|
||||
|
||||
def _has_user_left_server(user: User):
|
||||
active_join = self._user_joined_servers.find_active_user_joined_server_by_user_id(user.user_id)
|
||||
active_join = self._user_joined_servers.find_active_user_joined_server_by_user_id(user.id)
|
||||
return (active_join is None) == self._left_server
|
||||
|
||||
query = query.where(_has_user_left_server)
|
||||
|
@ -42,7 +42,7 @@ class UserJoinedGameServerFilter(FilterABC):
|
||||
query = query.where(lambda x: x.game_server == self._game_server)
|
||||
|
||||
if self._user is not None:
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.user_id)
|
||||
query = query.where(lambda x: x.user.user_id in users)
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.user.id in users)
|
||||
|
||||
return query
|
||||
|
@ -43,8 +43,8 @@ class UserJoinedServerFilter(FilterABC):
|
||||
query = query.where(lambda x: x.id == self._id)
|
||||
|
||||
if self._user is not None:
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.user_id)
|
||||
query = query.where(lambda x: x.user.user_id in users)
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.user.id in users)
|
||||
|
||||
if self._joined_on is not None:
|
||||
query = query.where(lambda x: x.joined_on == self._joined_on or self._joined_on in x.joined_on)
|
||||
|
@ -62,8 +62,8 @@ class UserJoinedVoiceChannelFilter(FilterABC):
|
||||
query = query.where(get_channel_name)
|
||||
|
||||
if self._user is not None:
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.user_id)
|
||||
query = query.where(lambda x: x.user.user_id in users)
|
||||
users = self._user.filter(query.select(lambda x: x.user)).select(lambda x: x.id)
|
||||
query = query.where(lambda x: x.user.id in users)
|
||||
|
||||
if self._joined_on is not None:
|
||||
query = query.where(lambda x: x.joined_on == self._joined_on or self._joined_on in x.joined_on)
|
||||
|
@ -9,6 +9,11 @@ input Page {
|
||||
}
|
||||
|
||||
input Sort {
|
||||
sortDirection: String
|
||||
sortDirection: SortDirection
|
||||
sortColumn: String
|
||||
}
|
||||
|
||||
enum SortDirection {
|
||||
ASC
|
||||
DESC
|
||||
}
|
@ -33,12 +33,12 @@ class AutoRoleMutation(QueryABC):
|
||||
|
||||
def get_new(x: AutoRole):
|
||||
return (
|
||||
x.server.server_id == input["serverId"]
|
||||
x.server.id == input["serverId"]
|
||||
and x.discord_channel_id == input["channelId"]
|
||||
and x.discord_message_id == input["messageId"]
|
||||
)
|
||||
|
||||
return self._auto_roles.get_auto_roles_by_server_id(auto_role.server.server_id).where(get_new).last()
|
||||
return self._auto_roles.get_auto_roles_by_server_id(auto_role.server.id).where(get_new).last()
|
||||
|
||||
def resolve_update_auto_role(self, *_, input: dict):
|
||||
auto_role = self._auto_roles.get_auto_role_by_id(input["id"])
|
||||
|
@ -35,16 +35,12 @@ class AutoRoleRuleMutation(QueryABC):
|
||||
|
||||
def get_new(x: AutoRoleRule):
|
||||
return (
|
||||
x.auto_role.auto_role_id == input["autoRoleId"]
|
||||
x.auto_role.id == input["autoRoleId"]
|
||||
and x.emoji_name == input["emojiName"]
|
||||
and x.role_id == input["roleId"]
|
||||
)
|
||||
|
||||
return (
|
||||
self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_rule.auto_role.auto_role_id)
|
||||
.where(get_new)
|
||||
.last()
|
||||
)
|
||||
return self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_rule.auto_role.id).where(get_new).last()
|
||||
|
||||
def resolve_update_auto_role_rule(self, *_, input: dict):
|
||||
auto_role_rule = self._auto_roles.get_auto_role_rule_by_id(input["id"])
|
||||
|
@ -46,7 +46,7 @@ class LevelMutation(QueryABC):
|
||||
and l.permissions == level.permissions
|
||||
)
|
||||
|
||||
return self._levels.get_levels_by_server_id(level.server.server_id).where(get_new_level).last()
|
||||
return self._levels.get_levels_by_server_id(level.server.id).where(get_new_level).last()
|
||||
|
||||
def resolve_update_level(self, *_, input: dict):
|
||||
level = self._levels.get_level_by_id(input["id"])
|
||||
|
@ -45,11 +45,11 @@ class UserJoinedGameServerMutation(QueryABC):
|
||||
user = self._users.get_user_by_id(input["userId"])
|
||||
self._can_user_mutate_data(user.server, UserRoleEnum.admin)
|
||||
|
||||
active = self._user_joined_game_servers.find_active_user_joined_game_server_by_user_id(user.user_id)
|
||||
active = self._user_joined_game_servers.find_active_user_joined_game_server_by_user_id(user.id)
|
||||
if active is not None:
|
||||
self._logger.debug(
|
||||
__name__,
|
||||
f"Skip UserJoinedGameServer for user {user.user_id}. User already plays on {active.game_server}.",
|
||||
f"Skip UserJoinedGameServer for user {user.id}. User already plays on {active.game_server}.",
|
||||
)
|
||||
return
|
||||
|
||||
@ -57,18 +57,18 @@ class UserJoinedGameServerMutation(QueryABC):
|
||||
self._user_joined_game_servers.add_user_joined_game_server(new)
|
||||
self._db.save_changes()
|
||||
|
||||
return self._user_joined_game_servers.get_active_user_joined_game_server_by_user_id(user.user_id)
|
||||
return self._user_joined_game_servers.get_active_user_joined_game_server_by_user_id(user.id)
|
||||
|
||||
def resolve_user_leaved(self, *_, input: dict):
|
||||
user = self._users.get_user_by_id(input["userId"])
|
||||
self._can_user_mutate_data(user.server, UserRoleEnum.admin)
|
||||
|
||||
active = self._user_joined_game_servers.find_active_user_joined_game_server_by_user_id(user.user_id)
|
||||
active = self._user_joined_game_servers.find_active_user_joined_game_server_by_user_id(user.id)
|
||||
if active is None:
|
||||
return None
|
||||
active.leaved_on = datetime.now()
|
||||
|
||||
settings: BaseServerSettings = self._base_helper.get_config(user.server.discord_server_id)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(user.server.discord_id)
|
||||
|
||||
ontime = round((active.leaved_on - active.joined_on).total_seconds() / 3600, 2)
|
||||
old_xp = user.xp
|
||||
|
@ -28,13 +28,13 @@ class AutoRoleQuery(DataQueryABC):
|
||||
self.set_field("server", self.resolve_server)
|
||||
self.add_collection(
|
||||
"autoRoleRule",
|
||||
lambda x, *_: self._auto_role_rules.get_auto_role_rules_by_auto_role_id(x.auto_role_id),
|
||||
lambda x, *_: self._auto_role_rules.get_auto_role_rules_by_auto_role_id(x.id),
|
||||
AutoRoleFilter,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: AutoRole, *_):
|
||||
return x.auto_role_id
|
||||
return x.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_channel_id(x: AutoRole, *_):
|
||||
@ -50,6 +50,6 @@ class AutoRoleQuery(DataQueryABC):
|
||||
|
||||
def resolve_server(self, x: AutoRole, *_, filter: ServerFilter = None):
|
||||
if filter is not None:
|
||||
return filter.filter(self._servers.get_server_by_id(x.server.server_id))
|
||||
return filter.filter(self._servers.get_server_by_id(x.server.id))
|
||||
|
||||
return self._servers.get_server_by_id(x.server.server_id)
|
||||
return self._servers.get_server_by_id(x.server.id)
|
||||
|
@ -24,7 +24,7 @@ class AutoRoleRuleQuery(DataQueryABC):
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: AutoRoleRule, *_):
|
||||
return x.auto_role_rule_id
|
||||
return x.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_emoji_name(x: AutoRoleRule, *_):
|
||||
@ -35,8 +35,8 @@ class AutoRoleRuleQuery(DataQueryABC):
|
||||
return x.role_id
|
||||
|
||||
def resolve_role_name(self, x: AutoRoleRule, *_):
|
||||
guild = self._bot.get_guild(x.auto_role.server.discord_server_id)
|
||||
guild = self._bot.get_guild(x.auto_role.server.discord_id)
|
||||
return guild.get_role(x.role_id).name
|
||||
|
||||
def resolve_auto_role(self, x: AutoRoleRule, *_):
|
||||
return self._auto_roles.get_auto_role_by_id(x.auto_role.auto_role_id)
|
||||
return self._auto_roles.get_auto_role_by_id(x.auto_role.id)
|
||||
|
@ -25,7 +25,7 @@ class ClientQuery(DataQueryABC):
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(client: Client, *_):
|
||||
return client.client_id
|
||||
return client.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_discord_id(client: Client, *_):
|
||||
|
@ -11,7 +11,7 @@ class KnownUserQuery(DataQueryABC):
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: KnownUser, *_):
|
||||
return x.known_user_id
|
||||
return x.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_discord_id(x: KnownUser, *_):
|
||||
|
@ -42,29 +42,27 @@ class ServerQuery(DataQueryABC):
|
||||
|
||||
self.add_collection(
|
||||
"autoRole",
|
||||
lambda server, *_: self._auto_roles.get_auto_roles_by_server_id(server.server_id),
|
||||
lambda server, *_: self._auto_roles.get_auto_roles_by_server_id(server.id),
|
||||
AutoRoleFilter,
|
||||
)
|
||||
self.add_collection(
|
||||
"client", lambda server, *_: self._clients.get_clients_by_server_id(server.server_id), ClientFilter
|
||||
"client", lambda server, *_: self._clients.get_clients_by_server_id(server.id), ClientFilter
|
||||
)
|
||||
self.add_collection(
|
||||
"level", lambda server, *_: self._levels.get_levels_by_server_id(server.server_id), LevelFilter
|
||||
)
|
||||
self.add_collection("user", lambda server, *_: self._users.get_users_by_server_id(server.server_id), UserFilter)
|
||||
self.add_collection("level", lambda server, *_: self._levels.get_levels_by_server_id(server.id), LevelFilter)
|
||||
self.add_collection("user", lambda server, *_: self._users.get_users_by_server_id(server.id), UserFilter)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(server: Server, *_):
|
||||
return server.server_id
|
||||
return server.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_discord_id(server: Server, *_):
|
||||
return server.discord_server_id
|
||||
return server.discord_id
|
||||
|
||||
def resolve_name(self, server: Server, *_):
|
||||
guild = self._bot.get_guild(server.discord_server_id)
|
||||
guild = self._bot.get_guild(server.discord_id)
|
||||
return None if guild is None else guild.name
|
||||
|
||||
def resolve_icon_url(self, server: Server, *_):
|
||||
guild = self._bot.get_guild(server.discord_server_id)
|
||||
guild = self._bot.get_guild(server.discord_id)
|
||||
return None if guild is None else guild.icon.url
|
||||
|
@ -13,7 +13,7 @@ class UserJoinedServerQuery(DataQueryABC):
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: UserJoinedServer, *_):
|
||||
return x.join_id
|
||||
return x.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_user(x: UserJoinedServer, *_):
|
||||
|
@ -19,7 +19,7 @@ class UserJoinedVoiceChannelQuery(DataQueryABC):
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(x: UserJoinedVoiceChannel, *_):
|
||||
return x.join_id
|
||||
return x.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_channel_id(x: UserJoinedVoiceChannel, *_):
|
||||
|
@ -43,17 +43,17 @@ class UserQuery(DataQueryABC):
|
||||
self.set_field("level", self.resolve_level)
|
||||
self.add_collection(
|
||||
"joinedServer",
|
||||
lambda user, *_: self._ujs.get_user_joined_servers_by_user_id(user.user_id),
|
||||
lambda user, *_: self._ujs.get_user_joined_servers_by_user_id(user.id),
|
||||
UserJoinedServerFilter,
|
||||
)
|
||||
self.add_collection(
|
||||
"joinedVoiceChannel",
|
||||
lambda user, *_: self._ujvs.get_user_joined_voice_channels_by_user_id(user.user_id),
|
||||
lambda user, *_: self._ujvs.get_user_joined_voice_channels_by_user_id(user.id),
|
||||
UserJoinedVoiceChannelFilter,
|
||||
)
|
||||
self.add_collection(
|
||||
"userJoinedGameServer",
|
||||
lambda user, *_: self._user_joined_game_server.get_user_joined_game_servers_by_user_id(user.user_id),
|
||||
lambda user, *_: self._user_joined_game_server.get_user_joined_game_servers_by_user_id(user.id),
|
||||
UserJoinedGameServerFilter,
|
||||
)
|
||||
self.set_field("server", self.resolve_server)
|
||||
@ -61,14 +61,14 @@ class UserQuery(DataQueryABC):
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(user: User, *_):
|
||||
return user.user_id
|
||||
return user.id
|
||||
|
||||
@staticmethod
|
||||
def resolve_discord_id(user: User, *_):
|
||||
return user.discord_id
|
||||
|
||||
def resolve_name(self, user: User, *_):
|
||||
guild = self._bot.get_guild(user.server.discord_server_id)
|
||||
guild = self._bot.get_guild(user.server.discord_id)
|
||||
user = guild.get_member(user.discord_id)
|
||||
return None if user is None else user.name
|
||||
|
||||
@ -91,4 +91,4 @@ class UserQuery(DataQueryABC):
|
||||
return user.server
|
||||
|
||||
def resolve_left_server(self, user: User, *_):
|
||||
return self._ujs.find_active_user_joined_server_by_user_id(user.user_id) is None
|
||||
return self._ujs.find_active_user_joined_server_by_user_id(user.id) is None
|
||||
|
@ -52,7 +52,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
||||
self, interaction: discord.Interaction, current: str
|
||||
) -> TList[app_commands.Choice[str]]:
|
||||
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id)
|
||||
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.id).select(lambda x: x.id)
|
||||
return [
|
||||
app_commands.Choice(name=auto_role, value=auto_role)
|
||||
for auto_role in self._client_utils.get_auto_complete_list(auto_roles, current)
|
||||
@ -79,7 +79,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
||||
color=int("ef9d0d", 16),
|
||||
)
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id)
|
||||
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.id)
|
||||
if auto_roles.count() < 1:
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.auto_role.error.nothing_found"))
|
||||
self._logger.trace(__name__, f"Finished command auto-role list")
|
||||
@ -88,7 +88,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
||||
auto_role_id = ""
|
||||
message_id = ""
|
||||
for auto_role in auto_roles:
|
||||
auto_role_id += f"\n{auto_role.auto_role_id}"
|
||||
auto_role_id += f"\n{auto_role.id}"
|
||||
message_id += f"\n{auto_role.discord_message_id}"
|
||||
|
||||
embed.add_field(
|
||||
@ -181,7 +181,7 @@ class AutoRoleGroup(DiscordCommandABC):
|
||||
self._logger.trace(__name__, f"Finished command auto-role remove")
|
||||
return
|
||||
|
||||
for rule in self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_from_db.auto_role_id):
|
||||
for rule in self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role_from_db.id):
|
||||
self._auto_roles.delete_auto_role_rule(rule)
|
||||
self._logger.info(__name__, f"Removed auto-role rule {rule.role_id}")
|
||||
|
||||
@ -392,12 +392,12 @@ class AutoRoleGroup(DiscordCommandABC):
|
||||
self, interaction: discord.Interaction, current: str
|
||||
) -> TList[app_commands.Choice[str]]:
|
||||
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.server_id).select(lambda x: x.auto_role_id)
|
||||
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.id).select(lambda x: x.id)
|
||||
rules = auto_roles.select_many(lambda ar: self._auto_roles.get_auto_role_rules_by_auto_role_id(ar))
|
||||
return [
|
||||
app_commands.Choice(
|
||||
name=f"{rule.auto_role_rule_id} {rule.emoji_name} {interaction.guild.get_role(int(rule.role_id))}",
|
||||
value=rule.auto_role_rule_id,
|
||||
name=f"{rule.id} {rule.emoji_name} {interaction.guild.get_role(int(rule.role_id))}",
|
||||
value=rule.id,
|
||||
)
|
||||
for rule in self._client_utils.get_auto_complete_list(rules, current, lambda r: r.auto_role_rule_id)
|
||||
for rule in self._client_utils.get_auto_complete_list(rules, current, lambda r: r.id)
|
||||
]
|
||||
|
@ -1,4 +1,3 @@
|
||||
import discord
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
@ -50,7 +49,7 @@ class AutoRoleReactionHandler:
|
||||
self._logger.debug(__name__, f"auto-role for message not found - skipping")
|
||||
return
|
||||
|
||||
rules: List[AutoRoleRule] = self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role.auto_role_id)
|
||||
rules: List[AutoRoleRule] = self._auto_roles.get_auto_role_rules_by_auto_role_id(auto_role.id)
|
||||
if rules.count() == 0:
|
||||
self._logger.debug(__name__, f"auto-role rules not found - skipping")
|
||||
return
|
||||
|
@ -59,7 +59,7 @@ class PingCommand(DiscordCommandABC):
|
||||
color=int("ef9d0d", 16),
|
||||
)
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(server.discord_server_id)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(server.discord_id)
|
||||
for server in settings.ping_urls:
|
||||
embed.add_field(name=server, value=f"{self._get_ping(server)} ms", inline=False)
|
||||
await self._message_service.send_ctx_msg(ctx, embed)
|
||||
|
@ -73,7 +73,7 @@ class RegisterGroup(DiscordCommandABC):
|
||||
return
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
user.minecraft_id = minecraft_id
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
|
@ -52,7 +52,7 @@ class UnregisterGroup(DiscordCommandABC):
|
||||
self._logger.debug(__name__, f"Received command register minecraft {ctx}")
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
user.minecraft_id = None
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
|
@ -81,7 +81,7 @@ class UserGroup(DiscordCommandABC):
|
||||
member = ctx.author
|
||||
|
||||
server = self._servers.find_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
|
||||
if atr == "xp":
|
||||
if is_remove:
|
||||
@ -125,8 +125,8 @@ class UserGroup(DiscordCommandABC):
|
||||
member = ctx.author
|
||||
|
||||
server = self._servers.find_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
joins = self._user_joined_servers.get_user_joined_servers_by_user_id(user.user_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
joins = self._user_joined_servers.get_user_joined_servers_by_user_id(user.id)
|
||||
|
||||
embed = discord.Embed(title=member.name, description=member.name, color=int("ef9d0d", 16))
|
||||
|
||||
@ -206,7 +206,7 @@ class UserGroup(DiscordCommandABC):
|
||||
member = ctx.author
|
||||
|
||||
server = self._servers.find_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
|
||||
if atr == "xp":
|
||||
value = str(user.xp)
|
||||
@ -241,7 +241,7 @@ class UserGroup(DiscordCommandABC):
|
||||
member = ctx.author
|
||||
|
||||
server = self._servers.find_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
|
||||
if atr == "xp":
|
||||
try:
|
||||
@ -312,7 +312,7 @@ class UserGroup(DiscordCommandABC):
|
||||
member = ctx.author
|
||||
|
||||
server = self._servers.find_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
|
||||
if atr == "xp":
|
||||
user.xp = 0
|
||||
@ -321,7 +321,7 @@ class UserGroup(DiscordCommandABC):
|
||||
await self._level.check_level(member)
|
||||
|
||||
elif atr == "ontime":
|
||||
self._user_joined_voice_channel.delete_user_joined_voice_channel_by_user_id(user.user_id)
|
||||
self._user_joined_voice_channel.delete_user_joined_voice_channel_by_user_id(user.id)
|
||||
self._db.save_changes()
|
||||
|
||||
else:
|
||||
|
@ -64,7 +64,7 @@ class BaseOnCommandEvent(OnCommandABC):
|
||||
|
||||
user: Optional[User] = None
|
||||
try:
|
||||
user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, server.server_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, server.id)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f"Cannot get user {dc_user_id}", e)
|
||||
return
|
||||
|
@ -85,7 +85,7 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC):
|
||||
|
||||
try:
|
||||
server = self._servers.get_server_by_discord_id(member.guild.id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
if user is not None:
|
||||
self._user_joins.add_user_joined_server(UserJoinedServer(user, datetime.now()))
|
||||
self._db.save_changes()
|
||||
@ -94,7 +94,7 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC):
|
||||
self._logger.debug(__name__, f"Add user: {member.id}")
|
||||
self._users.add_user(User(member.id, 0, server))
|
||||
self._db.save_changes()
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
self._user_joins.add_user_joined_server(UserJoinedServer(user, datetime.now()))
|
||||
self._db.save_changes()
|
||||
except Exception as e:
|
||||
|
@ -47,12 +47,12 @@ class BaseOnMemberRemoveEvent(OnMemberRemoveABC):
|
||||
try:
|
||||
server = self._servers.get_server_by_discord_id(member.guild.id)
|
||||
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
if user is None:
|
||||
self._logger.error(__name__, f"Cannot find user {member}")
|
||||
return
|
||||
|
||||
join = self._user_joins.get_active_user_joined_server_by_user_id(user.user_id)
|
||||
join = self._user_joins.get_active_user_joined_server_by_user_id(user.id)
|
||||
join.leaved_on = datetime.now()
|
||||
self._user_joins.update_user_joined_server(join)
|
||||
self._db.save_changes()
|
||||
|
@ -52,7 +52,7 @@ class BaseOnMessageDeleteEvent(OnMessageDeleteABC):
|
||||
|
||||
user: Optional[User] = None
|
||||
try:
|
||||
user = self._users.find_user_by_discord_id_and_server_id(dc_user_id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(dc_user_id, server.id)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f"Cannot get user {dc_user_id}", e)
|
||||
return
|
||||
|
@ -57,7 +57,7 @@ class BaseOnMessageEvent(OnMessageABC):
|
||||
|
||||
user: Optional[User] = None
|
||||
try:
|
||||
user = self._users.find_user_by_discord_id_and_server_id(dc_user_id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(dc_user_id, server.id)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f"Cannot get user {dc_user_id}", e)
|
||||
return
|
||||
|
@ -51,7 +51,7 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
|
||||
def _update_voice_state(self, joined: bool, dc_user_id: int, dc_channel_id: int, server: Server):
|
||||
user: Optional[User] = None
|
||||
try:
|
||||
user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, server.server_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, server.id)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f"Cannot get user {dc_user_id}", e)
|
||||
return
|
||||
@ -67,9 +67,9 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
|
||||
self._db.save_changes()
|
||||
return
|
||||
|
||||
settings: BaseServerSettings = self._base_helper.get_config(server.discord_server_id)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(server.discord_id)
|
||||
|
||||
join = self._user_joins_vc.get_active_user_joined_voice_channel_by_user_id(user.user_id)
|
||||
join = self._user_joins_vc.get_active_user_joined_voice_channel_by_user_id(user.id)
|
||||
join.leaved_on = datetime.now()
|
||||
|
||||
# ontime as hours
|
||||
|
@ -43,7 +43,7 @@ class BaseOnVoiceStateUpdateEventHelpChannel(OnVoiceStateUpdateABC):
|
||||
):
|
||||
self._logger.debug(__name__, f"Module {type(self)} started")
|
||||
server = self._servers.get_server_by_discord_id(member.guild.id)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(server.discord_server_id)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(server.discord_id)
|
||||
if after.channel is None or after.channel.id != settings.help_voice_channel_id:
|
||||
return
|
||||
|
||||
|
@ -62,7 +62,7 @@ class BaseReactionHandler:
|
||||
return
|
||||
|
||||
server = self._servers.get_server_by_discord_id(guild.id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
settings: BaseServerSettings = self._base_helper.get_config(guild.id)
|
||||
|
||||
if r_type == "add":
|
||||
|
@ -144,7 +144,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
if server is None:
|
||||
self._logger.fatal(__name__, f"Server not found in database: {g.id}")
|
||||
|
||||
client = self._clients.find_client_by_server_id(server.server_id)
|
||||
client = self._clients.find_client_by_server_id(server.id)
|
||||
if client is not None:
|
||||
continue
|
||||
|
||||
@ -156,7 +156,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
self._clients.add_client(Client(self._bot.user.id, 0, 0, 0, 0, 0, server))
|
||||
self._db_context.save_changes()
|
||||
|
||||
client = self._clients.find_client_by_server_id(server.server_id)
|
||||
client = self._clients.find_client_by_server_id(server.id)
|
||||
if client is None:
|
||||
self._logger.fatal(
|
||||
__name__,
|
||||
@ -187,7 +187,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
self._logger.trace(__name__, f"User {u.id} is ignored, because its a bot")
|
||||
continue
|
||||
|
||||
user = self._users.find_user_by_discord_id_and_server_id(u.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(u.id, server.id)
|
||||
if user is not None:
|
||||
continue
|
||||
|
||||
@ -220,11 +220,11 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
self._logger.trace(__name__, f"User {u.id} is ignored, because its a bot")
|
||||
continue
|
||||
|
||||
user = self._users.find_user_by_discord_id_and_server_id(u.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(u.id, server.id)
|
||||
if user is None:
|
||||
self._logger.fatal(__name__, f"User not found in database: {u.id}")
|
||||
|
||||
join = self._user_joins.find_active_user_joined_server_by_user_id(user.user_id)
|
||||
join = self._user_joins.find_active_user_joined_server_by_user_id(user.id)
|
||||
if join is not None:
|
||||
continue
|
||||
|
||||
@ -253,7 +253,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
joins = self._user_joins.get_user_joined_servers()
|
||||
for join in joins:
|
||||
join: UserJoinedServer = join
|
||||
if join.user.server.discord_server_id != guild.id:
|
||||
if join.user.server.discord_id != guild.id:
|
||||
continue
|
||||
|
||||
if join.leaved_on is not None:
|
||||
@ -285,11 +285,11 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
self._logger.trace(__name__, f"User {member.id} is ignored, because its a bot")
|
||||
continue
|
||||
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
if user is None:
|
||||
self._logger.fatal(__name__, f"User not found in database: {member.id}")
|
||||
|
||||
joins = self._user_joins_vc.find_active_user_joined_voice_channels_by_user_id(user.user_id)
|
||||
joins = self._user_joins_vc.find_active_user_joined_voice_channels_by_user_id(user.id)
|
||||
if joins is None or len(joins) == 0:
|
||||
continue
|
||||
|
||||
@ -318,7 +318,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
if member.voice is None:
|
||||
continue
|
||||
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
if user is None:
|
||||
self._logger.fatal(__name__, f"User not found in database: {member.id}")
|
||||
|
||||
@ -345,11 +345,11 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
self._logger.trace(__name__, f"User {member.id} is ignored, because its a bot")
|
||||
continue
|
||||
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
if user is None:
|
||||
self._logger.fatal(__name__, f"User not found in database: {member.id}")
|
||||
|
||||
joins = self._user_joined_gs.find_active_user_joined_game_servers_by_user_id(user.user_id)
|
||||
joins = self._user_joined_gs.find_active_user_joined_game_servers_by_user_id(user.id)
|
||||
if joins is None or len(joins) == 0:
|
||||
continue
|
||||
|
||||
|
@ -108,7 +108,7 @@ class LevelGroup(DiscordCommandABC):
|
||||
self, interaction: discord.Interaction, current: str
|
||||
) -> TList[app_commands.Choice[str]]:
|
||||
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||
levels = self._levels.get_levels_by_server_id(server.server_id).select(lambda l: l.name)
|
||||
levels = self._levels.get_levels_by_server_id(server.id).select(lambda l: l.name)
|
||||
return [
|
||||
app_commands.Choice(name=level, value=level)
|
||||
for level in self._client_utils.get_auto_complete_list(levels, current)
|
||||
@ -130,7 +130,7 @@ class LevelGroup(DiscordCommandABC):
|
||||
return
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
levels = self._levels.get_levels_by_server_id(server.server_id)
|
||||
levels = self._levels.get_levels_by_server_id(server.id)
|
||||
if levels.count() < 1:
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.level.error.nothing_found"))
|
||||
self._logger.trace(__name__, f"Finished command level list")
|
||||
@ -187,7 +187,7 @@ class LevelGroup(DiscordCommandABC):
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
level = Level(name, color, min_xp, permissions, server)
|
||||
levels = self._levels.get_levels_by_server_id(server.server_id)
|
||||
levels = self._levels.get_levels_by_server_id(server.id)
|
||||
|
||||
if levels.where(lambda l: l.name == level.name).first_or_default() is not None:
|
||||
self._logger.debug(__name__, f"Level with name {level.name} already exists")
|
||||
@ -261,7 +261,7 @@ class LevelGroup(DiscordCommandABC):
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
level_from_db = (
|
||||
self._levels.get_levels_by_server_id(server.server_id).where(lambda l: l.name == level).single_or_default()
|
||||
self._levels.get_levels_by_server_id(server.id).where(lambda l: l.name == level).single_or_default()
|
||||
)
|
||||
if level_from_db is None:
|
||||
await self._message_service.send_ctx_msg(
|
||||
@ -353,7 +353,7 @@ class LevelGroup(DiscordCommandABC):
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
level_from_db = (
|
||||
self._levels.get_levels_by_server_id(server.server_id).where(lambda l: l.name == level).first_or_default()
|
||||
self._levels.get_levels_by_server_id(server.id).where(lambda l: l.name == level).first_or_default()
|
||||
)
|
||||
if level_from_db is None:
|
||||
self._logger.debug(__name__, f"level {level} not found")
|
||||
@ -399,9 +399,9 @@ class LevelGroup(DiscordCommandABC):
|
||||
return
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
level = self._level_service.get_level(user)
|
||||
levels = self._levels.get_levels_by_server_id(server.server_id).order_by(lambda l: l.min_xp)
|
||||
levels = self._levels.get_levels_by_server_id(server.id).order_by(lambda l: l.min_xp)
|
||||
|
||||
if level == levels.first():
|
||||
await self._message_service.send_ctx_msg(
|
||||
@ -441,9 +441,9 @@ class LevelGroup(DiscordCommandABC):
|
||||
return
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
level = self._level_service.get_level(user)
|
||||
levels = self._levels.get_levels_by_server_id(server.server_id).order_by(lambda l: l.min_xp)
|
||||
levels = self._levels.get_levels_by_server_id(server.id).order_by(lambda l: l.min_xp)
|
||||
|
||||
if level.name == levels.last().name:
|
||||
await self._message_service.send_ctx_msg(
|
||||
@ -482,11 +482,9 @@ class LevelGroup(DiscordCommandABC):
|
||||
return
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
current_level = self._level_service.get_level(user)
|
||||
new_level = (
|
||||
self._levels.get_levels_by_server_id(server.server_id).where(lambda l: l.name == level).single_or_default()
|
||||
)
|
||||
new_level = self._levels.get_levels_by_server_id(server.id).where(lambda l: l.name == level).single_or_default()
|
||||
|
||||
if new_level is None:
|
||||
await self._message_service.send_ctx_msg(
|
||||
|
@ -47,7 +47,7 @@ class LevelSeeder(DataSeederABC):
|
||||
)
|
||||
self._logger.debug(__name__, f"Created role {level.name}")
|
||||
|
||||
levels = self._levels.find_levels_by_server_id(server.server_id)
|
||||
levels = self._levels.find_levels_by_server_id(server.id)
|
||||
if levels is None or levels.where(lambda l: l.name == level.name).first_or_default() is None:
|
||||
self._levels.add_level(level)
|
||||
self._logger.debug(__name__, f"Saved level {level.name}")
|
||||
@ -69,7 +69,7 @@ class LevelSeeder(DataSeederABC):
|
||||
if server is None:
|
||||
continue
|
||||
|
||||
levels = self._levels.find_levels_by_server_id(server.server_id)
|
||||
levels = self._levels.find_levels_by_server_id(server.id)
|
||||
if levels is not None and levels.count() > 0:
|
||||
# create levels from db
|
||||
for level in levels:
|
||||
|
@ -1,5 +1,3 @@
|
||||
import asyncio
|
||||
|
||||
import discord
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
@ -41,7 +39,7 @@ class LevelService:
|
||||
self._t = t
|
||||
|
||||
def get_level(self, user: User) -> Level:
|
||||
levels_by_server = self._levels.get_levels_by_server_id(user.server.server_id)
|
||||
levels_by_server = self._levels.get_levels_by_server_id(user.server.id)
|
||||
levels = levels_by_server.order_by(lambda l: l.min_xp).where(lambda l: user.xp >= l.min_xp)
|
||||
|
||||
if levels.count() == 0:
|
||||
@ -50,8 +48,8 @@ class LevelService:
|
||||
return levels.last()
|
||||
|
||||
async def set_level(self, user: User):
|
||||
level_names = self._levels.get_levels_by_server_id(user.server.server_id).select(lambda l: l.name)
|
||||
guild: Guild = self._bot.guilds.where(lambda g: g.id == user.server.discord_server_id).single()
|
||||
level_names = self._levels.get_levels_by_server_id(user.server.id).select(lambda l: l.name)
|
||||
guild: Guild = self._bot.guilds.where(lambda g: g.id == user.server.discord_id).single()
|
||||
member: Member = guild.members.where(lambda m: m.id == user.discord_id).single()
|
||||
|
||||
level = self.get_level(user)
|
||||
@ -89,7 +87,7 @@ class LevelService:
|
||||
return
|
||||
|
||||
server = self._servers.get_server_by_discord_id(member.guild.id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
if user is None:
|
||||
self._logger.warn(__name__, f"User not found {member.guild.name}@{member.name}")
|
||||
return
|
||||
|
@ -66,7 +66,7 @@ class StatsGroup(DiscordCommandABC):
|
||||
)
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.server_id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.id)
|
||||
|
||||
if stats.count() == 0:
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.stats.list.nothing_found"))
|
||||
@ -103,7 +103,7 @@ class StatsGroup(DiscordCommandABC):
|
||||
|
||||
try:
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.server_id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.id)
|
||||
statistic = stats.where(lambda s: s.name == name).single()
|
||||
result = await self._statistic.execute(statistic.code, server)
|
||||
|
||||
@ -132,7 +132,7 @@ class StatsGroup(DiscordCommandABC):
|
||||
self, interaction: discord.Interaction, current: str
|
||||
) -> TList[app_commands.Choice[str]]:
|
||||
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.server_id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.id)
|
||||
return [
|
||||
app_commands.Choice(name=f"{statistic.name}: {statistic.description}", value=statistic.name)
|
||||
for statistic in stats
|
||||
@ -171,7 +171,7 @@ class StatsGroup(DiscordCommandABC):
|
||||
|
||||
try:
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.server_id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.id)
|
||||
statistic = stats.where(lambda s: s.name == name).single()
|
||||
form = AddStatisticForm(
|
||||
server,
|
||||
@ -196,7 +196,7 @@ class StatsGroup(DiscordCommandABC):
|
||||
self, interaction: discord.Interaction, current: str
|
||||
) -> TList[app_commands.Choice[str]]:
|
||||
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.server_id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.id)
|
||||
return [
|
||||
app_commands.Choice(name=f"{statistic.name}: {statistic.description}", value=statistic.name)
|
||||
for statistic in stats
|
||||
@ -211,7 +211,7 @@ class StatsGroup(DiscordCommandABC):
|
||||
|
||||
try:
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
statistic = self._stats.get_statistic_by_name(name, server.server_id)
|
||||
statistic = self._stats.get_statistic_by_name(name, server.id)
|
||||
self._stats.delete_statistic(statistic)
|
||||
self._db.save_changes()
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.stats.remove.success"))
|
||||
@ -225,7 +225,7 @@ class StatsGroup(DiscordCommandABC):
|
||||
self, interaction: discord.Interaction, current: str
|
||||
) -> TList[app_commands.Choice[str]]:
|
||||
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.server_id)
|
||||
stats = self._stats.get_statistics_by_server_id(server.id)
|
||||
return [
|
||||
app_commands.Choice(name=f"{statistic.name}: {statistic.description}", value=statistic.name)
|
||||
for statistic in stats
|
||||
|
@ -1,5 +1,3 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
from discord import Guild
|
||||
@ -49,22 +47,20 @@ class StatisticService:
|
||||
self._bot = bot
|
||||
|
||||
async def execute(self, code: str, server: Server) -> StatisticResult:
|
||||
guild = self._bot.guilds.where(lambda g: g.id == server.discord_server_id).single()
|
||||
guild = self._bot.guilds.where(lambda g: g.id == server.discord_id).single()
|
||||
|
||||
return await self.get_data(
|
||||
code,
|
||||
self._auto_roles.get_auto_roles().where(lambda x: x.server.server_id == server.server_id),
|
||||
self._clients.get_clients().where(lambda x: x.server.server_id == server.server_id),
|
||||
self._auto_roles.get_auto_roles().where(lambda x: x.server.id == server.id),
|
||||
self._clients.get_clients().where(lambda x: x.server.id == server.id),
|
||||
self._known_users.get_users(),
|
||||
self._levels.get_levels().where(lambda x: x.server.server_id == server.server_id),
|
||||
self._servers.get_servers().where(lambda x: x.server_id == server.server_id),
|
||||
self._user_joined_servers.get_user_joined_servers().where(
|
||||
lambda x: x.user.server.server_id == server.server_id
|
||||
),
|
||||
self._levels.get_levels().where(lambda x: x.server.id == server.id),
|
||||
self._servers.get_servers().where(lambda x: x.id == server.id),
|
||||
self._user_joined_servers.get_user_joined_servers().where(lambda x: x.user.server.id == server.id),
|
||||
self._user_joined_voice_channel.get_user_joined_voice_channels().where(
|
||||
lambda x: x.user.server.server_id == server.server_id
|
||||
lambda x: x.user.server.id == server.id
|
||||
),
|
||||
self._users.get_users().where(lambda x: x.server.server_id == server.server_id),
|
||||
self._users.get_users().where(lambda x: x.server.id == server.id),
|
||||
guild,
|
||||
)
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import discord
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_query.extension import List
|
||||
from cpl_translation import TranslatePipe
|
||||
from discord import ui, TextStyle
|
||||
|
||||
@ -45,7 +44,7 @@ class AddStatisticForm(ui.Modal):
|
||||
|
||||
async def on_submit(self, interaction: discord.Interaction):
|
||||
statistic = (
|
||||
self._stats.get_statistics_by_server_id(self._server.server_id)
|
||||
self._stats.get_statistics_by_server_id(self._server.id)
|
||||
.where(lambda s: s.name == self._name)
|
||||
.single_or_default()
|
||||
)
|
||||
|
@ -95,7 +95,7 @@ class ApiKeyGroup(DiscordCommandABC):
|
||||
self._logger.debug(__name__, f"Received command api-key add {ctx}: {identifier}")
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(ctx.author.id, server.server_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(ctx.author.id, server.id)
|
||||
api_key = ApiKey(identifier, str(uuid.uuid4()), user)
|
||||
self._api_keys.add_api_key(api_key)
|
||||
self._db.save_changes()
|
||||
|
@ -13,7 +13,7 @@ import { Queries } from "../../../../models/graphql/queries.model";
|
||||
import { LevelListQuery, UserListQuery } from "../../../../models/graphql/query.model";
|
||||
import { DataService } from "../../../../services/data/data.service";
|
||||
import { Page } from "../../../../models/graphql/filter/page.model";
|
||||
import { Sort } from "../../../../models/graphql/filter/sort.model";
|
||||
import { Sort, SortDirection } from "../../../../models/graphql/filter/sort.model";
|
||||
import { SidebarService } from "../../../../services/sidebar/sidebar.service";
|
||||
import { Mutations } from "../../../../models/graphql/mutations.model";
|
||||
import { throwError } from "rxjs";
|
||||
@ -171,7 +171,7 @@ export class MembersComponent {
|
||||
if (event.first != null && event.rows != null)
|
||||
this.page.pageIndex = event.first / event.rows;
|
||||
this.sort.sortColumn = event.sortField ?? undefined;
|
||||
this.sort.sortDirection = event.sortOrder === 1 ? "asc" : event.sortOrder === -1 ? "desc" : "asc";
|
||||
this.sort.sortDirection = event.sortOrder === 1 ? SortDirection.ASC : event.sortOrder === -1 ? SortDirection.DESC: SortDirection.ASC;
|
||||
|
||||
this.loadNextPage();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user