1.2.0 #406

Merged
edraft merged 20 commits from 1.2.0 into dev 2023-10-22 11:54:10 +02:00
4 changed files with 79 additions and 17 deletions
Showing only changes of commit 3cba8de675 - Show all commits

View File

@ -229,6 +229,10 @@
"success": "Verlinkung wurde entfernt :D"
},
"user": {
"birthday": {
"success": "Dein Geburtstag wurde eingetragen.",
"success_team": "{} hat seinen Geburtstag eingetragen: {}"
},
"add": {
"xp": "Die {} von {} wurden um {} erhöht"
},

View File

@ -131,7 +131,7 @@ class ClientUtilsService(ClientUtilsABC):
if current in sl:
sl = sl.skip(sl.index_of(current))
_l = _l.where(lambda x: x.name in sl)
_l = _l.where(lambda x: select(x) in sl)
return _l.take(25)

View File

@ -61,7 +61,7 @@ class AutoRoleGroup(DiscordCommandABC):
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)
for auto_role in self._client_utils.get_auto_complete_list(auto_roles, current, lambda x: x.name)
]
@commands.hybrid_group(name="auto-role")

View File

@ -1,10 +1,12 @@
from typing import Optional, List
import datetime
from typing import Optional, List as TList
import discord
from cpl_core.configuration import ConfigurationABC
from cpl_core.database.context import DatabaseContextABC
from cpl_discord.command import DiscordCommandABC
from cpl_discord.service import DiscordBotServiceABC
from cpl_query.extension import List
from cpl_translation import TranslatePipe
from discord import app_commands
from discord.ext import commands
@ -22,6 +24,7 @@ from bot_data.abc.user_joined_voice_channel_repository_abc import (
)
from bot_data.abc.user_repository_abc import UserRepositoryABC
from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
from bot_data.model.server_config import ServerConfig
from modules.base.service.user_warnings_service import UserWarningsService
from modules.level.service.level_service import LevelService
from modules.permission.abc.permission_service_abc import PermissionServiceABC
@ -73,7 +76,7 @@ class UserGroup(DiscordCommandABC):
"ontime": self._t.transform("modules.base.user.atr.ontime"),
}
self._atr_list = [(key, self._atr_dict[key]) for key in self._atr_dict]
self._atr_TList = [(key, self._atr_dict[key]) for key in self._atr_dict]
async def _handle_atr_calc(
self,
@ -116,6 +119,61 @@ class UserGroup(DiscordCommandABC):
async def user(self, ctx: Context):
pass
@user.command()
@commands.guild_only()
@CommandChecks.check_is_ready()
async def birthday(self, ctx: Context, day: int, month: int, year: int):
self._logger.debug(__name__, f"Received command user birthday {ctx}:{ctx.author},{day}:{month}:{year}")
date = datetime.date(year, month, day)
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.id)
user.birthday = date
self._users.update_user(user)
self._db.save_changes()
await self._message_service.send_interaction_msg(
ctx.interaction, self._t.transform("modules.base.user.birthday.success")
)
# notify team to prevent multiple entries every day
settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
channel = ctx.guild.get_channel(settings.team_channel_id)
await self._message_service.send_channel_message(
channel,
self._t.transform("modules.base.user.birthday.success_team").format(ctx.author.mention, date),
is_persistent=True,
)
self._logger.trace(__name__, f"Finished user-info command")
@birthday.autocomplete("day")
async def birthday_autocomplete(
self, interaction: discord.Interaction, current: str
) -> TList[app_commands.Choice[int]]:
days = List(int, range(0, 32)).select(lambda x: str(x))
return [
app_commands.Choice(name=date, value=date)
for date in self._client_utils.get_auto_complete_list(days, current)
]
@birthday.autocomplete("month")
async def birthday_autocomplete(
self, interaction: discord.Interaction, current: str
) -> TList[app_commands.Choice[int]]:
days = List(int, range(0, 13)).select(lambda x: str(x))
return [
app_commands.Choice(name=date, value=date)
for date in self._client_utils.get_auto_complete_list(days, current)
]
@birthday.autocomplete("year")
async def birthday_autocomplete(
self, interaction: discord.Interaction, current: str
) -> TList[app_commands.Choice[int]]:
today = datetime.date.today()
days = List(int, range(today.year - 75, today.year)).select(lambda x: str(x))
return [
app_commands.Choice(name=date, value=date)
for date in self._client_utils.get_auto_complete_list(days, current)
]
@user.command()
@commands.guild_only()
@CommandChecks.check_is_ready()
@ -237,8 +295,8 @@ class UserGroup(DiscordCommandABC):
)
@get.autocomplete("atr")
async def get_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
return [app_commands.Choice(name=value, value=key) for key, value in self._atr_list]
async def get_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
return [app_commands.Choice(name=value, value=key) for key, value in self._atr_TList]
@user.command()
@commands.guild_only()
@ -281,9 +339,9 @@ class UserGroup(DiscordCommandABC):
)
@set.autocomplete("atr")
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
atr_list = [("xp", self._atr_dict["xp"])]
return [app_commands.Choice(name=value, value=key) for key, value in atr_list]
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
atr_TList = [("xp", self._atr_dict["xp"])]
return [app_commands.Choice(name=value, value=key) for key, value in atr_TList]
@user.command()
@commands.guild_only()
@ -294,9 +352,9 @@ class UserGroup(DiscordCommandABC):
await self._handle_atr_calc(ctx, atr, value, member)
@add.autocomplete("atr")
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
atr_list = [("xp", self._atr_dict["xp"])]
return [app_commands.Choice(name=value, value=key) for key, value in atr_list]
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
atr_TList = [("xp", self._atr_dict["xp"])]
return [app_commands.Choice(name=value, value=key) for key, value in atr_TList]
@user.command()
@commands.guild_only()
@ -307,9 +365,9 @@ class UserGroup(DiscordCommandABC):
await self._handle_atr_calc(ctx, atr, value, member, is_remove=True)
@remove.autocomplete("atr")
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
atr_list = [("xp", self._atr_dict["xp"])]
return [app_commands.Choice(name=value, value=key) for key, value in atr_list]
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
atr_TList = [("xp", self._atr_dict["xp"])]
return [app_commands.Choice(name=value, value=key) for key, value in atr_TList]
@user.command()
@commands.guild_only()
@ -349,8 +407,8 @@ class UserGroup(DiscordCommandABC):
@reset.autocomplete("atr")
async def reset_autocomplete(
self, interaction: discord.Interaction, current: str
) -> List[app_commands.Choice[str]]:
return [app_commands.Choice(name=value, value=key) for key, value in self._atr_list]
) -> TList[app_commands.Choice[str]]:
return [app_commands.Choice(name=value, value=key) for key, value in self._atr_TList]
@user.group()
@commands.guild_only()