Merge pull request 'Added gmod support #277' (#459) from #277 into staging
All checks were successful
Deploy staging on push / pre-build (push) Successful in 1s
Deploy staging on push / build-bot (push) Successful in 3m8s
Deploy staging on push / build-web (push) Successful in 1m47s
Deploy staging on push / deploy (push) Successful in 24s

Reviewed-on: #459
This commit is contained in:
Sven Heidemann 2023-12-12 11:49:43 +01:00
commit 53c6bf4208
2 changed files with 57 additions and 8 deletions

View File

@ -11,6 +11,7 @@ from flask import request
from bot_api.configuration.authentication_settings import AuthenticationSettings
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_core.service.permission_service import PermissionService
from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC
from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC
@ -24,7 +25,6 @@ from bot_data.model.server_config import ServerConfig
from bot_data.model.user_joined_game_server import UserJoinedGameServer
from bot_data.model.user_role_enum import UserRoleEnum
from bot_graphql.abc.query_abc import QueryABC
from bot_core.service.permission_service import PermissionService
class UserJoinedGameServerMutation(QueryABC):
@ -79,7 +79,10 @@ class UserJoinedGameServerMutation(QueryABC):
)
def resolve_user_joined(self, *_, input: dict):
game_ident = self._user_game_idents.get_user_game_ident_by_ident(input["ident"])
game_ident = self._user_game_idents.find_user_game_ident_by_ident(input["ident"])
if game_ident is None:
return
user = game_ident.user
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{user.server.discord_id}")

View File

@ -9,6 +9,7 @@ from cpl_translation import TranslatePipe
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context
from valve.steam.id import SteamID
from bot_core.abc.client_utils_abc import ClientUtilsABC
from bot_core.abc.message_service_abc import MessageServiceABC
@ -50,6 +51,17 @@ class RegisterGroup(DiscordCommandABC):
self._logger.trace(__name__, f"Loaded command service: {type(self).__name__}")
async def _game_server_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_server.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)
]
@commands.hybrid_group()
@commands.guild_only()
async def register(self, ctx: Context):
@ -101,10 +113,44 @@ class RegisterGroup(DiscordCommandABC):
async def game_server_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_server.get_game_servers_by_server_id(server.id)
return await self._game_server_autocomplete(interaction, current)
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)
]
@register.command()
@commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def gmod(self, ctx: Context, member: discord.Member, game_server: int, steam_url: str):
self._logger.debug(__name__, f"Received command register gmod {ctx}")
steam_id = None
try:
self._logger.debug(__name__, f"Try to get steam id for {id}")
steam_id = SteamID.from_community_url(steam_url)
except Exception as e:
self._logger.error(__name__, f"Get steam id for {steam_id} failed", e)
await self._message_service.send_interaction_msg(
ctx.interaction, self._t.transform("modules.base.register.not_found")
)
if steam_id is None:
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.id)
gs = self._game_server.get_game_server_by_id(game_server)
game_ident = UserGameIdent(user, gs, steam_id)
self._user_game_ident.add_user_game_ident(game_ident)
self._db.save_changes()
await self._message_service.send_interaction_msg(
ctx.interaction, self._t.transform("modules.base.register.success")
)
self._logger.trace(__name__, f"Finished register gmod command")
@gmod.autocomplete("game_server")
async def game_server_autocomplete(
self, interaction: discord.Interaction, current: str
) -> TList[app_commands.Choice[str]]:
return await self._game_server_autocomplete(interaction, current)