Reviewed-on: sh-edraft.de/kd_discord_bot#144 Reviewed-by: Sven Heidemann <sven.heidemann@sh-edraft.de> Closes #23
This commit is contained in:
commit
6273ce9cba
@ -184,11 +184,13 @@
|
|||||||
"xp": "{} hat nun {} xp",
|
"xp": "{} hat nun {} xp",
|
||||||
"error": {
|
"error": {
|
||||||
"value_type_not_numeric": "Der angegebende Wert ist keine Ganzzahl! :(",
|
"value_type_not_numeric": "Der angegebende Wert ist keine Ganzzahl! :(",
|
||||||
"type_error": "Der angegebene Wert konnte nicht als eine Ganzzahl interpretiert werden :(",
|
"type_error": "Der angegebene Wert konnte nicht als eine Ganzzahl interpretiert werden :("
|
||||||
"database_error": "Beim Speichern des Wertes kam es zu einem Fehler :(",
|
|
||||||
"general_error": "Bei der Ausführung dieses Befehls kam es zu einen Fehler :("
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"remove": {
|
||||||
|
"xp": "Die {} von {} wurden entfernt",
|
||||||
|
"ontime": "Die {} von {} wurden entfernt"
|
||||||
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"atr_not_found": "Das Attribut {} konnte nicht gefunden werden :("
|
"atr_not_found": "Das Attribut {} konnte nicht gefunden werden :("
|
||||||
}
|
}
|
||||||
|
@ -35,3 +35,6 @@ class UserJoinedVoiceChannelRepositoryABC(ABC):
|
|||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def delete_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel): pass
|
def delete_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def delete_user_joined_voice_channel_by_user_id(self, user_id: int): pass
|
||||||
|
@ -119,3 +119,10 @@ class UserJoinedVoiceChannel(TableABC):
|
|||||||
DELETE FROM `UserJoinedVoiceChannel`
|
DELETE FROM `UserJoinedVoiceChannel`
|
||||||
WHERE `JoinId` = {self._join_id};
|
WHERE `JoinId` = {self._join_id};
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def delete_by_user_id_string(id: int) -> str:
|
||||||
|
return str(f"""
|
||||||
|
DELETE FROM `UserJoinedVoiceChannel`
|
||||||
|
WHERE `UserId` = {id}
|
||||||
|
""")
|
@ -121,3 +121,7 @@ class UserJoinedVoiceChannelRepositoryService(UserJoinedVoiceChannelRepositoryAB
|
|||||||
def delete_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel):
|
def delete_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel):
|
||||||
self._logger.trace(__name__, f'Send SQL command: {user_joined_voice_channel.delete_string}')
|
self._logger.trace(__name__, f'Send SQL command: {user_joined_voice_channel.delete_string}')
|
||||||
self._context.cursor.execute(user_joined_voice_channel.delete_string)
|
self._context.cursor.execute(user_joined_voice_channel.delete_string)
|
||||||
|
|
||||||
|
def delete_user_joined_voice_channel_by_user_id(self, user_id: int):
|
||||||
|
self._logger.trace(__name__, f'Send SQL command: {UserJoinedVoiceChannel.delete_by_user_id_string}')
|
||||||
|
self._context.cursor.execute(UserJoinedVoiceChannel.delete_by_user_id_string(user_id))
|
||||||
|
@ -194,16 +194,14 @@ class UserGroup(DiscordCommandABC):
|
|||||||
|
|
||||||
if atr == self._atr_dict["xp"]:
|
if atr == self._atr_dict["xp"]:
|
||||||
if not value.isnumeric():
|
if not value.isnumeric():
|
||||||
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform(
|
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.set.error.value_type_not_numeric'))
|
||||||
'modules.base.user.set.error.value_type_not_numeric'))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
user.xp = int(value)
|
user.xp = int(value)
|
||||||
except TypeError as te:
|
except TypeError as te:
|
||||||
self._logger.error(__name__, f'String value couldn\'t be converted to int', te)
|
self._logger.error(__name__, f'String value couldn\'t be converted to int', te)
|
||||||
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform(
|
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.set.error.type_error'))
|
||||||
'modules.base.user.set.error.type_error'))
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self._users.update_user(user)
|
self._users.update_user(user)
|
||||||
@ -211,16 +209,49 @@ class UserGroup(DiscordCommandABC):
|
|||||||
await self._level.check_level(member)
|
await self._level.check_level(member)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform(
|
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.error.atr_not_found').format(atr))
|
||||||
'modules.base.user.error.atr_not_found').format(atr))
|
|
||||||
return
|
return
|
||||||
|
|
||||||
await self._message_service.send_interaction_msg(
|
await self._message_service.send_interaction_msg(ctx.interaction,self._t.transform(f'modules.base.user.set.{atr}').format(member.mention, value))
|
||||||
ctx.interaction,
|
|
||||||
self._t.transform(f'modules.base.user.set.{atr}').format(member.mention, value)
|
|
||||||
)
|
|
||||||
|
|
||||||
@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) -> List[app_commands.Choice[str]]:
|
||||||
atr_list = [self._atr_dict["xp"]]
|
atr_list = [self._atr_dict["xp"]]
|
||||||
return [app_commands.Choice(name=atr, value=atr) for atr in atr_list]
|
return [app_commands.Choice(name=atr, value=atr) for atr 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, member: discord.Member = None):
|
||||||
|
self._logger.debug(__name__, f'Received command user-remove {ctx}:{member}')
|
||||||
|
|
||||||
|
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 == self._atr_dict["xp"]:
|
||||||
|
user.xp = 0
|
||||||
|
self._users.update_user(user)
|
||||||
|
self._db.save_changes()
|
||||||
|
await self._level.check_level(member)
|
||||||
|
|
||||||
|
elif atr == self._atr_dict["ontime"]:
|
||||||
|
self._user_joined_voice_channel.delete_user_joined_voice_channel_by_user_id(user.user_id)
|
||||||
|
self._db.save_changes()
|
||||||
|
|
||||||
|
else:
|
||||||
|
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.error.atr_not_found').format(atr))
|
||||||
|
return
|
||||||
|
|
||||||
|
await self._message_service.send_interaction_msg(
|
||||||
|
ctx.interaction,
|
||||||
|
self._t.transform(f'modules.base.user.remove.{atr}').format(atr, member.mention)
|
||||||
|
)
|
||||||
|
|
||||||
|
@remove.autocomplete('atr')
|
||||||
|
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
|
||||||
|
atr_list = [self._atr_dict["xp"], self._atr_dict["ontime"]]
|
||||||
|
return [app_commands.Choice(name=atr, value=atr) for atr in atr_list]
|
||||||
|
Loading…
Reference in New Issue
Block a user