0.4 - Befehlsstruktur #37
@ -11,7 +11,8 @@
|
||||
"level-generator": "tools/level_generator/level-generator.json",
|
||||
"ontime-calculator": "tools/ontime_calculator/ontime-calculator.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": {
|
||||
"build-start": "cd src/gismo_cli; echo 'gismo-cli:'; cpl build; cd ../gismo; echo 'gismo:'; cpl build; cd ../../dist/gismo/build/gismo; bash gismo",
|
||||
|
@ -9,12 +9,6 @@
|
||||
"AFKChannelIds": [
|
||||
910199452915093593,
|
||||
910199452915093594
|
||||
],
|
||||
"AdminRoleIds": [
|
||||
925072155203477584
|
||||
],
|
||||
"ModeratorRoleIds": [
|
||||
925072209884635167
|
||||
]
|
||||
}
|
||||
}
|
10
src/gismo/config/permission.json
Normal file
10
src/gismo/config/permission.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"910199451145076828": {
|
||||
"AdminRoleIds": [
|
||||
925072155203477584
|
||||
],
|
||||
"ModeratorRoleIds": [
|
||||
925072209884635167
|
||||
]
|
||||
}
|
||||
}
|
@ -37,6 +37,9 @@ from gismo_data.service.user_repository_service import UserRepositoryService
|
||||
from modules.base.base import Base
|
||||
from modules.boot_log.boot_log import BootLog
|
||||
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_service_abc import ModuleServiceABC
|
||||
from modules_core.service.module_service import ModuleService
|
||||
@ -73,7 +76,7 @@ class Startup(StartupABC):
|
||||
services.add_singleton(BotServiceABC, BotService)
|
||||
services.add_transient(MessageServiceABC, MessageService)
|
||||
|
||||
# services
|
||||
# general services
|
||||
services.add_transient(MigrationService)
|
||||
|
||||
# data services
|
||||
@ -85,10 +88,14 @@ class Startup(StartupABC):
|
||||
services.add_transient(UserJoinedVoiceChannelRepositoryABC, UserJoinedVoiceChannelRepositoryService)
|
||||
|
||||
# modules
|
||||
services.add_transient(ModuleABC, Permission)
|
||||
services.add_transient(ModuleABC, Database)
|
||||
services.add_transient(ModuleABC, Base)
|
||||
services.add_transient(ModuleABC, BootLog)
|
||||
|
||||
# permission module services
|
||||
services.add_transient(PermissionServiceABC, PermissionService)
|
||||
|
||||
# migrations
|
||||
services.add_transient(MigrationABC, InitialMigration)
|
||||
services.add_transient(MigrationABC, Migration_0_3)
|
||||
|
@ -0,0 +1 @@
|
||||
# imports
|
@ -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]):
|
||||
self._logger.debug(__name__, f'Check if user exists {member}')
|
||||
# todo: user permission service
|
||||
settings: BaseSettings = self._get_config()
|
||||
await self._messenger.send_dm_message(settings.welcome_message.format(member.guild.name), member)
|
||||
|
||||
|
@ -16,8 +16,6 @@ class BaseSettings(ConfigurationModelABC):
|
||||
self._xp_per_message: int = 0
|
||||
self._xp_per_ontime_hour: int = 0
|
||||
self._afk_channel_ids: list[int] = []
|
||||
self._admin_roles: list[int] = []
|
||||
self._moderator_roles: list[int] = []
|
||||
|
||||
@property
|
||||
def welcome_message(self) -> str:
|
||||
@ -47,14 +45,6 @@ class BaseSettings(ConfigurationModelABC):
|
||||
def afk_channel_ids(self) -> list[int]:
|
||||
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):
|
||||
try:
|
||||
self._welcome_message = settings['WelcomeMessage']
|
||||
@ -65,12 +55,6 @@ class BaseSettings(ConfigurationModelABC):
|
||||
self._xp_per_ontime_hour = int(settings['XpPerOntimeHour'])
|
||||
for id in settings['AFKChannelIds']:
|
||||
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:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||
|
1
src/modules/permission/__init__.py
Normal file
1
src/modules/permission/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# imports
|
1
src/modules/permission/abc/__init__.py
Normal file
1
src/modules/permission/abc/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# imports
|
7
src/modules/permission/abc/permission_service_abc.py
Normal file
7
src/modules/permission/abc/permission_service_abc.py
Normal file
@ -0,0 +1,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class PermissionServiceABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
33
src/modules/permission/configuration/permission_settings.py
Normal file
33
src/modules/permission/configuration/permission_settings.py
Normal 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()}')
|
43
src/modules/permission/permission.json
Normal file
43
src/modules/permission/permission.json
Normal 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": []
|
||||
}
|
||||
}
|
41
src/modules/permission/permission.py
Normal file
41
src/modules/permission/permission.py
Normal 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')
|
1
src/modules/permission/service/__init__.py
Normal file
1
src/modules/permission/service/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# imports
|
4
src/modules/permission/service/permission_service.py
Normal file
4
src/modules/permission/service/permission_service.py
Normal file
@ -0,0 +1,4 @@
|
||||
class PermissionService:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
Reference in New Issue
Block a user