Compare commits

...

6 Commits

10 changed files with 153 additions and 43 deletions

@ -1 +1 @@
Subproject commit e7e9d85f7d0054ba95ae1ff87d91b4e218ef510f
Subproject commit c8983770f7a41f84441e6b60cdfe5eb694039f1c

View File

@ -160,20 +160,27 @@
"removed": "Presence wurde entfernt.",
"max_char_count_exceeded": "Der Text darf nicht mehr als 128 Zeichen lang sein!"
},
"user_info": {
"fields": {
"id": "Id",
"name": "Name",
"discord_join": "Discord beigetreten am",
"last_join": "Server beigetreten am",
"xp": "XP",
"ontime": "Ontime",
"roles": "Rollen",
"joins": "Beitritte",
"lefts": "Abgänge",
"warnings": "Verwarnungen"
"user": {
"info": {
"fields": {
"id": "Id",
"name": "Name",
"discord_join": "Discord beigetreten am",
"last_join": "Server beigetreten am",
"xp": "XP",
"ontime": "Ontime",
"roles": "Rollen",
"joins": "Beitritte",
"lefts": "Abgänge",
"warnings": "Verwarnungen"
},
"footer": ""
},
"footer": ""
"get": {
"atr_not_found": "Das Attribut {} konnte nicht gefunden werden :(",
"xp": "{} hat {} xp",
"ontime": "{} war insgesamt {} Stunden aktiv in einem Sprachkanal"
}
}
},
"boot_log": {

@ -1 +1 @@
Subproject commit 98303ffd45445eecfad57f8b1be86729de3661d2
Subproject commit e6046881b562982008583afa973b39ff08b6a3c7

View File

@ -98,7 +98,7 @@ class AutoRoleGroup(DiscordCommandABC):
message = List(discord.Message, [message async for message in channel.history(limit=50)]).where(lambda m: m.id == int(message_id)).single_or_default()
if message is None:
self._logger.debug(__name__, f'Message with id {message_id} not found in {channel.name}')
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.error.not_found').format(message_id, channel.name))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.add.error.not_found').format(message_id, channel.mention))
self._logger.trace(__name__, f'Finished command auto-role add')
return
@ -250,7 +250,7 @@ class AutoRoleGroup(DiscordCommandABC):
except Exception as e:
self._logger.error(__name__, f'Cannot add reaction {rule.emoji_name} to message: {auto_role_from_db.discord_message_id}', e)
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.rule.add.success').format(emoji, role.name, auto_role))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.auto_role.rule.add.success').format(emoji, role.mention, auto_role))
self._logger.trace(__name__, f'Finished command auto-role rule add')
@add.autocomplete('auto_role')

View File

@ -1,10 +1,11 @@
from typing import Optional
from typing import Optional, List
import discord
from cpl_core.configuration import ConfigurationABC
from cpl_discord.command import DiscordCommandABC
from cpl_discord.service import DiscordBotServiceABC
from cpl_translation import TranslatePipe
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context
@ -83,26 +84,28 @@ class UserGroup(DiscordCommandABC):
color=int('ef9d0d', 16)
)
ujvs = self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.user_id)
ontime = ujvs.sum(lambda join: round((join.leaved_on - join.joined_on).total_seconds() / 3600, 2))
ontime = self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.user_id).sum(
lambda join: round((join.leaved_on - join.joined_on).total_seconds() / 3600, 2))
embed.add_field(name=self._t.transform('modules.base.user_info.fields.id'), value=member.id)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.name'), value=member.name)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.discord_join'), value=self._date.transform(member.created_at), inline=False)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.last_join'), value=self._date.transform(member.joined_at), inline=False)
embed.add_field(name=self._t.transform('modules.base.user_info.fields.xp'), value=str(user.xp))
embed.add_field(name=self._t.transform('modules.base.user_info.fields.ontime'), value=str(ontime))
embed.add_field(name=self._t.transform('modules.base.user.info.fields.id'), value=member.id)
embed.add_field(name=self._t.transform('modules.base.user.info.fields.name'), value=member.name)
embed.add_field(name=self._t.transform('modules.base.user.info.fields.discord_join'),
value=self._date.transform(member.created_at), inline=False)
embed.add_field(name=self._t.transform('modules.base.user.info.fields.last_join'),
value=self._date.transform(member.joined_at), inline=False)
embed.add_field(name=self._t.transform('modules.base.user.info.fields.xp'), value=str(user.xp))
embed.add_field(name=self._t.transform('modules.base.user.info.fields.ontime'), value=str(ontime))
roles = ''
for role in member.roles:
roles += f'{role.name}\n'
embed.add_field(name=self._t.transform('modules.base.user_info.fields.roles'), value=roles, inline=False)
embed.add_field(name=self._t.transform('modules.base.user.info.fields.roles'), value=roles, inline=False)
if is_mod or member == ctx.author:
joins_string = ''
for join in joins:
joins_string += f'{self._date.transform(join.joined_on)}\n'
embed.add_field(name=self._t.transform('modules.base.user_info.fields.joins'), value=joins_string)
embed.add_field(name=self._t.transform('modules.base.user.info.fields.joins'), value=joins_string)
if is_mod or member == ctx.author:
lefts_string = ''
@ -113,11 +116,96 @@ class UserGroup(DiscordCommandABC):
continue
lefts_string += f'{self._date.transform(join.leaved_on)}\n'
embed.add_field(name=self._t.transform('modules.base.user_info.fields.lefts'), value=lefts_string)
embed.add_field(name=self._t.transform('modules.base.user.info.fields.lefts'), value=lefts_string)
if is_mod or member == ctx.author:
embed.add_field(name=self._t.transform('modules.base.user_info.fields.warnings'), value=self._t.transform('common.not_implemented_yet'), inline=False)
embed.add_field(name=self._t.transform('modules.base.user.info.fields.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)
self._logger.trace(__name__, f'Finished user-info command')
@user.command()
@commands.guild_only()
@CommandChecks.check_is_ready()
async def get(self, ctx: Context, atr: str, member: discord.Member = None):
self._logger.debug(__name__, f'Received command user-get {ctx}:{member}')
is_mod = self._permissions.is_member_moderator(ctx.author)
if member is not None and not is_mod:
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
return
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)
match atr:
case 'xp':
value = str(user.xp)
case 'ontime':
value = str(
self._user_joined_voice_channel.get_user_joined_voice_channels_by_user_id(user.user_id)
.sum(lambda join: round((join.leaved_on - join.joined_on).total_seconds() / 3600, 2))
)
case other:
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.get.atr_not_found').format(atr))
return
await self._message_service.send_interaction_msg(
ctx.interaction,
self._t.transform(f'modules.base.user.get.{atr}').format(member.mention, value)
)
@get.autocomplete('atr')
async def get_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
atr_list = ['xp', 'ontime']
return [app_commands.Choice(name=atr, value=atr) for atr in atr_list]
@commands.guild_only()
@CommandChecks.check_is_ready()
@CommandChecks.check_is_member_moderator()
async def set(self, ctx: Contex, atr: str, value: str, member: discord.Member = None):
self._logger.debug(__name__, f'Received command user-set {ctx}:{member}')
if value == '':
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.set.error.no_value'))
return
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)
match atr:
case 'xp':
try:
user.xp = int(value)
except Exception as e:
await self._logger.trace(__name__, f'Value couldn\'t be converted to int\n'+e)
# ToDo: Add text for this exception
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.error.value_type'))
return
case other:
# ToDo: Move atr_not_found
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform(
'modules.base.user.error.atr_not_found').format(atr))
return
# ToDo: Add text for set
await self._message_service.send_interaction_msg(
ctx.interaction,
self._t.transform(f'modules.base.user.set.{atr}').format(member.mention, value)
)
@set.autocomplete('atr')
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
atr_list = ['xp']
return [app_commands.Choice(name=atr, value=atr) for atr in atr_list]

View File

@ -70,10 +70,10 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC):
await self._messenger.send_dm_message(self._t.transform('modules.base.welcome_message').format(member.guild.name), member)
for admin in self._permission_service.get_admins(member.guild.id):
await self._messenger.send_dm_message(self._t.transform('modules.base.welcome_message_for_team').format(member.name), admin)
await self._messenger.send_dm_message(self._t.transform('modules.base.welcome_message_for_team').format(member.mention), admin)
for moderator in self._permission_service.get_moderators(member.guild.id):
await self._messenger.send_dm_message(self._t.transform('modules.base.welcome_message_for_team').format(member.name), moderator)
await self._messenger.send_dm_message(self._t.transform('modules.base.welcome_message_for_team').format(member.mention), moderator)
try:
server = self._servers.get_server_by_discord_id(member.guild.id)

View File

@ -46,7 +46,7 @@ class BaseOnVoiceStateUpdateEventHelpChannel(OnVoiceStateUpdateABC):
mods = [*self._permissions.get_admins(member.guild.id), *self._permissions.get_moderators(member.guild.id)]
for a in mods:
await self._message_service.send_dm_message(
self._t.transform('modules.base.member_joined_help_voice_channel').format(member.name),
self._t.transform('modules.base.member_joined_help_voice_channel').format(member.mention),
a,
)

View File

@ -303,7 +303,7 @@ class LevelGroup(DiscordCommandABC):
levels = self._levels.get_levels_by_server_id(server.server_id).order_by(lambda l: l.min_xp)
if level == levels.first():
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.down.already_first').format(member.name))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.down.already_first').format(member.mention))
self._logger.trace(__name__, f'Finished command level down')
return
@ -312,11 +312,11 @@ class LevelGroup(DiscordCommandABC):
user.xp = new_level.min_xp
self._users.update_user(user)
self._db.save_changes()
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.down.success').format(member.name, new_level.name))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.down.success').format(member.mention, new_level.name))
await self._level_service.set_level(user)
except Exception as e:
self._logger.error(__name__, f'Cannot level down {member.name} with level {level.name}', e)
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.down.failed').format(member.name))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.down.failed').format(member.mention))
self._logger.trace(__name__, f'Finished command level down')
@ -336,7 +336,7 @@ class LevelGroup(DiscordCommandABC):
levels = self._levels.get_levels_by_server_id(server.server_id).order_by(lambda l: l.min_xp)
if level.name == levels.last().name:
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.up.already_last').format(member.name))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.up.already_last').format(member.mention))
self._logger.trace(__name__, f'Finished command level up')
return
@ -345,11 +345,11 @@ class LevelGroup(DiscordCommandABC):
user.xp = new_level.min_xp
self._users.update_user(user)
self._db.save_changes()
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.up.success').format(member.name, new_level.name))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.up.success').format(member.mention, new_level.name))
await self._level_service.set_level(user)
except Exception as e:
self._logger.error(__name__, f'Cannot level up {member.name} with level {level.name}', e)
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.up.failed').format(member.name))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.up.failed').format(member.mention))
self._logger.trace(__name__, f'Finished command level up')
@ -374,7 +374,7 @@ class LevelGroup(DiscordCommandABC):
return
if current_level.name == level:
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.set.already_level').format(member.name, level))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.set.already_level').format(member.mention, level))
self._logger.trace(__name__, f'Finished command level set')
return
@ -382,11 +382,11 @@ class LevelGroup(DiscordCommandABC):
user.xp = new_level.min_xp
self._users.update_user(user)
self._db.save_changes()
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.set.success').format(member.name, new_level.name))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.set.success').format(member.mention, new_level.name))
await self._level_service.set_level(user)
except Exception as e:
self._logger.error(__name__, f'Cannot set level {level} for {member.name}', e)
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.set.failed').format(member.name))
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.set.failed').format(member.mention))
self._logger.trace(__name__, f'Finished command level set')

View File

@ -0,0 +1,13 @@
import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";
import { MembersComponent } from "./component/members/members.component";
const routes: Routes = [
{ path: '', component: MembersComponent },
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class MembersRoutingModule { }

View File

@ -1,9 +1,11 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { ServerDashboardComponent } from './server-dashboard/server-dashboard.component';
import { AuthGuard } from "../../shared/guards/auth/auth.guard";
const routes: Routes = [
{ path: '', component: ServerDashboardComponent }
{ path: '', component: ServerDashboardComponent },
{ path: 'members', loadChildren: () => import('./members/members.module').then(m => m.MembersModule), canActivate: [AuthGuard] },
];
@NgModule({