1.1.0 #352

Merged
edraft merged 145 commits from 1.1.0 into master 2023-08-24 17:50:25 +02:00
12 changed files with 100 additions and 23 deletions
Showing only changes of commit 5dd2000f10 - Show all commits

@ -1 +1 @@
Subproject commit 359f9c38c3ec825a89f3bf289a65ec035cfcb693
Subproject commit 5e8e5caf886cf99dd74339bd7cdceb2f6c0ecb88

View File

@ -51,6 +51,9 @@ class AchievementGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def check(self, ctx: Context, member: discord.Member):
self._logger.debug(__name__, f"Received command achievement check {ctx}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(
server_config.feature_flags, FeatureFlagsEnum.achievements_module

View File

@ -37,15 +37,18 @@ class AchievementOnMessageEvent(OnMessageABC):
@EventChecks.check_is_ready()
async def on_message(self, message: discord.Message):
if message.guild is None:
return
if message.author.bot:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{message.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(
server_config.feature_flags, FeatureFlagsEnum.achievements_module
):
return
if message.author.bot:
return
server = self._servers.get_server_by_discord_id(message.guild.id)
user = self._users.get_user_by_discord_id_and_server_id(message.author.id, server.id)

View File

@ -75,11 +75,11 @@ class AutoRoleGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def list(self, ctx: Context, wait: int = None):
self._logger.debug(__name__, f"Received command auto-role list {ctx}")
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module):
if ctx.guild is None:
return
if ctx.guild is None:
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module):
return
embed = discord.Embed(
@ -119,6 +119,9 @@ class AutoRoleGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def add(self, ctx: Context, channel: discord.TextChannel, message_id: str):
self._logger.debug(__name__, f"Received command auto-role add {ctx} {message_id}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module):
return
@ -182,6 +185,9 @@ class AutoRoleGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def remove(self, ctx: Context, auto_role: int):
self._logger.debug(__name__, f"Received command auto-role remove {ctx} {auto_role}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module):
return
@ -225,6 +231,9 @@ class AutoRoleGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def list(self, ctx: Context, auto_role: int, wait: int = None):
self._logger.debug(__name__, f"Received command auto-role rule list {ctx}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module):
return
@ -280,6 +289,9 @@ class AutoRoleGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def add(self, ctx: Context, auto_role: int, emoji_name: str, role_id: str):
self._logger.debug(__name__, f"Received command auto-role add {ctx} {auto_role}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module):
return
@ -375,6 +387,9 @@ class AutoRoleGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def remove(self, ctx: Context, auto_role_rule: int):
self._logger.debug(__name__, f"Received command auto-role remove {ctx} {auto_role_rule}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module):
return

View File

@ -1,6 +1,7 @@
from typing import Optional
import discord
from cpl_core.configuration import ConfigurationABC
from cpl_core.database.context import DatabaseContextABC
from cpl_core.time import TimeFormatSettings
from cpl_discord.events import OnCommandABC
@ -13,12 +14,14 @@ from bot_core.logging.command_logger import CommandLogger
from bot_data.abc.client_repository_abc import ClientRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.user_repository_abc import UserRepositoryABC
from bot_data.model.server_config import ServerConfig
from bot_data.model.user import User
class BaseOnCommandEvent(OnCommandABC):
def __init__(
self,
config: ConfigurationABC,
logger: CommandLogger,
bot: DiscordBotServiceABC,
messenger: MessageServiceABC,
@ -30,6 +33,7 @@ class BaseOnCommandEvent(OnCommandABC):
servers: ServerRepositoryABC,
):
OnCommandABC.__init__(self)
self._config = config
self._logger = logger
self._bot = bot
self._messenger = messenger

View File

@ -1,6 +1,7 @@
from typing import Optional
import discord
from cpl_core.configuration import ConfigurationABC
from cpl_core.database.context import DatabaseContextABC
from cpl_discord.events import OnMessageDeleteABC
from cpl_discord.service import DiscordBotServiceABC
@ -10,12 +11,14 @@ from bot_core.logging.message_logger import MessageLogger
from bot_data.abc.client_repository_abc import ClientRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.abc.user_repository_abc import UserRepositoryABC
from bot_data.model.server_config import ServerConfig
from bot_data.model.user import User
class BaseOnMessageDeleteEvent(OnMessageDeleteABC):
def __init__(
self,
config: ConfigurationABC,
logger: MessageLogger,
db: DatabaseContextABC,
bot: DiscordBotServiceABC,
@ -24,6 +27,7 @@ class BaseOnMessageDeleteEvent(OnMessageDeleteABC):
servers: ServerRepositoryABC,
):
OnMessageDeleteABC.__init__(self)
self._config = config
self._logger = logger
self._db = db
self._bot = bot

View File

@ -1,6 +1,7 @@
from typing import List as TList
import discord
from cpl_core.configuration import ConfigurationABC
from cpl_core.database.context import DatabaseContextABC
from cpl_discord.command import DiscordCommandABC
from cpl_discord.container import Guild, Role
@ -12,12 +13,15 @@ from discord.ext.commands import Context
from bot_core.abc.client_utils_abc import ClientUtilsABC
from bot_core.abc.message_service_abc import MessageServiceABC
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_core.helper.command_checks import CommandChecks
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 bot_data.abc.user_repository_abc import UserRepositoryABC
from bot_data.model.level import Level
from bot_data.model.server_config import ServerConfig
from modules.level.level_seeder import LevelSeeder
from modules.level.service.level_service import LevelService
from modules.permission.abc.permission_service_abc import PermissionServiceABC
@ -26,6 +30,7 @@ from modules.permission.abc.permission_service_abc import PermissionServiceABC
class LevelGroup(DiscordCommandABC):
def __init__(
self,
config: ConfigurationABC,
logger: CommandLogger,
message_service: MessageServiceABC,
bot: DiscordBotServiceABC,
@ -41,6 +46,7 @@ class LevelGroup(DiscordCommandABC):
):
DiscordCommandABC.__init__(self)
self._config = config
self._logger = logger
self._message_service = message_service
self._bot = bot
@ -125,10 +131,13 @@ class LevelGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def list(self, ctx: Context, wait: int = None):
self._logger.debug(__name__, f"Received command level list {ctx}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
server = self._servers.get_server_by_discord_id(ctx.guild.id)
levels = self._levels.get_levels_by_server_id(server.id)
if levels.count() < 1:
@ -169,6 +178,12 @@ class LevelGroup(DiscordCommandABC):
@CommandChecks.check_is_member_admin()
async def create(self, ctx: Context, name: str, color: str, min_xp: int, permissions: int):
self._logger.debug(__name__, f"Received command level create {ctx}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
try:
color = hex(discord.Colour.from_str(color).value)
@ -258,6 +273,12 @@ class LevelGroup(DiscordCommandABC):
permissions: int = None,
):
self._logger.debug(__name__, f"Received command level edit {ctx}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
server = self._servers.get_server_by_discord_id(ctx.guild.id)
level_from_db = (
@ -350,6 +371,12 @@ class LevelGroup(DiscordCommandABC):
@CommandChecks.check_is_member_admin()
async def remove(self, ctx: Context, level: str):
self._logger.debug(__name__, f"Received command level remove {ctx}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
server = self._servers.get_server_by_discord_id(ctx.guild.id)
level_from_db = (
@ -394,6 +421,12 @@ class LevelGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def down(self, ctx: Context, member: discord.Member):
self._logger.debug(__name__, f"Received command level down {ctx} {member}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
if member.bot:
return
@ -436,6 +469,12 @@ class LevelGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def up(self, ctx: Context, member: discord.Member):
self._logger.debug(__name__, f"Received command level up {ctx} {member}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
if member.bot:
return
@ -477,6 +516,12 @@ class LevelGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def set(self, ctx: Context, member: discord.Member, level: str):
self._logger.debug(__name__, f"Received command level up {ctx} {member}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
if member.bot:
return
@ -529,5 +574,12 @@ class LevelGroup(DiscordCommandABC):
@CommandChecks.check_is_member_moderator()
async def reload(self, ctx: Context):
self._logger.debug(__name__, f"Received command level reload {ctx}")
if ctx.guild is None:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
await self._seed_levels(ctx)
self._logger.trace(__name__, f"Finished command level reload")

View File

@ -21,9 +21,7 @@ class LevelOnMemberJoinEvent(OnMemberJoinABC):
async def on_member_join(self, member: discord.Member):
self._logger.debug(__name__, f"Module {type(self)} started")
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(
server_config.feature_flags, FeatureFlagsEnum.achievements_module
):
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
await self._level.check_level(member)

View File

@ -20,10 +20,14 @@ class LevelOnMessageEvent(OnMessageABC):
@EventChecks.check_is_ready()
async def on_message(self, message: discord.Message):
self._logger.debug(__name__, f"Module {type(self)} started")
if message.guild is None:
return
if message.author.bot:
return
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{message.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(
server_config.feature_flags, FeatureFlagsEnum.achievements_module
):
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
try:

View File

@ -30,9 +30,7 @@ class LevelOnRawReactionAddEvent(OnRawReactionAddABC):
async def on_raw_reaction_add(self, payload: RawReactionActionEvent):
self._logger.debug(__name__, f"Module {type(self)} started")
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{payload.guild_id}")
if not FeatureFlagsSettings.get_flag_from_dict(
server_config.feature_flags, FeatureFlagsEnum.achievements_module
):
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
try:

View File

@ -30,9 +30,7 @@ class LevelOnRawReactionRemoveEvent(OnRawReactionRemoveABC):
async def on_raw_reaction_remove(self, payload: RawReactionActionEvent):
self._logger.debug(__name__, f"Module {type(self)} started")
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{payload.guild_id}")
if not FeatureFlagsSettings.get_flag_from_dict(
server_config.feature_flags, FeatureFlagsEnum.achievements_module
):
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
try:

View File

@ -28,9 +28,7 @@ class LevelOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
):
self._logger.debug(__name__, f"Module {type(self)} started")
server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}")
if not FeatureFlagsSettings.get_flag_from_dict(
server_config.feature_flags, FeatureFlagsEnum.achievements_module
):
if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.level_module):
return
await self._level.check_level(member)