Added PyCharm support (fixed typing and so on)
This commit is contained in:
@@ -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):
|
||||
|
@@ -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
|
||||
|
@@ -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}')
|
||||
|
@@ -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)
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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")
|
||||
|
@@ -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):
|
||||
|
@@ -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):
|
||||
|
@@ -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)
|
||||
|
@@ -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]
|
||||
)
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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]
|
||||
|
@@ -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]
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user