forked from sh-edraft.de/sh_discord_bot
[WIP] Added basic commands & functionality of Gismo@0.4.10
This commit is contained in:
@@ -1 +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__ = 'bot'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2022 sh-edraft.de'
|
||||
__version__ = '1.0.0.dev1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='1', minor='0', micro='0.dev1')
|
||||
|
@@ -1,4 +1,6 @@
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from typing import Optional, Type
|
||||
|
||||
from cpl_core.configuration import ConfigurationABC, ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
@@ -7,6 +9,15 @@ from cpl_discord.configuration import DiscordBotSettings
|
||||
from cpl_discord.service import DiscordBotServiceABC, DiscordBotService
|
||||
from cpl_translation import TranslatePipe, TranslationServiceABC, TranslationSettings
|
||||
|
||||
from bot_core.configuration.bot_settings import BotSettings
|
||||
from bot_core.configuration.server_settings import ServerSettings
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
from modules.base.configuration.base_settings import BaseSettings
|
||||
from modules.boot_log.configuration.boot_log_server_settings import BootLogServerSettings
|
||||
from modules.boot_log.configuration.boot_log_settings import BootLogSettings
|
||||
from modules.permission.configuration.permission_server_settings import PermissionServerSettings
|
||||
from modules.permission.configuration.permission_settings import PermissionSettings
|
||||
|
||||
|
||||
class Application(DiscordBotApplicationABC):
|
||||
|
||||
@@ -22,8 +33,21 @@ class Application(DiscordBotApplicationABC):
|
||||
self._translation: TranslationServiceABC = services.get_service(TranslationServiceABC)
|
||||
self._translate: TranslatePipe = services.get_service(TranslatePipe)
|
||||
|
||||
def _configure_settings_with_servers(self, settings: Type, server_settings: Type):
|
||||
settings: Optional[settings] = self._configuration.get_configuration(settings)
|
||||
if settings is None:
|
||||
return
|
||||
|
||||
for server in settings.servers:
|
||||
self._logger.trace(__name__, f'Saved config: {type(server).__name__}_{server.id}')
|
||||
self._configuration.add_configuration(f'{type(server).__name__}_{server.id}', server)
|
||||
|
||||
async def configure(self):
|
||||
self._translation.load_by_settings(self._configuration.get_configuration(TranslationSettings))
|
||||
self._configure_settings_with_servers(BotSettings, ServerSettings)
|
||||
self._configure_settings_with_servers(BaseSettings, BaseServerSettings)
|
||||
self._configure_settings_with_servers(BootLogSettings, BootLogServerSettings)
|
||||
self._configure_settings_with_servers(PermissionSettings, PermissionServerSettings)
|
||||
|
||||
async def main(self):
|
||||
try:
|
||||
|
@@ -17,7 +17,7 @@
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.7.0.post1",
|
||||
"cpl-translation==2022.7.0.post1",
|
||||
"cpl-translation==2022.7.0.post2",
|
||||
"cpl-query==2022.7.0",
|
||||
"cpl-discord==2022.7.0.post1"
|
||||
],
|
||||
|
@@ -20,14 +20,5 @@
|
||||
"DiscordBot": {
|
||||
"Token": "OTA5ODc4NDcyNzExNzU3ODQ1.YZKsXA.8p-g1c37EBZzYYW09Fvr7egQzhE",
|
||||
"Prefix": "!kd "
|
||||
},
|
||||
"Bot": {
|
||||
"Servers": [
|
||||
{
|
||||
"Id": "910199451145076828",
|
||||
"MessageDeleteTimer": 2,
|
||||
"BotHasNoPermissionMessage": "Ich habe keine Berechtigungen :("
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@@ -1,31 +1,58 @@
|
||||
{
|
||||
"LoggingSettings": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_dev.log",
|
||||
"ConsoleLogLevel": "TRACE",
|
||||
"FileLogLevel": "TRACE"
|
||||
"LoggingSettings": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_dev.log",
|
||||
"ConsoleLogLevel": "TRACE",
|
||||
"FileLogLevel": "TRACE"
|
||||
},
|
||||
"DatabaseSettings": {
|
||||
"Host": "localhost",
|
||||
"User": "kd_kdb",
|
||||
"Password": "VGpZcihrb0N2T2MyZUlURQ==",
|
||||
"Database": "keksdose_bot_dev",
|
||||
"Charset": "utf8mb4",
|
||||
"UseUnicode": "true",
|
||||
"Buffered": "true",
|
||||
"AuthPlugin": "mysql_native_password"
|
||||
},
|
||||
"DiscordBot": {
|
||||
"Token": "OTExNTc0NDQyMzMxNzM0MDI2.YZjX2w.k7N2qTkvkDD7j9bT4Nrdl4qBHlI",
|
||||
"Prefix": "!kde "
|
||||
},
|
||||
"Bot": {
|
||||
"511824600884051979": {
|
||||
"MessageDeleteTimer": 2
|
||||
},
|
||||
"DatabaseSettings": {
|
||||
"Host": "localhost",
|
||||
"User": "sh_gismo",
|
||||
"Password": "c2hfZ2lzbW8=",
|
||||
"Database": "sh_gismo_dev",
|
||||
"Charset": "utf8mb4",
|
||||
"UseUnicode": "true",
|
||||
"Buffered": "true",
|
||||
"AuthPlugin": "mysql_native_password"
|
||||
},
|
||||
"DiscordBot": {
|
||||
"Token": "OTExNTc0NDQyMzMxNzM0MDI2.YZjX2w.k7N2qTkvkDD7j9bT4Nrdl4qBHlI",
|
||||
"Prefix": "!kde "
|
||||
},
|
||||
"Bot": {
|
||||
"Servers": [
|
||||
{
|
||||
"Id": "910199451145076828",
|
||||
"MessageDeleteTimer": 2,
|
||||
"BotHasNoPermissionMessage": "Ich habe keine Berechtigungen :("
|
||||
}
|
||||
]
|
||||
"910199451145076828": {
|
||||
"MessageDeleteTimer": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
"Base": {
|
||||
"910199451145076828": {
|
||||
"MaxVoiceStateHours": 24,
|
||||
"XpPerMessage": 2,
|
||||
"XpPerOntimeHour": 4,
|
||||
"AFKChannelIds": [
|
||||
910199452915093593,
|
||||
910199452915093594
|
||||
],
|
||||
"AFKCommandChannelId": 910199452915093594,
|
||||
"HelpCommandReferenceUrl": "https://git.sh-edraft.de/sh-edraft.de/sh_gismo/wiki/Befehle"
|
||||
}
|
||||
},
|
||||
"BootLog": {
|
||||
"910199451145076828": {
|
||||
"LoginMessageChannelId": "910199452915093588"
|
||||
}
|
||||
},
|
||||
"Permission": {
|
||||
"910199451145076828": {
|
||||
"AdminRoleIds": [
|
||||
925072155203477584
|
||||
],
|
||||
"ModeratorRoleIds": [
|
||||
925072209884635167
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,15 +19,5 @@
|
||||
},
|
||||
"Discord": {
|
||||
"Token": "OTEwMjAxNjA1NDkwNjEwMjA3.YZPZTQ.lUj2Bs5pQAv4AJ_tb_mHMTpIRls"
|
||||
},
|
||||
"Bot": {
|
||||
"Prefix": "!kt ",
|
||||
"Servers": [
|
||||
{
|
||||
"Id": "910199451145076828",
|
||||
"MessageDeleteTimer": 2,
|
||||
"BotHasNoPermissionMessage": "Ich habe keine Berechtigungen :("
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@@ -5,6 +5,10 @@ from cpl_core.application import ApplicationBuilder
|
||||
|
||||
from bot.application import Application
|
||||
from bot.startup import Startup
|
||||
from bot.startup_discord_extension import StartupDiscordExtension
|
||||
from bot.startup_migration_extension import StartupMigrationExtension
|
||||
from modules.boot_log.boot_log_extension import BootLogExtension
|
||||
from modules.database.database_extension import DatabaseExtension
|
||||
|
||||
|
||||
class Main:
|
||||
@@ -14,6 +18,10 @@ class Main:
|
||||
|
||||
async def main(self):
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app_builder.use_extension(StartupDiscordExtension)
|
||||
app_builder.use_extension(StartupMigrationExtension)
|
||||
app_builder.use_extension(BootLogExtension)
|
||||
app_builder.use_extension(DatabaseExtension)
|
||||
app_builder.use_startup(Startup)
|
||||
self._app: Application = await app_builder.build_async()
|
||||
await self._app.run_async()
|
||||
|
@@ -4,9 +4,31 @@ from typing import Optional
|
||||
|
||||
from cpl_core.application import StartupABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.database import DatabaseSettings
|
||||
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironment
|
||||
from cpl_discord import get_discord_collection
|
||||
|
||||
from bot_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.service.client_utils_service import ClientUtilsService
|
||||
from bot_core.service.message_service import MessageService
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.db_context import DBContext
|
||||
from bot_data.service.client_repository_service import ClientRepositoryService
|
||||
from bot_data.service.known_user_repository_service import KnownUserRepositoryService
|
||||
from bot_data.service.server_repository_service import ServerRepositoryService
|
||||
from bot_data.service.user_joined_server_repository_service import UserJoinedServerRepositoryService
|
||||
from bot_data.service.user_joined_voice_channel_service import UserJoinedVoiceChannelRepositoryService
|
||||
from bot_data.service.user_repository_service import UserRepositoryService
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
from modules.base.service.base_helper_service import BaseHelperService
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
from modules.permission.service.permission_service import PermissionService
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
@@ -34,7 +56,23 @@ class Startup(StartupABC):
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
services.add_logging()
|
||||
services.add_translation()
|
||||
services.add_discord()
|
||||
discord_collection = get_discord_collection(services)
|
||||
|
||||
services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings))
|
||||
|
||||
# general services
|
||||
services.add_transient(BaseHelperABC, BaseHelperService)
|
||||
services.add_transient(MessageServiceABC, MessageService)
|
||||
services.add_transient(ClientUtilsServiceABC, ClientUtilsService)
|
||||
|
||||
# module services
|
||||
services.add_singleton(PermissionServiceABC, PermissionService)
|
||||
|
||||
# data services
|
||||
services.add_transient(ServerRepositoryABC, ServerRepositoryService)
|
||||
services.add_transient(UserRepositoryABC, UserRepositoryService)
|
||||
services.add_transient(ClientRepositoryABC, ClientRepositoryService)
|
||||
services.add_transient(KnownUserRepositoryABC, KnownUserRepositoryService)
|
||||
services.add_transient(UserJoinedServerRepositoryABC, UserJoinedServerRepositoryService)
|
||||
services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService)
|
||||
|
||||
return services.build_service_provider()
|
||||
|
52
src/bot/startup_discord_extension.py
Normal file
52
src/bot/startup_discord_extension.py
Normal file
@@ -0,0 +1,52 @@
|
||||
from cpl_core.application import StartupExtensionABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_discord import get_discord_collection
|
||||
from cpl_discord.discord_event_types_enum import DiscordEventTypesEnum
|
||||
|
||||
from modules.base.command.afk_command import AFKCommand
|
||||
from modules.base.command.help_command import HelpCommand
|
||||
from modules.base.command.ping_command import PingCommand
|
||||
from modules.base.command.purge_command import PurgeCommand
|
||||
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_event import BaseOnMessageEvent
|
||||
from modules.base.events.base_on_voice_state_update_event import BaseOnVoiceStateUpdateEvent
|
||||
from modules.boot_log.boot_log_on_ready_event import BootLogOnReadyEvent
|
||||
from modules.database.database_on_ready_event import DatabaseOnReadyEvent
|
||||
from modules.permission.events.permission_on_member_update_event import PermissionOnMemberUpdateEvent
|
||||
from modules.permission.events.permission_on_ready_event import PermissionOnReadyEvent
|
||||
|
||||
|
||||
class StartupDiscordExtension(StartupExtensionABC):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
pass
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services.add_discord()
|
||||
dc = get_discord_collection(services)
|
||||
""" commands """
|
||||
dc.add_command(AFKCommand)
|
||||
dc.add_command(HelpCommand)
|
||||
dc.add_command(PingCommand)
|
||||
dc.add_command(PurgeCommand)
|
||||
""" events """
|
||||
# on_member_join
|
||||
dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberJoinEvent)
|
||||
# on_member_remove
|
||||
dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnMemberRemoveEvent)
|
||||
# on_member_update
|
||||
dc.add_event(DiscordEventTypesEnum.on_member_update.value, PermissionOnMemberUpdateEvent)
|
||||
# on_message
|
||||
dc.add_event(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent)
|
||||
# on_voice_state_update
|
||||
dc.add_event(DiscordEventTypesEnum.on_member_join.value, BaseOnVoiceStateUpdateEvent)
|
||||
# on_ready
|
||||
dc.add_event(DiscordEventTypesEnum.on_ready.value, DatabaseOnReadyEvent)
|
||||
dc.add_event(DiscordEventTypesEnum.on_ready.value, PermissionOnReadyEvent)
|
||||
dc.add_event(DiscordEventTypesEnum.on_ready.value, BootLogOnReadyEvent) # has to be last
|
21
src/bot/startup_migration_extension.py
Normal file
21
src/bot/startup_migration_extension.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from cpl_core.application import StartupExtensionABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.migration.initial_migration import InitialMigration
|
||||
from bot_data.service.migration_service import MigrationService
|
||||
|
||||
|
||||
class StartupMigrationExtension(StartupExtensionABC):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
pass
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services.add_transient(MigrationService)
|
||||
services.add_transient(MigrationABC, InitialMigration)
|
@@ -1,8 +1,23 @@
|
||||
{
|
||||
"common": {
|
||||
"hello-world": "Hallo Welt"
|
||||
"hello_world": "Hallo Welt",
|
||||
"bot_has_no_permission_message": "Ey!!!\nWas soll das?\nIch habe keine Berechtigungen :(\nScheiß System...",
|
||||
"no_permission_message": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯"
|
||||
},
|
||||
"commands": {
|
||||
|
||||
"modules": {
|
||||
"base": {
|
||||
"welcome_message": "Hello There!\nIch bin Gismo und heiße dich bei {} herzlichst willkommen!",
|
||||
"welcome_message_for_team": "{} hat gerade das Irrenhaus betreten.",
|
||||
"goodbye_message": "Schade das du uns so schnell verlässt :(",
|
||||
"purge_message": "Na gut..., ich lösche alle Nachrichten wenns sein muss.",
|
||||
"afk_command_channel_missing_message": "Zu unfähig einem Sprachkanal beizutreten?",
|
||||
"afk_command_move_message": "Ich verschiebe dich ja schon... (◔_◔)",
|
||||
"pong": "Pong"
|
||||
},
|
||||
"boot_log": {
|
||||
"login_message": "Ich bin on the line :D\nDer Scheiß hat {} Sekunden gedauert"
|
||||
},
|
||||
"database": {},
|
||||
"permission": {}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user