Reviewed-on: sh-edraft.de/kd_discord_bot#94 Reviewed-by: Ebola-Chan <nick.jungmann@gmail.com> Closes #29
This commit is contained in:
commit
22456946b8
@ -150,7 +150,17 @@
|
|||||||
"login_message": "Ich bin on the line :D\nDer Scheiß hat {} Sekunden gedauert"
|
"login_message": "Ich bin on the line :D\nDer Scheiß hat {} Sekunden gedauert"
|
||||||
},
|
},
|
||||||
"level": {
|
"level": {
|
||||||
"new_level_message": "<@{}> ist nun Level {}"
|
"new_level_message": "<@{}> ist nun Level {}",
|
||||||
|
"error": {
|
||||||
|
"nothing_found": "Keine auto-role Einträge gefunden."
|
||||||
|
},
|
||||||
|
"list": {
|
||||||
|
"title": "Level:",
|
||||||
|
"description": "Konfigurierte Level:",
|
||||||
|
"name": "Name",
|
||||||
|
"min_xp": "Mindest XP",
|
||||||
|
"permission_int": "Berechtigungen"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"database": {},
|
"database": {},
|
||||||
"permission": {
|
"permission": {
|
||||||
|
26
kdb-bot/src/modules/level/command/__init__.py
Normal file
26
kdb-bot/src/modules/level/command/__init__.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
bot Keksdose bot
|
||||||
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
Discord bot for the Keksdose discord Server
|
||||||
|
|
||||||
|
:copyright: (c) 2022 sh-edraft.de
|
||||||
|
:license: MIT, see LICENSE for more details.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
__title__ = 'modules.level.command'
|
||||||
|
__author__ = 'Sven Heidemann'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
|
||||||
|
__version__ = '0.3.dev29'
|
||||||
|
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
# imports
|
||||||
|
|
||||||
|
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||||
|
version_info = VersionInfo(major='0', minor='3', micro='dev29')
|
89
kdb-bot/src/modules/level/command/level_group.py
Normal file
89
kdb-bot/src/modules/level/command/level_group.py
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
import discord
|
||||||
|
from cpl_core.database.context import DatabaseContextABC
|
||||||
|
from cpl_discord.command import DiscordCommandABC
|
||||||
|
from cpl_discord.service import DiscordBotServiceABC
|
||||||
|
from cpl_translation import TranslatePipe
|
||||||
|
from discord.ext import commands
|
||||||
|
from discord.ext.commands import Context
|
||||||
|
|
||||||
|
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||||
|
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||||
|
from bot_core.logging.command_logger import CommandLogger
|
||||||
|
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||||
|
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||||
|
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||||
|
|
||||||
|
|
||||||
|
class LevelGroup(DiscordCommandABC):
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
logger: CommandLogger,
|
||||||
|
message_service: MessageServiceABC,
|
||||||
|
bot: DiscordBotServiceABC,
|
||||||
|
client_utils: ClientUtilsServiceABC,
|
||||||
|
permission_service: PermissionServiceABC,
|
||||||
|
translate: TranslatePipe,
|
||||||
|
db_context: DatabaseContextABC,
|
||||||
|
levels: LevelRepositoryABC,
|
||||||
|
servers: ServerRepositoryABC,
|
||||||
|
):
|
||||||
|
DiscordCommandABC.__init__(self)
|
||||||
|
|
||||||
|
self._logger = logger
|
||||||
|
self._message_service = message_service
|
||||||
|
self._bot = bot
|
||||||
|
self._client_utils = client_utils
|
||||||
|
self._permissions = permission_service
|
||||||
|
self._t = translate
|
||||||
|
self._db_context = db_context
|
||||||
|
self._levels = levels
|
||||||
|
self._servers = servers
|
||||||
|
|
||||||
|
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
|
||||||
|
|
||||||
|
@commands.hybrid_group()
|
||||||
|
@commands.guild_only()
|
||||||
|
async def level(self, ctx: Context):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@level.command(alias='levels')
|
||||||
|
@commands.guild_only()
|
||||||
|
async def list(self, ctx: Context, wait: int = None):
|
||||||
|
self._logger.debug(__name__, f'Received command level list {ctx}')
|
||||||
|
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
|
||||||
|
return
|
||||||
|
|
||||||
|
if not self._permissions.is_member_moderator(ctx.author):
|
||||||
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
|
||||||
|
self._logger.trace(__name__, f'Finished command level list')
|
||||||
|
return
|
||||||
|
|
||||||
|
if ctx.guild is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||||
|
levels = self._levels.get_levels_by_server_id(server.server_id)
|
||||||
|
if levels.count() < 1:
|
||||||
|
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.error.nothing_found'))
|
||||||
|
self._logger.trace(__name__, f'Finished command level list')
|
||||||
|
return
|
||||||
|
|
||||||
|
level_name = ''
|
||||||
|
xp = ''
|
||||||
|
permissions = ''
|
||||||
|
for level in levels:
|
||||||
|
level_name += f'\n{level.name}'
|
||||||
|
xp += f'\n{level.min_xp}'
|
||||||
|
permissions += f'\n{level.permissions}'
|
||||||
|
|
||||||
|
embed = discord.Embed(
|
||||||
|
title=self._t.transform('modules.level.list.title'),
|
||||||
|
description=self._t.transform('modules.level.list.description'),
|
||||||
|
color=int('ef9d0d', 16)
|
||||||
|
)
|
||||||
|
embed.add_field(name=self._t.transform('modules.level.list.name'), value=level_name, inline=True)
|
||||||
|
embed.add_field(name=self._t.transform('modules.level.list.min_xp'), value=xp, inline=True)
|
||||||
|
embed.add_field(name=self._t.transform('modules.level.list.permission_int'), value=permissions, inline=True)
|
||||||
|
await self._message_service.send_ctx_msg(ctx, embed, wait_before_delete=wait)
|
||||||
|
self._logger.trace(__name__, f'Finished command level list')
|
@ -8,6 +8,7 @@ from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
|||||||
|
|
||||||
from bot_core.abc.module_abc import ModuleABC
|
from bot_core.abc.module_abc import ModuleABC
|
||||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||||
|
from modules.level.command.level_group import LevelGroup
|
||||||
from modules.level.events.level_on_message_event import LevelOnMessageEvent
|
from modules.level.events.level_on_message_event import LevelOnMessageEvent
|
||||||
from modules.level.events.level_on_voice_state_update_event import LevelOnVoiceStateUpdateEvent
|
from modules.level.events.level_on_voice_state_update_event import LevelOnVoiceStateUpdateEvent
|
||||||
from modules.level.level_seeder import LevelSeeder
|
from modules.level.level_seeder import LevelSeeder
|
||||||
@ -29,5 +30,9 @@ class LevelModule(ModuleABC):
|
|||||||
services.add_transient(LevelSeeder)
|
services.add_transient(LevelSeeder)
|
||||||
services.add_transient(LevelService)
|
services.add_transient(LevelService)
|
||||||
|
|
||||||
|
# commands
|
||||||
|
self._dc.add_command(LevelGroup)
|
||||||
|
|
||||||
|
# events
|
||||||
self._dc.add_event(DiscordEventTypesEnum.on_message.value, LevelOnMessageEvent)
|
self._dc.add_event(DiscordEventTypesEnum.on_message.value, LevelOnMessageEvent)
|
||||||
self._dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, LevelOnVoiceStateUpdateEvent)
|
self._dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, LevelOnVoiceStateUpdateEvent)
|
||||||
|
Loading…
Reference in New Issue
Block a user