diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml
new file mode 100644
index 0000000..5f1ab1c
--- /dev/null
+++ b/.idea/dbnavigator.xml
@@ -0,0 +1,554 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..1a4fced
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..453e776
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..899c89c
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/sh_gismo.iml b/.idea/sh_gismo.iml
new file mode 100644
index 0000000..755c55c
--- /dev/null
+++ b/.idea/sh_gismo.iml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/gismo/main.py b/src/gismo/main.py
index af10e51..e5363d8 100644
--- a/src/gismo/main.py
+++ b/src/gismo/main.py
@@ -19,7 +19,7 @@ class Main:
app_builder.use_extension(DatabaseExtension)
app_builder.use_extension(BootLogExtension)
app_builder.use_startup(Startup)
- self._gismo: Gismo = await app_builder.build_async()
+ self._gismo = await app_builder.build_async()
await self._gismo.run_async()
async def stop(self):
diff --git a/src/gismo/startup.py b/src/gismo/startup.py
index 491dfae..a9378a2 100644
--- a/src/gismo/startup.py
+++ b/src/gismo/startup.py
@@ -52,27 +52,27 @@ class Startup(StartupABC):
def __init__(self):
StartupABC.__init__(self)
self._start_time = datetime.now()
-
+
self._config: Optional[ConfigurationABC] = None
async def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
environment.set_working_directory(os.path.dirname(os.path.realpath(__file__)))
configuration.add_environment_variables('GISMO_')
-
+
configuration.add_json_file(f'config/appsettings.json', optional=False)
configuration.add_json_file(f'config/appsettings.{environment.environment_name}.json', optional=True)
configuration.add_json_file(f'config/appsettings.{environment.host_name}.json', optional=True)
-
- configuration.add_configuration('Startup_StartTime', self._start_time)
-
+
+ configuration.add_configuration('Startup_StartTime', str(self._start_time))
+
self._config = configuration
return configuration
async def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
services.add_logging()
-
+
services.add_db_context(DBContext, self._config.get_configuration(DatabaseSettings))
-
+
# general services
services.add_singleton(ModuleServiceABC, ModuleService)
services.add_singleton(BotServiceABC, BotService)
@@ -89,7 +89,7 @@ class Startup(StartupABC):
# module services
services.add_singleton(PermissionServiceABC, PermissionService)
-
+
# commands
services.add_singleton(CommandABC, BaseCommandService)
@@ -103,12 +103,12 @@ class Startup(StartupABC):
services.add_transient(MigrationABC, InitialMigration)
services.add_transient(MigrationABC, Migration_0_3)
services.add_transient(MigrationABC, Migration_0_3_1)
-
+
provider: ServiceProviderABC = services.build_service_provider()
-
+
startup_init_time = round((datetime.now() - self._config.get_configuration('Startup_StartTime')).total_seconds(), 2)
- self._config.add_configuration('Startup_InitTime', startup_init_time)
+ self._config.add_configuration('Startup_InitTime', str(startup_init_time))
logger: LoggerABC = provider.get_service(LoggerABC)
logger.debug(__name__, f'Startup Init time: {startup_init_time}s')
-
+
return provider
diff --git a/src/gismo_core/service/message_service.py b/src/gismo_core/service/message_service.py
index d31a733..75df1fd 100644
--- a/src/gismo_core/service/message_service.py
+++ b/src/gismo_core/service/message_service.py
@@ -70,7 +70,7 @@ class MessageService(MessageServiceABC):
self._db.save_changes()
self._logger.info(__name__, f'Sent message to user {receiver.id}')
- async def send_ctx_msg(self, ctx: Context, message: Union[str, discord.File]):
+ async def send_ctx_msg(self, ctx: Context, message: str, file: discord.File = None):
if ctx is None:
self._logger.warn(__name__, 'Message context is empty')
self._logger.debug(__name__, f'Message: {message}')
diff --git a/src/gismo_core/service/module_service.py b/src/gismo_core/service/module_service.py
index cb870df..aef87ee 100644
--- a/src/gismo_core/service/module_service.py
+++ b/src/gismo_core/service/module_service.py
@@ -9,7 +9,7 @@ from cpl_core.dependency_injection import ServiceProviderABC
from cpl_core.environment import ApplicationEnvironmentABC
from cpl_core.logging import LoggerABC
from cpl_core.utils import String
-from cpl_query.extension import List
+from cpl_query.extension import List, OrderedIterableABC
from discord.ext import commands
from gismo_core.abc.events.on_bulk_message_delete_abc import OnBulkMessageDeleteABC
from gismo_core.abc.events.on_connect_abc import OnConnectABC
@@ -72,7 +72,7 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=CommandsMeta):
self._modules: List[ModuleABC] = List()
self._modules.extend(ModuleABC.__subclasses__())
- def _get_modules(self, t: type) -> List[ModuleABC]:
+ def _get_modules(self, t: type) -> OrderedIterableABC:
module_types = self._modules.where(lambda m: issubclass(m, t))
modules = List(t)
for module_type in module_types:
@@ -81,14 +81,14 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=CommandsMeta):
self._logger.warn(__name__, f'Module {module_type} not found in services!')
break
- if (module.settings_type is not None):
+ if module.settings_type is not None:
with open(f'config/{String.convert_to_snake_case(type(module).__name__).lower()}.json', encoding='utf-8') as cfg:
json_cfg = json.load(cfg)
- for id in json_cfg:
+ for index in json_cfg:
settings: ConfigurationModelABC = module.settings_type()
- settings.from_dict(json_cfg[id])
- self._config.add_configuration(f'{type(module).__name__}_{id}', settings)
- self._logger.debug(__name__, f'Added config: {type(module).__name__}_{id}')
+ settings.from_dict(json_cfg[index])
+ self._config.add_configuration(f'{type(module).__name__}_{index}', settings)
+ self._logger.debug(__name__, f'Added config: {type(module).__name__}_{index}')
modules.append(module)
diff --git a/src/gismo_data/abc/client_repository_abc.py b/src/gismo_data/abc/client_repository_abc.py
index 4c61661..6c6f56d 100644
--- a/src/gismo_data/abc/client_repository_abc.py
+++ b/src/gismo_data/abc/client_repository_abc.py
@@ -14,7 +14,7 @@ class ClientRepositoryABC(ABC):
def get_clients(self) -> List[Client]: pass
@abstractmethod
- def get_client_by_id(self, id: int) -> Client: pass
+ def get_client_by_id(self, client_id: int) -> Client: pass
@abstractmethod
def get_client_by_discord_id(self, discord_id: int) -> Client: pass
@@ -38,16 +38,16 @@ class ClientRepositoryABC(ABC):
def delete_client(self, client: Client): pass
@abstractmethod
- def apppend_sent_message_count(self, id: int, server_id: int, value: int): pass
+ def append_sent_message_count(self, client_id: int, server_id: int, value: int): pass
@abstractmethod
- def apppend_received_message_count(self, id: int, server_id: int, value: int): pass
+ def append_received_message_count(self, client_id: int, server_id: int, value: int): pass
@abstractmethod
- def apppend_deleted_message_count(self, id: int, server_id: int, value: int): pass
+ def append_deleted_message_count(self, client_id: int, server_id: int, value: int): pass
@abstractmethod
- def apppend_received_command_count(self, id: int, server_id: int, value: int): pass
+ def append_received_command_count(self, client_id: int, server_id: int, value: int): pass
@abstractmethod
- def apppend_moved_users_count(self, id: int, server_id: int, value: int): pass
+ def append_moved_users_count(self, client_id: int, server_id: int, value: int): pass
diff --git a/src/gismo_data/db_context.py b/src/gismo_data/db_context.py
index c45dafa..dc2fcb0 100644
--- a/src/gismo_data/db_context.py
+++ b/src/gismo_data/db_context.py
@@ -10,8 +10,7 @@ class DBContext(DatabaseContext):
self._logger = logger
DatabaseContext.__init__(self)
-
-
+
def connect(self, database_settings: DatabaseSettings):
try:
self._logger.debug(__name__, "Connecting to database")
diff --git a/src/gismo_data/migration/migration_0_3.py b/src/gismo_data/migration/migration_0_3.py
index 138de96..13c8512 100644
--- a/src/gismo_data/migration/migration_0_3.py
+++ b/src/gismo_data/migration/migration_0_3.py
@@ -3,6 +3,7 @@ from cpl_core.logging import LoggerABC
from gismo_data.abc.migration_abc import MigrationABC
from gismo_data.db_context import DBContext
+
class Migration_0_3(MigrationABC):
def __init__(self, logger: LoggerABC, db: DBContext):
diff --git a/src/gismo_data/migration/migration_0_3_1.py b/src/gismo_data/migration/migration_0_3_1.py
index 6102720..ac44a45 100644
--- a/src/gismo_data/migration/migration_0_3_1.py
+++ b/src/gismo_data/migration/migration_0_3_1.py
@@ -3,6 +3,7 @@ from cpl_core.logging import LoggerABC
from gismo_data.abc.migration_abc import MigrationABC
from gismo_data.db_context import DBContext
+
class Migration_0_3_1(MigrationABC):
def __init__(self, logger: LoggerABC, db: DBContext):
diff --git a/src/gismo_data/service/client_repository_service.py b/src/gismo_data/service/client_repository_service.py
index fc2b9e7..bbee523 100644
--- a/src/gismo_data/service/client_repository_service.py
+++ b/src/gismo_data/service/client_repository_service.py
@@ -37,9 +37,9 @@ class ClientRepositoryService(ClientRepositoryABC):
return clients
- def get_client_by_id(self, id: int) -> Client:
- self._logger.trace(__name__, f'Send SQL command: {Client.get_select_by_id_string(id)}')
- result = self._context.select(Client.get_select_by_id_string(id))
+ def get_client_by_id(self, client_id: int) -> Client:
+ self._logger.trace(__name__, f'Send SQL command: {Client.get_select_by_id_string(client_id)}')
+ result = self._context.select(Client.get_select_by_id_string(client_id))
return Client(
result[1],
result[2],
@@ -147,27 +147,27 @@ class ClientRepositoryService(ClientRepositoryABC):
return client
- def apppend_sent_message_count(self, id: int, server_id: int, value: int):
- client = self._get_client_and_server(id, server_id)
+ def append_sent_message_count(self, client_id: int, server_id: int, value: int):
+ client = self._get_client_and_server(client_id, server_id)
client.sent_message_count += value
self.update_client(client)
- def apppend_received_message_count(self, id: int, server_id: int, value: int):
- client = self._get_client_and_server(id, server_id)
+ def append_received_message_count(self, client_id: int, server_id: int, value: int):
+ client = self._get_client_and_server(client_id, server_id)
client.received_message_count += value
self.update_client(client)
- def apppend_deleted_message_count(self, id: int, server_id: int, value: int):
- client = self._get_client_and_server(id, server_id)
+ def append_deleted_message_count(self, client_id: int, server_id: int, value: int):
+ client = self._get_client_and_server(client_id, server_id)
client.deleted_message_count += value
self.update_client(client)
- def apppend_received_command_count(self, id: int, server_id: int, value: int):
- client = self._get_client_and_server(id, server_id)
+ def append_received_command_count(self, client_id: int, server_id: int, value: int):
+ client = self._get_client_and_server(client_id, server_id)
client.received_command_count += value
self.update_client(client)
- def apppend_moved_users_count(self, id: int, server_id: int, value: int):
- client = self._get_client_and_server(id, server_id)
+ def append_moved_users_count(self, client_id: int, server_id: int, value: int):
+ client = self._get_client_and_server(client_id, server_id)
client.moved_users_count += value
self.update_client(client)
diff --git a/src/gismo_data/service/known_user_repository_service.py b/src/gismo_data/service/known_user_repository_service.py
index d85b44c..011a472 100644
--- a/src/gismo_data/service/known_user_repository_service.py
+++ b/src/gismo_data/service/known_user_repository_service.py
@@ -27,7 +27,7 @@ class KnownUserRepositoryService(KnownUserRepositoryABC):
users.append(KnownUser(
result[1],
result[2],
- self._servers.get_server_by_id(result[3]),
+ result[3],
id=result[0]
))
@@ -39,7 +39,7 @@ class KnownUserRepositoryService(KnownUserRepositoryABC):
return KnownUser(
result[1],
result[2],
- self._servers.get_server_by_id(result[3]),
+ result[3],
id=result[0]
)
@@ -49,7 +49,7 @@ class KnownUserRepositoryService(KnownUserRepositoryABC):
return KnownUser(
result[1],
result[2],
- self._servers.get_server_by_id(result[3]),
+ result[3],
id=result[0]
)
diff --git a/src/gismo_data/service/migration_service.py b/src/gismo_data/service/migration_service.py
index cd34dd3..861b480 100644
--- a/src/gismo_data/service/migration_service.py
+++ b/src/gismo_data/service/migration_service.py
@@ -1,3 +1,5 @@
+from typing import Type
+
from cpl_core.database.context import DatabaseContextABC
from cpl_core.dependency_injection import ServiceProviderABC
from cpl_core.logging import LoggerABC
@@ -15,7 +17,7 @@ class MigrationService:
self._db = db
self._cursor = db.cursor
- self._migrations: list[MigrationABC] = MigrationABC.__subclasses__()
+ self._migrations: list[Type[MigrationABC]] = MigrationABC.__subclasses__()
def migrate(self):
self._logger.info(__name__, f"Running Migrations")
@@ -28,8 +30,8 @@ class MigrationService:
if result:
# there is a table named "tableName"
self._logger.trace(__name__, f"Running SQL Command: {MigrationHistory.get_select_by_id_string(migration_id)}")
- migration_from_db: MigrationHistory = self._db.select(MigrationHistory.get_select_by_id_string(migration_id))
- self._logger.trace(__name__, migration_from_db)
+ migration_from_db = self._db.select(MigrationHistory.get_select_by_id_string(migration_id))
+ self._logger.trace(__name__, str(migration_from_db))
if migration_from_db is not None and len(migration_from_db) > 0:
continue
diff --git a/src/gismo_data/service/server_repository_service.py b/src/gismo_data/service/server_repository_service.py
index 6096390..28426ce 100644
--- a/src/gismo_data/service/server_repository_service.py
+++ b/src/gismo_data/service/server_repository_service.py
@@ -27,9 +27,9 @@ class ServerRepositoryService(ServerRepositoryABC):
return servers
- def get_server_by_id(self, id: int) -> Server:
- self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_id_string(id)}')
- result = self._context.select(Server.get_select_by_id_string(id))[0]
+ def get_server_by_id(self, server_id: int) -> Server:
+ self._logger.trace(__name__, f'Send SQL command: {Server.get_select_by_id_string(server_id)}')
+ result = self._context.select(Server.get_select_by_id_string(server_id))[0]
return Server(
result[1],
id=result[0]
diff --git a/src/gismo_data/service/user_repository_service.py b/src/gismo_data/service/user_repository_service.py
index 7bb29ec..adde980 100644
--- a/src/gismo_data/service/user_repository_service.py
+++ b/src/gismo_data/service/user_repository_service.py
@@ -56,6 +56,8 @@ class UserRepositoryService(UserRepositoryABC):
id=result[0]
))
+ return users
+
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User:
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}')
result = self._context.select(User.get_select_by_discord_id_and_server_id_string(discord_id, server_id))[0]
@@ -78,9 +80,9 @@ class UserRepositoryService(UserRepositoryABC):
return User(
result[1],
result[2],
- result[3],
- result[4],
self._servers.get_server_by_id(result[3]),
+ result[4],
+ result[5],
id=result[0]
)