Reviewed-on: sh-edraft.de/kd_discord_bot#182 Reviewed-by: Ebola-Chan <nick.jungmann@gmail.com> Closes #179
This commit is contained in:
commit
37ec0cf0c7
@ -187,7 +187,13 @@
|
||||
"type_error": "Der angegebene Wert ist keine Zahl! :("
|
||||
}
|
||||
},
|
||||
"add": {
|
||||
"xp": "Die {} von {} wurden um {} erhöht"
|
||||
},
|
||||
"remove": {
|
||||
"xp": "Die {} von {} wurden um {} verringert"
|
||||
},
|
||||
"reset": {
|
||||
"xp": "Die {} von {} wurden entfernt",
|
||||
"ontime": "Die {} von {} wurden entfernt"
|
||||
},
|
||||
|
@ -1,4 +1,5 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
from typing import Callable
|
||||
|
||||
from cpl_query.extension import List
|
||||
@ -6,8 +7,6 @@ from discord.ext.commands import Context
|
||||
|
||||
from bot_data.model.user import User
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
from bot_data.model.user import User
|
||||
|
||||
|
||||
|
||||
class ClientUtilsABC(ABC):
|
||||
|
@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
from typing import Callable
|
||||
|
||||
import discord
|
||||
from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
@ -17,6 +17,7 @@ from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_repository_abc import UserJoinedVoiceChannelRepositoryABC
|
||||
from bot_data.abc.user_message_count_per_hour_repository_abc import UserMessageCountPerHourRepositoryABC
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.user_message_count_per_hour import UserMessageCountPerHour
|
||||
@ -33,8 +34,8 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
bot: DiscordBotServiceABC,
|
||||
servers: ServerRepositoryABC,
|
||||
clients: ClientRepositoryABC,
|
||||
umcphs: UserMessageCountPerHourRepositoryABC,
|
||||
user_joined_vc: UserJoinedVoiceChannelRepositoryABC,
|
||||
umcphs: UserMessageCountPerHourRepositoryABC,
|
||||
message_service: MessageServiceABC,
|
||||
db: DatabaseContextABC,
|
||||
t: TranslatePipe,
|
||||
@ -90,8 +91,6 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
async def check_if_bot_is_ready_yet_and_respond(self, ctx: Context) -> bool:
|
||||
result = await self.check_if_bot_is_ready_yet()
|
||||
if not result:
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.errors.bot_not_ready_yet'),
|
||||
without_tracking=True)
|
||||
await self._message_service.send_ctx_msg(
|
||||
ctx,
|
||||
self._t.transform('common.errors.bot_not_ready_yet'),
|
||||
|
@ -68,6 +68,35 @@ class UserGroup(DiscordCommandABC):
|
||||
|
||||
self._atr_list = [(key, self._atr_dict[key]) for key in self._atr_dict]
|
||||
|
||||
async def _handle_atr_calc(self, ctx: Context, atr: str, value: int, member: discord.Member, is_remove=False):
|
||||
if member is None or not isinstance(member, discord.Member):
|
||||
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)
|
||||
|
||||
if atr == 'xp':
|
||||
if is_remove:
|
||||
user.xp -= value
|
||||
else:
|
||||
user.xp += value
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
await self._level.check_level(member)
|
||||
|
||||
else:
|
||||
await self._message_service.send_interaction_msg(
|
||||
ctx.interaction,
|
||||
self._t.transform('modules.base.user.error.atr_not_found').format(atr)
|
||||
)
|
||||
return
|
||||
|
||||
type = 'add' if not is_remove else 'remove'
|
||||
await self._message_service.send_interaction_msg(
|
||||
ctx.interaction,
|
||||
self._t.transform(f'modules.base.user.{type}.{atr.lower()}').format(atr, value, member.mention)
|
||||
)
|
||||
|
||||
@commands.hybrid_group()
|
||||
@commands.guild_only()
|
||||
async def user(self, ctx: Context):
|
||||
@ -130,8 +159,11 @@ class UserGroup(DiscordCommandABC):
|
||||
embed.add_field(name=self._t.transform('modules.base.user.atr.lefts'), value=lefts_string)
|
||||
|
||||
if is_mod or member == ctx.author:
|
||||
embed.add_field(name=self._t.transform('modules.base.user.atr.warnings'),
|
||||
value=self._t.transform('common.not_implemented_yet'), inline=False)
|
||||
embed.add_field(
|
||||
name=self._t.transform('modules.base.user.atr.warnings'),
|
||||
value=self._t.transform('common.not_implemented_yet'),
|
||||
inline=False
|
||||
)
|
||||
|
||||
# send to interaction because of sensitive data
|
||||
await self._message_service.send_interaction_msg(ctx.interaction, embed, wait_before_delete=wait)
|
||||
@ -180,7 +212,7 @@ class UserGroup(DiscordCommandABC):
|
||||
@commands.guild_only()
|
||||
@CommandChecks.check_is_ready()
|
||||
@CommandChecks.check_is_member_moderator()
|
||||
async def set(self, ctx: Context, atr: str, value: str, member: discord.Member = None):
|
||||
async def set(self, ctx: Context, atr: str, value: int, member: discord.Member = None):
|
||||
self._logger.debug(__name__, f'Received command user-set {atr} {ctx}:{member}')
|
||||
|
||||
if member is None or not isinstance(member, discord.Member):
|
||||
@ -190,14 +222,8 @@ class UserGroup(DiscordCommandABC):
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
|
||||
if atr == 'xp':
|
||||
if not value.isnumeric():
|
||||
await self._message_service.send_interaction_msg(
|
||||
ctx.interaction, self._t.transform('modules.base.user.set.error.value_type_not_numeric')
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
user.xp = int(value)
|
||||
user.xp = value
|
||||
except TypeError as te:
|
||||
self._logger.error(__name__, f'String value couldn\'t be converted to int', te)
|
||||
await self._message_service.send_interaction_msg(
|
||||
@ -231,8 +257,34 @@ class UserGroup(DiscordCommandABC):
|
||||
@commands.guild_only()
|
||||
@CommandChecks.check_is_ready()
|
||||
@CommandChecks.check_is_member_moderator()
|
||||
async def remove(self, ctx: Context, atr: str, member: discord.Member = None):
|
||||
self._logger.debug(__name__, f'Received command user-remove {atr} {ctx}:{member}')
|
||||
async def add(self, ctx: Context, atr: str, value: int, member: discord.Member = None):
|
||||
self._logger.debug(__name__, f'Received command user-add {atr}-={value} {ctx}:{member}')
|
||||
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]
|
||||
|
||||
@user.command()
|
||||
@commands.guild_only()
|
||||
@CommandChecks.check_is_ready()
|
||||
@CommandChecks.check_is_member_moderator()
|
||||
async def remove(self, ctx: Context, atr: str, value: int, member: discord.Member = None):
|
||||
self._logger.debug(__name__, f'Received command user-remove {atr}-={value} {ctx}:{member}')
|
||||
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]
|
||||
|
||||
@user.command()
|
||||
@commands.guild_only()
|
||||
@CommandChecks.check_is_ready()
|
||||
@CommandChecks.check_is_member_moderator()
|
||||
async def reset(self, ctx: Context, atr: str, member: discord.Member = None):
|
||||
self._logger.debug(__name__, f'Received command user-reset {atr} {ctx}:{member}')
|
||||
|
||||
if member is None or not isinstance(member, discord.Member):
|
||||
member = ctx.author
|
||||
@ -259,11 +311,11 @@ class UserGroup(DiscordCommandABC):
|
||||
|
||||
await self._message_service.send_interaction_msg(
|
||||
ctx.interaction,
|
||||
self._t.transform(f'modules.base.user.remove.{atr.lower()}').format(atr, member.mention)
|
||||
self._t.transform(f'modules.base.user.reset.{atr.lower()}').format(atr, member.mention)
|
||||
)
|
||||
|
||||
@remove.autocomplete('atr')
|
||||
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> List[
|
||||
@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]
|
||||
|
@ -7,7 +7,7 @@ from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.events import OnVoiceStateUpdateABC
|
||||
|
||||
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||
from bot_core.helper.event_checks import EventChecks
|
||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
@ -33,7 +33,7 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
|
||||
users: UserRepositoryABC,
|
||||
user_joins: UserJoinedServerRepositoryABC,
|
||||
user_joins_vc: UserJoinedVoiceChannelRepositoryABC,
|
||||
client_utils: ClientUtilsServiceABC,
|
||||
client_utils: ClientUtilsABC,
|
||||
db: DatabaseContextABC,
|
||||
):
|
||||
OnVoiceStateUpdateABC.__init__(self)
|
||||
|
Loading…
Reference in New Issue
Block a user