Added logic to list game ident users #366
This commit is contained in:
parent
ca5a6c81b8
commit
b53ddb1351
@ -21,6 +21,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"common": {
|
"common": {
|
||||||
|
"feature_not_activated": "Diese Funktion ist deaktiviert",
|
||||||
"bot_has_no_permission_message": "Ey!!!\nWas soll das?\nIch habe keine Berechtigungen :(\nScheiß System...",
|
"bot_has_no_permission_message": "Ey!!!\nWas soll das?\nIch habe keine Berechtigungen :(\nScheiß System...",
|
||||||
"colors": {
|
"colors": {
|
||||||
"blue": "Blau",
|
"blue": "Blau",
|
||||||
@ -170,6 +171,11 @@
|
|||||||
"error": {
|
"error": {
|
||||||
"nothing_found": "Keine Gameserver gefunden."
|
"nothing_found": "Keine Gameserver gefunden."
|
||||||
},
|
},
|
||||||
|
"list_members": {
|
||||||
|
"title": "Mitglieder",
|
||||||
|
"description": "Konfigurierte Mitglieder:",
|
||||||
|
"users": "Mitglieder"
|
||||||
|
},
|
||||||
"list": {
|
"list": {
|
||||||
"title": "Gameserver",
|
"title": "Gameserver",
|
||||||
"description": "Konfigurierte Gameserver:",
|
"description": "Konfigurierte Gameserver:",
|
||||||
|
@ -20,3 +20,4 @@ class FeatureFlagsEnum(Enum):
|
|||||||
api_only = "ApiOnly"
|
api_only = "ApiOnly"
|
||||||
presence = "Presence"
|
presence = "Presence"
|
||||||
version_in_presence = "VersionInPresence"
|
version_in_presence = "VersionInPresence"
|
||||||
|
game_server = "GameServer"
|
||||||
|
@ -22,6 +22,7 @@ class FeatureFlagsSettings(ConfigurationModelABC):
|
|||||||
FeatureFlagsEnum.api_only.value: False, # 13.10.2022 #70
|
FeatureFlagsEnum.api_only.value: False, # 13.10.2022 #70
|
||||||
FeatureFlagsEnum.presence.value: True, # 03.10.2022 #56
|
FeatureFlagsEnum.presence.value: True, # 03.10.2022 #56
|
||||||
FeatureFlagsEnum.version_in_presence.value: False, # 21.03.2023 #253
|
FeatureFlagsEnum.version_in_presence.value: False, # 21.03.2023 #253
|
||||||
|
FeatureFlagsEnum.game_server.value: False, # 25.09.2023 #366
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, **kwargs: dict):
|
def __init__(self, **kwargs: dict):
|
||||||
|
@ -14,6 +14,10 @@ class UserGameIdentRepositoryABC(ABC):
|
|||||||
def get_user_game_idents(self) -> List[UserGameIdent]:
|
def get_user_game_idents(self) -> List[UserGameIdent]:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_user_game_idents_by_game_server_id(self, id: int) -> List[UserGameIdent]:
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_user_game_ident_by_id(self, id: int) -> UserGameIdent:
|
def get_user_game_ident_by_id(self, id: int) -> UserGameIdent:
|
||||||
pass
|
pass
|
||||||
|
@ -49,6 +49,15 @@ class UserGameIdent(TableABC):
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_select_by_game_server_id_string(id: int) -> str:
|
||||||
|
return str(
|
||||||
|
f"""
|
||||||
|
SELECT * FROM `UserGameIdents`
|
||||||
|
WHERE `GameServerId` = {id};
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_select_by_id_string(id: int) -> str:
|
def get_select_by_id_string(id: int) -> str:
|
||||||
return str(
|
return str(
|
||||||
|
@ -51,6 +51,19 @@ class UserGameIdentRepositoryService(UserGameIdentRepositoryABC):
|
|||||||
|
|
||||||
return joins
|
return joins
|
||||||
|
|
||||||
|
def get_user_game_idents_by_game_server_id(self, game_server_id: int) -> List[UserGameIdent]:
|
||||||
|
joins = List(UserGameIdent)
|
||||||
|
self._logger.trace(
|
||||||
|
__name__,
|
||||||
|
f"Send SQL command: {UserGameIdent.get_select_by_game_server_id_string(game_server_id)}",
|
||||||
|
)
|
||||||
|
results = self._context.select(UserGameIdent.get_select_by_game_server_id_string(game_server_id))
|
||||||
|
for result in results:
|
||||||
|
self._logger.trace(__name__, f"Get UserGameIdent with id {result[0]}")
|
||||||
|
joins.append(self._from_result(result))
|
||||||
|
|
||||||
|
return joins
|
||||||
|
|
||||||
def get_user_game_ident_by_id(self, id: int) -> UserGameIdent:
|
def get_user_game_ident_by_id(self, id: int) -> UserGameIdent:
|
||||||
self._logger.trace(
|
self._logger.trace(
|
||||||
__name__,
|
__name__,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from typing import List as TList
|
from typing import List as TList
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
from cpl_core.database.context import DatabaseContextABC
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
from cpl_discord.command import DiscordCommandABC
|
from cpl_discord.command import DiscordCommandABC
|
||||||
from cpl_discord.service import DiscordBotServiceABC
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
@ -11,38 +12,49 @@ from discord.ext.commands import Context
|
|||||||
|
|
||||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||||
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
|
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||||
from bot_core.helper.command_checks import CommandChecks
|
from bot_core.helper.command_checks import CommandChecks
|
||||||
from bot_core.logging.command_logger import CommandLogger
|
from bot_core.logging.command_logger import CommandLogger
|
||||||
from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC
|
from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC
|
||||||
from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC
|
from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC
|
||||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
|
from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryABC
|
||||||
|
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||||
from bot_data.model.game_server import GameServer
|
from bot_data.model.game_server import GameServer
|
||||||
|
from bot_data.model.server_config import ServerConfig
|
||||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||||
|
|
||||||
|
|
||||||
class GameServerGroup(DiscordCommandABC):
|
class GameServerGroup(DiscordCommandABC):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
config: ConfigurationABC,
|
||||||
logger: CommandLogger,
|
logger: CommandLogger,
|
||||||
message_service: MessageServiceABC,
|
message_service: MessageServiceABC,
|
||||||
bot: DiscordBotServiceABC,
|
bot: DiscordBotServiceABC,
|
||||||
client_utils: ClientUtilsABC,
|
client_utils: ClientUtilsABC,
|
||||||
translate: TranslatePipe,
|
translate: TranslatePipe,
|
||||||
servers: ServerRepositoryABC,
|
servers: ServerRepositoryABC,
|
||||||
|
user: UserRepositoryABC,
|
||||||
game_servers: GameServerRepositoryABC,
|
game_servers: GameServerRepositoryABC,
|
||||||
|
user_game_idents: UserGameIdentRepositoryABC,
|
||||||
api_keys: ApiKeyRepositoryABC,
|
api_keys: ApiKeyRepositoryABC,
|
||||||
db: DatabaseContextABC,
|
db: DatabaseContextABC,
|
||||||
permission_service: PermissionServiceABC,
|
permission_service: PermissionServiceABC,
|
||||||
):
|
):
|
||||||
DiscordCommandABC.__init__(self)
|
DiscordCommandABC.__init__(self)
|
||||||
|
|
||||||
|
self._config = config
|
||||||
self._logger = logger
|
self._logger = logger
|
||||||
self._message_service = message_service
|
self._message_service = message_service
|
||||||
self._bot = bot
|
self._bot = bot
|
||||||
self._client_utils = client_utils
|
self._client_utils = client_utils
|
||||||
self._t = translate
|
self._t = translate
|
||||||
self._servers = servers
|
self._servers = servers
|
||||||
|
self._user = user
|
||||||
self._game_servers = game_servers
|
self._game_servers = game_servers
|
||||||
|
self._user_game_idents = user_game_idents
|
||||||
self._api_keys = api_keys
|
self._api_keys = api_keys
|
||||||
self._db = db
|
self._db = db
|
||||||
self._permissions = permission_service
|
self._permissions = permission_service
|
||||||
@ -64,6 +76,11 @@ class GameServerGroup(DiscordCommandABC):
|
|||||||
if ctx.guild is None:
|
if ctx.guild is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
|
||||||
|
if not FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum.game_server):
|
||||||
|
await self._message_service.send_ctx_msg(ctx, self._t.transform("common.feature_not_activated"))
|
||||||
|
return
|
||||||
|
|
||||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||||
game_servers = self._game_servers.get_game_servers_by_server_id(server.id)
|
game_servers = self._game_servers.get_game_servers_by_server_id(server.id)
|
||||||
if game_servers.count() < 1:
|
if game_servers.count() < 1:
|
||||||
@ -102,6 +119,14 @@ class GameServerGroup(DiscordCommandABC):
|
|||||||
async def add(self, ctx: Context, name: str, api_key_id: int):
|
async def add(self, ctx: Context, name: str, api_key_id: int):
|
||||||
self._logger.debug(__name__, f"Received command game-server add {ctx}: {name} {api_key_id}")
|
self._logger.debug(__name__, f"Received command game-server add {ctx}: {name} {api_key_id}")
|
||||||
|
|
||||||
|
if ctx.guild is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
|
||||||
|
if not FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum.game_server):
|
||||||
|
await self._message_service.send_ctx_msg(ctx, self._t.transform("common.feature_not_activated"))
|
||||||
|
return
|
||||||
|
|
||||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||||
api_key = self._api_keys.get_api_key_by_id(api_key_id)
|
api_key = self._api_keys.get_api_key_by_id(api_key_id)
|
||||||
game_server = GameServer(name, server, api_key)
|
game_server = GameServer(name, server, api_key)
|
||||||
@ -133,6 +158,14 @@ class GameServerGroup(DiscordCommandABC):
|
|||||||
async def remove(self, ctx: Context, id: int):
|
async def remove(self, ctx: Context, id: int):
|
||||||
self._logger.debug(__name__, f"Received command game-server remove {ctx}: {id}")
|
self._logger.debug(__name__, f"Received command game-server remove {ctx}: {id}")
|
||||||
|
|
||||||
|
if ctx.guild is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
|
||||||
|
if not FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum.game_server):
|
||||||
|
await self._message_service.send_ctx_msg(ctx, self._t.transform("common.feature_not_activated"))
|
||||||
|
return
|
||||||
|
|
||||||
game_server = self._game_servers.get_game_server_by_id(id)
|
game_server = self._game_servers.get_game_server_by_id(id)
|
||||||
self._game_servers.delete_game_server(game_server)
|
self._game_servers.delete_game_server(game_server)
|
||||||
self._db.save_changes()
|
self._db.save_changes()
|
||||||
@ -149,3 +182,44 @@ class GameServerGroup(DiscordCommandABC):
|
|||||||
app_commands.Choice(name=gs.name, value=gs.id)
|
app_commands.Choice(name=gs.name, value=gs.id)
|
||||||
for gs in self._client_utils.get_auto_complete_list(game_servers, current, lambda x: x.name)
|
for gs in self._client_utils.get_auto_complete_list(game_servers, current, lambda x: x.name)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@game_server.command(name="list-members")
|
||||||
|
@commands.guild_only()
|
||||||
|
@CommandChecks.check_is_ready()
|
||||||
|
@CommandChecks.check_is_member_moderator()
|
||||||
|
async def list_members(self, ctx: Context, id: int, wait: int = None):
|
||||||
|
self._logger.debug(__name__, f"Received command game-server remove {ctx}: {id}")
|
||||||
|
|
||||||
|
if ctx.guild is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
|
||||||
|
if not FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum.game_server):
|
||||||
|
await self._message_service.send_ctx_msg(ctx, self._t.transform("common.feature_not_activated"))
|
||||||
|
return
|
||||||
|
|
||||||
|
game_server = self._game_servers.get_game_server_by_id(id)
|
||||||
|
game_idents = self._user_game_idents.get_user_game_idents_by_game_server_id(game_server.id)
|
||||||
|
users = ""
|
||||||
|
for game_ident in game_idents:
|
||||||
|
users += f"\n{game_ident.user.name}"
|
||||||
|
|
||||||
|
embed = discord.Embed(
|
||||||
|
title=self._t.transform("modules.base.game_server.list_members.title"),
|
||||||
|
description=self._t.transform("modules.base.game_server.list_members.description"),
|
||||||
|
color=int("ef9d0d", 16),
|
||||||
|
)
|
||||||
|
embed.add_field(name=self._t.transform("modules.base.game_server.list_members.users"), value=users, inline=True)
|
||||||
|
await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait)
|
||||||
|
|
||||||
|
self._logger.trace(__name__, f"Finished command game-server remove")
|
||||||
|
|
||||||
|
@list_members.autocomplete("id")
|
||||||
|
async def id_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
|
server = self._servers.get_server_by_discord_id(interaction.guild.id)
|
||||||
|
game_servers = self._game_servers.get_game_servers_by_server_id(server.id)
|
||||||
|
|
||||||
|
return [
|
||||||
|
app_commands.Choice(name=gs.name, value=gs.id)
|
||||||
|
for gs in self._client_utils.get_auto_complete_list(game_servers, current, lambda x: x.name)
|
||||||
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user