0.4 - Befehlsstruktur #37

Merged
edraft merged 10 commits from 0.4 into Alpha 2021-12-31 12:10:05 +01:00
15 changed files with 153 additions and 24 deletions
Showing only changes of commit ff247bcec3 - Show all commits

View File

@ -11,7 +11,8 @@
"level-generator": "tools/level_generator/level-generator.json", "level-generator": "tools/level_generator/level-generator.json",
"ontime-calculator": "tools/ontime_calculator/ontime-calculator.json", "ontime-calculator": "tools/ontime_calculator/ontime-calculator.json",
"database": "src/modules/database/database.json", "database": "src/modules/database/database.json",
"base": "src/modules/base/base.json" "base": "src/modules/base/base.json",
"permission": "src/modules/permission/permission.json"
}, },
"Scripts": { "Scripts": {
"build-start": "cd src/gismo_cli; echo 'gismo-cli:'; cpl build; cd ../gismo; echo 'gismo:'; cpl build; cd ../../dist/gismo/build/gismo; bash gismo", "build-start": "cd src/gismo_cli; echo 'gismo-cli:'; cpl build; cd ../gismo; echo 'gismo:'; cpl build; cd ../../dist/gismo/build/gismo; bash gismo",

View File

@ -9,12 +9,6 @@
"AFKChannelIds": [ "AFKChannelIds": [
910199452915093593, 910199452915093593,
910199452915093594 910199452915093594
],
"AdminRoleIds": [
925072155203477584
],
"ModeratorRoleIds": [
925072209884635167
] ]
} }
} }

View File

@ -0,0 +1,10 @@
{
"910199451145076828": {
"AdminRoleIds": [
925072155203477584
],
"ModeratorRoleIds": [
925072209884635167
]
}
}

View File

@ -37,6 +37,9 @@ from gismo_data.service.user_repository_service import UserRepositoryService
from modules.base.base import Base from modules.base.base import Base
from modules.boot_log.boot_log import BootLog from modules.boot_log.boot_log import BootLog
from modules.database.database import Database from modules.database.database import Database
from modules.permission.abc.permission_service_abc import PermissionServiceABC
from modules.permission.permission import Permission
from modules.permission.service.permission_service import PermissionService
from modules_core.abc.module_abc import ModuleABC from modules_core.abc.module_abc import ModuleABC
from modules_core.abc.module_service_abc import ModuleServiceABC from modules_core.abc.module_service_abc import ModuleServiceABC
from modules_core.service.module_service import ModuleService from modules_core.service.module_service import ModuleService
@ -73,7 +76,7 @@ class Startup(StartupABC):
services.add_singleton(BotServiceABC, BotService) services.add_singleton(BotServiceABC, BotService)
services.add_transient(MessageServiceABC, MessageService) services.add_transient(MessageServiceABC, MessageService)
# services # general services
services.add_transient(MigrationService) services.add_transient(MigrationService)
# data services # data services
@ -85,10 +88,14 @@ class Startup(StartupABC):
services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService) services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService)
# modules # modules
services.add_transient(ModuleABC, Permission)
services.add_transient(ModuleABC, Database) services.add_transient(ModuleABC, Database)
services.add_transient(ModuleABC, Base) services.add_transient(ModuleABC, Base)
services.add_transient(ModuleABC, BootLog) services.add_transient(ModuleABC, BootLog)
# permission module services
services.add_transient(PermissionServiceABC, PermissionService)
# migrations # migrations
services.add_transient(MigrationABC, InitialMigration) services.add_transient(MigrationABC, InitialMigration)
services.add_transient(MigrationABC, Migration_0_3) services.add_transient(MigrationABC, Migration_0_3)

View File

@ -0,0 +1 @@
# imports

View File

@ -100,6 +100,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS
async def _add_if_not_exists_user(self, member: Union[discord.User, discord.Member]): async def _add_if_not_exists_user(self, member: Union[discord.User, discord.Member]):
self._logger.debug(__name__, f'Check if user exists {member}') self._logger.debug(__name__, f'Check if user exists {member}')
# todo: user permission service
settings: BaseSettings = self._get_config() settings: BaseSettings = self._get_config()
await self._messenger.send_dm_message(settings.welcome_message.format(member.guild.name), member) await self._messenger.send_dm_message(settings.welcome_message.format(member.guild.name), member)

View File

@ -16,8 +16,6 @@ class BaseSettings(ConfigurationModelABC):
self._xp_per_message: int = 0 self._xp_per_message: int = 0
self._xp_per_ontime_hour: int = 0 self._xp_per_ontime_hour: int = 0
self._afk_channel_ids: list[int] = [] self._afk_channel_ids: list[int] = []
self._admin_roles: list[int] = []
self._moderator_roles: list[int] = []
@property @property
def welcome_message(self) -> str: def welcome_message(self) -> str:
@ -47,14 +45,6 @@ class BaseSettings(ConfigurationModelABC):
def afk_channel_ids(self) -> list[int]: def afk_channel_ids(self) -> list[int]:
return self._afk_channel_ids return self._afk_channel_ids
@property
def admin_roles(self) -> list[int]:
return self._admin_roles
@property
def moderator_roles(self) -> list[int]:
return self._moderator_roles
def from_dict(self, settings: dict): def from_dict(self, settings: dict):
try: try:
self._welcome_message = settings['WelcomeMessage'] self._welcome_message = settings['WelcomeMessage']
@ -65,12 +55,6 @@ class BaseSettings(ConfigurationModelABC):
self._xp_per_ontime_hour = int(settings['XpPerOntimeHour']) self._xp_per_ontime_hour = int(settings['XpPerOntimeHour'])
for id in settings['AFKChannelIds']: for id in settings['AFKChannelIds']:
self._afk_channel_ids.append(int(id)) self._afk_channel_ids.append(int(id))
for id in settings['AdminRoleIds']:
self._admin_roles.append(int(id))
for id in settings['ModeratorRoleIds']:
self._moderator_roles.append(int(id))
except Exception as e: except Exception as e:
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings') Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,7 @@
from abc import ABC, abstractmethod
class PermissionServiceABC(ABC):
@abstractmethod
def __init__(self): pass

View File

@ -0,0 +1,33 @@
import traceback
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_core.console import Console
class PermissionSettings(ConfigurationModelABC):
def __init__(self):
ConfigurationModelABC.__init__(self)
self._admin_roles: list[int] = []
self._moderator_roles: list[int] = []
@property
def admin_roles(self) -> list[int]:
return self._admin_roles
@property
def moderator_roles(self) -> list[int]:
return self._moderator_roles
def from_dict(self, settings: dict):
try:
for id in settings['AdminRoleIds']:
self._admin_roles.append(int(id))
for id in settings['ModeratorRoleIds']:
self._moderator_roles.append(int(id))
except Exception as e:
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')

View File

@ -0,0 +1,43 @@
{
"ProjectSettings": {
"Name": "modules/permission",
"Version": {
"Major": "0",
"Minor": "0",
"Micro": "0"
},
"Author": "",
"AuthorEmail": "",
"Description": "",
"LongDescription": "",
"URL": "",
"CopyrightDate": "",
"CopyrightName": "",
"LicenseName": "",
"LicenseDescription": "",
"Dependencies": [
"sh_cpl-core>=2021.11.0.post1"
],
"PythonVersion": ">=3.9.2",
"PythonPath": {
"linux": ""
},
"Classifiers": []
},
"BuildSettings": {
"ProjectType": "library",
"SourcePath": "",
"OutputPath": "../../dist",
"Main": "modules/permission.main",
"EntryPoint": "modules/permission",
"IncludePackageData": false,
"Included": [],
"Excluded": [
"*/__pycache__",
"*/logs",
"*/tests"
],
"PackageData": {},
"ProjectReferences": []
}
}

View File

@ -0,0 +1,41 @@
from ctypes import Union
from datetime import datetime
import discord
from cpl_core.configuration import ConfigurationABC
from cpl_core.database.context import DatabaseContextABC
from cpl_core.logging import LoggerABC
from gismo_core.abc.bot_service_abc import BotServiceABC
from gismo_core.configuration.server_settings import ServerSettings
from gismo_data.abc.client_repository_abc import ClientRepositoryABC
from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC
from gismo_data.abc.user_joined_server_repository_abc import \
UserJoinedServerRepositoryABC
from gismo_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC
from gismo_data.abc.user_repository_abc import UserRepositoryABC
from gismo_data.model.client import Client
from gismo_data.model.known_user import KnownUser
from gismo_data.model.server import Server
from gismo_data.model.user import User
from gismo_data.model.user_joined_server import UserJoinedServer
from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel
from gismo_data.service.user_repository_service import ServerRepositoryABC
from modules.permission.configuration.permission_settings import PermissionSettings
from modules_core.abc.events.on_ready_abc import OnReadyABC
from modules_core.abc.module_abc import ModuleABC
class Permission(ModuleABC):
def __init__(
self,
logger: LoggerABC,
):
self._logger = logger
ModuleABC.__init__(
self,
{ OnReadyABC: 0 },
PermissionSettings
)
self._logger.trace(__name__, f'Module {type(self)} loaded')

View File

@ -0,0 +1 @@
# imports

View File

@ -0,0 +1,4 @@
class PermissionService:
def __init__(self):
pass