support #381

Merged
edraft merged 31 commits from support into master 2023-09-28 20:03:32 +02:00
4 changed files with 70 additions and 22 deletions
Showing only changes of commit 378d2c3dc9 - Show all commits

View File

@ -4,6 +4,7 @@ from datetime import datetime
from cpl_core.configuration import ConfigurationModelABC
from cpl_core.database import TableABC
from cpl_query.extension import List
from discord import Guild
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_data.model.server import Server
@ -59,6 +60,29 @@ class ServerConfig(TableABC, ConfigurationModelABC):
self._created_at = created_at if created_at is not None else self._created_at
self._modified_at = modified_at if modified_at is not None else self._modified_at
@staticmethod
def new(guild: Guild, server: Server) -> "ServerConfig":
return ServerConfig(
6,
guild.system_channel.id,
6,
1,
1,
20,
10,
10,
10,
guild.system_channel.id,
guild.system_channel.id,
guild.system_channel.id,
guild.system_channel.id,
guild.default_role.id,
{},
server,
List(int),
List(int),
)
@property
def id(self) -> int:
return self._id

View File

@ -34,31 +34,12 @@ class ServerConfigSeeder(DataSeederABC):
if self._server_config.does_server_config_exists(server.id):
continue
config = ServerConfig(
6,
guild.system_channel.id,
6,
1,
1,
20,
10,
10,
10,
guild.system_channel.id,
guild.system_channel.id,
guild.system_channel.id,
guild.system_channel.id,
guild.default_role.id,
{},
server,
[],
[],
)
config = ServerConfig.new(guild, server)
self._server_config.add_server_config(config)
self._db.save_changes()
self._logger.debug(__name__, "Seeded technician config")
self._logger.debug(__name__, "Seeded server config")
except Exception as e:
self._logger.error(__name__, f"Seeding technician config failed", e)
self._logger.error(__name__, f"Seeding server config failed", e)

View File

@ -21,6 +21,7 @@ from modules.base.command.unregister_group import UnregisterGroup
from modules.base.command.user_group import UserGroup
from modules.base.events.base_on_command_error_event import BaseOnCommandErrorEvent
from modules.base.events.base_on_command_event import BaseOnCommandEvent
from modules.base.events.base_on_guild_join_event import BaseOnGuildJoinEvent
from modules.base.events.base_on_member_join_event import BaseOnMemberJoinEvent
from modules.base.events.base_on_member_remove_event import BaseOnMemberRemoveEvent
from modules.base.events.base_on_message_delete_event import BaseOnMessageDeleteEvent
@ -103,3 +104,7 @@ class BaseModule(ModuleABC):
DiscordEventTypesEnum.on_scheduled_event_update.value,
BaseOnScheduledEventUpdateEvent,
)
self._dc.add_event(
DiscordEventTypesEnum.on_guild_join.value,
BaseOnGuildJoinEvent,
)

View File

@ -0,0 +1,38 @@
from cpl_core.database.context import DatabaseContextABC
from cpl_core.logging import LoggerABC
from cpl_discord.events import OnGuildJoinABC
from cpl_discord.service import DiscordBotServiceABC
from discord import Guild
from bot_data.abc.server_config_repository_abc import ServerConfigRepositoryABC
from bot_data.abc.server_repository_abc import ServerRepositoryABC
from bot_data.model.server import Server
from bot_data.service.seeder_service import SeederService
class BaseOnGuildJoinEvent(OnGuildJoinABC):
def __init__(
self,
logger: LoggerABC,
bot: DiscordBotServiceABC,
servers: ServerRepositoryABC,
server_config: ServerConfigRepositoryABC,
db: DatabaseContextABC,
seeder: SeederService,
):
OnGuildJoinABC.__init__(self)
self._logger = logger
self._bot = bot
self._servers = servers
self._server_config = server_config
self._db = db
self._seeder = seeder
async def on_guild_join(self, guild: Guild):
if self._servers.find_server_by_discord_id(guild.id) is None:
self._servers.add_server(Server(guild.id))
self._db.save_changes()
await self._seeder.seed()
self._logger.debug(__name__, "Seeded technician config")