Added birthday command #401
This commit is contained in:
parent
b7ff070676
commit
3cba8de675
@ -229,6 +229,10 @@
|
|||||||
"success": "Verlinkung wurde entfernt :D"
|
"success": "Verlinkung wurde entfernt :D"
|
||||||
},
|
},
|
||||||
"user": {
|
"user": {
|
||||||
|
"birthday": {
|
||||||
|
"success": "Dein Geburtstag wurde eingetragen.",
|
||||||
|
"success_team": "{} hat seinen Geburtstag eingetragen: {}"
|
||||||
|
},
|
||||||
"add": {
|
"add": {
|
||||||
"xp": "Die {} von {} wurden um {} erhöht"
|
"xp": "Die {} von {} wurden um {} erhöht"
|
||||||
},
|
},
|
||||||
|
@ -131,7 +131,7 @@ class ClientUtilsService(ClientUtilsABC):
|
|||||||
if current in sl:
|
if current in sl:
|
||||||
sl = sl.skip(sl.index_of(current))
|
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)
|
return _l.take(25)
|
||||||
|
|
||||||
|
@ -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)
|
auto_roles = self._auto_roles.get_auto_roles_by_server_id(server.id).select(lambda x: x.id)
|
||||||
return [
|
return [
|
||||||
app_commands.Choice(name=auto_role, value=auto_role)
|
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")
|
@commands.hybrid_group(name="auto-role")
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
from typing import Optional, List
|
import datetime
|
||||||
|
from typing import Optional, List as TList
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from cpl_core.configuration import ConfigurationABC
|
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
|
||||||
|
from cpl_query.extension import List
|
||||||
from cpl_translation import TranslatePipe
|
from cpl_translation import TranslatePipe
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from discord.ext import 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_repository_abc import UserRepositoryABC
|
||||||
from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
|
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.base.service.user_warnings_service import UserWarningsService
|
||||||
from modules.level.service.level_service import LevelService
|
from modules.level.service.level_service import LevelService
|
||||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
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"),
|
"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(
|
async def _handle_atr_calc(
|
||||||
self,
|
self,
|
||||||
@ -116,6 +119,61 @@ class UserGroup(DiscordCommandABC):
|
|||||||
async def user(self, ctx: Context):
|
async def user(self, ctx: Context):
|
||||||
pass
|
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()
|
@user.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@CommandChecks.check_is_ready()
|
@CommandChecks.check_is_ready()
|
||||||
@ -237,8 +295,8 @@ class UserGroup(DiscordCommandABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@get.autocomplete("atr")
|
@get.autocomplete("atr")
|
||||||
async def get_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
|
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_list]
|
return [app_commands.Choice(name=value, value=key) for key, value in self._atr_TList]
|
||||||
|
|
||||||
@user.command()
|
@user.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -281,9 +339,9 @@ class UserGroup(DiscordCommandABC):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@set.autocomplete("atr")
|
@set.autocomplete("atr")
|
||||||
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
|
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
atr_list = [("xp", self._atr_dict["xp"])]
|
atr_TList = [("xp", self._atr_dict["xp"])]
|
||||||
return [app_commands.Choice(name=value, value=key) for key, value in atr_list]
|
return [app_commands.Choice(name=value, value=key) for key, value in atr_TList]
|
||||||
|
|
||||||
@user.command()
|
@user.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -294,9 +352,9 @@ class UserGroup(DiscordCommandABC):
|
|||||||
await self._handle_atr_calc(ctx, atr, value, member)
|
await self._handle_atr_calc(ctx, atr, value, member)
|
||||||
|
|
||||||
@add.autocomplete("atr")
|
@add.autocomplete("atr")
|
||||||
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
|
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
atr_list = [("xp", self._atr_dict["xp"])]
|
atr_TList = [("xp", self._atr_dict["xp"])]
|
||||||
return [app_commands.Choice(name=value, value=key) for key, value in atr_list]
|
return [app_commands.Choice(name=value, value=key) for key, value in atr_TList]
|
||||||
|
|
||||||
@user.command()
|
@user.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -307,9 +365,9 @@ class UserGroup(DiscordCommandABC):
|
|||||||
await self._handle_atr_calc(ctx, atr, value, member, is_remove=True)
|
await self._handle_atr_calc(ctx, atr, value, member, is_remove=True)
|
||||||
|
|
||||||
@remove.autocomplete("atr")
|
@remove.autocomplete("atr")
|
||||||
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
|
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
|
||||||
atr_list = [("xp", self._atr_dict["xp"])]
|
atr_TList = [("xp", self._atr_dict["xp"])]
|
||||||
return [app_commands.Choice(name=value, value=key) for key, value in atr_list]
|
return [app_commands.Choice(name=value, value=key) for key, value in atr_TList]
|
||||||
|
|
||||||
@user.command()
|
@user.command()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -349,8 +407,8 @@ class UserGroup(DiscordCommandABC):
|
|||||||
@reset.autocomplete("atr")
|
@reset.autocomplete("atr")
|
||||||
async def reset_autocomplete(
|
async def reset_autocomplete(
|
||||||
self, interaction: discord.Interaction, current: str
|
self, interaction: discord.Interaction, current: str
|
||||||
) -> List[app_commands.Choice[str]]:
|
) -> TList[app_commands.Choice[str]]:
|
||||||
return [app_commands.Choice(name=value, value=key) for key, value in self._atr_list]
|
return [app_commands.Choice(name=value, value=key) for key, value in self._atr_TList]
|
||||||
|
|
||||||
@user.group()
|
@user.group()
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
|
Loading…
Reference in New Issue
Block a user