Compare commits
243 Commits
Author | SHA1 | Date | |
---|---|---|---|
0f2f17b1f4 | |||
e7747a306f | |||
8a1dfb92f8 | |||
ef276564d2 | |||
f8fe9af8da | |||
db175b5b28 | |||
4bbb2b5c45 | |||
c74a74a3c5 | |||
3ae2b68528 | |||
2deeecf8ff | |||
8416eaf32a | |||
5489cc96b4 | |||
82ba1ae904 | |||
a5267a793d | |||
010bb65ba7 | |||
b5d5e0cf66 | |||
c968fbb3d7 | |||
0ef2428b9d | |||
e17b24a0c1 | |||
234a9a382a | |||
|
9eef94baf2 | ||
ca7798987c | |||
e825a708ac | |||
a4df809916 | |||
6bfcd4748d | |||
dee76b4d0d | |||
01a7b1f996 | |||
c04389ecaf | |||
fcf1d2038b | |||
558d134bd7 | |||
26963b2bef | |||
bc8ff7dc0f | |||
7d4a28d524 | |||
d83e842551 | |||
0c142f51cc | |||
291d9ad6d6 | |||
7f3541c5c8 | |||
|
0662be7b79 | ||
|
853c1262e7 | ||
|
dc025170e1 | ||
|
c9a5a64c7b | ||
bed3f07347 | |||
ab44aa55bc | |||
ed2dab6ff8 | |||
7dd2d13b58 | |||
b352987dcc | |||
a8663b8d54 | |||
ff247bcec3 | |||
500d884ea1 | |||
2f657a7ce7 | |||
4db97248ca | |||
40419c9a0b | |||
dadaa6ac09 | |||
10ba511158 | |||
09a4ace867 | |||
b436daeb35 | |||
daa031bc57 | |||
286c653252 | |||
|
3eaae4679f | ||
|
39079b2b58 | ||
|
fcc5b882b7 | ||
42826a1914 | |||
2ae0a99783 | |||
51fd8f7a8b | |||
291efd2319 | |||
0b17b27bd0 | |||
f800a11f41 | |||
7e6485459b | |||
789186454e | |||
49aa2f3aa3 | |||
199c269804 | |||
adc74d6288 | |||
c6e52039cb | |||
4955eb3a19 | |||
9d17070d02 | |||
f417eca644 | |||
a10724a495 | |||
e3ac78f97b | |||
68c1bc0bc3 | |||
be5567c1fd | |||
e34fbb60aa | |||
f03ee54703 | |||
9bae6c3c13 | |||
e73ebeb052 | |||
5fce7318ae | |||
d1298606f3 | |||
ca361b63cb | |||
d5de1991eb | |||
22b0c3ca6a | |||
1d09ad80bf | |||
c949efea50 | |||
0fd99cc6ba | |||
2c29b45f5a | |||
b8e340f661 | |||
026dfe0dfb | |||
d27964372d | |||
e15ae555be | |||
ce70e816fe | |||
60172e0cfe | |||
62d56a2247 | |||
be692326d6 | |||
074fa1ed46 | |||
93269908bc | |||
0bb5024c6a | |||
9c7b00e259 | |||
1a5767edf0 | |||
7bcd632b59 | |||
20aedba23d | |||
1d4a6c3e3b | |||
61101eb576 | |||
14ecc46d92 | |||
01cf17ef86 | |||
c5d2639e0a | |||
6356d455f4 | |||
0029fc4ac8 | |||
cbb73d7c86 | |||
68694d2e13 | |||
762ae5fd4d | |||
ed1cb24e9c | |||
e489787f01 | |||
d668d0138f | |||
7c77768697 | |||
8108f83b92 | |||
afd024e991 | |||
e69955e6d2 | |||
df26a66562 | |||
c6f460c0ab | |||
3390e09ef3 | |||
ed9a3bc90c | |||
2e24a3b1f2 | |||
f4c340796e | |||
4edda07cee | |||
e951baa358 | |||
2d261a6222 | |||
1f095c9415 | |||
a8551f2f95 | |||
3806c36571 | |||
a5f710177e | |||
5a91e31964 | |||
112b9d6208 | |||
be810a6533 | |||
9ebbd7ccf7 | |||
0b5f47ab8a | |||
|
00a0c182be | ||
|
d7105b9d19 | ||
|
73fedd31dc | ||
|
c9a5f648a2 | ||
|
76642112ab | ||
|
5e646d394b | ||
|
2ab2ef3776 | ||
7780b43e11 | |||
|
ffad565520 | ||
f033eeaf87 | |||
3b4b81eba0 | |||
|
4e00da99b5 | ||
3fc3b9548a | |||
9cbc589d62 | |||
|
e351b98fe4 | ||
a2e52e473c | |||
463456711d | |||
4d69250342 | |||
|
276910c86d | ||
b0c75fa651 | |||
|
e81449031e | ||
4176db9f91 | |||
14d543a587 | |||
d1740edda0 | |||
|
1edcfe58d2 | ||
2c7755310d | |||
aeef7ed477 | |||
e83982fc2a | |||
|
acc106a567 | ||
67696bc63c | |||
|
c9f28ddc14 | ||
|
b903ec5434 | ||
|
81bf7b6250 | ||
|
bef8ea0a25 | ||
558b6628a3 | |||
15af3b1f63 | |||
a2ebf4e3b5 | |||
|
3d56ef1dd5 | ||
|
b429d60bcd | ||
7edef25617 | |||
4d7c67a3b6 | |||
426772910f | |||
04179ce906 | |||
|
c3e1aaf40f | ||
49ec7ea931 | |||
|
c0d38817d4 | ||
31682f2b83 | |||
|
a56bdf39f7 | ||
89c31c6392 | |||
0730c5f915 | |||
|
ae7f6543f3 | ||
|
711819cdea | ||
85931926c3 | |||
d99cec79b9 | |||
|
8461d793de | ||
|
baa86b75e7 | ||
|
652a3eeb47 | ||
03d427b520 | |||
7a9e127df3 | |||
118ba99b92 | |||
2914308d65 | |||
732d28e5dc | |||
cb8c090ab3 | |||
5cbd40ec03 | |||
3832f9b8fc | |||
d6b65c42cc | |||
6509f628ca | |||
5b61de0bf1 | |||
5afbdb9b82 | |||
880fe8a4c7 | |||
12492cf596 | |||
9584b34f8f | |||
5e1caf713c | |||
c254114987 | |||
81499ef8e6 | |||
b0b646bb2b | |||
e8e6a28d87 | |||
26e1ed7496 | |||
d2c233a855 | |||
2176037d08 | |||
16546b4d3c | |||
9c25ec9f24 | |||
d413ace721 | |||
647e847d17 | |||
f2ee3d64f6 | |||
4763c41b10 | |||
562caeb10b | |||
a3bf5535f6 | |||
26a93c5ea1 | |||
abe9a7b472 | |||
97a3ba24a6 | |||
b1becbe866 | |||
059e345751 | |||
744501b3c2 | |||
056335e84b | |||
eda1caf36a | |||
c82e8e3065 | |||
bca2e02cc2 | |||
1927860206 | |||
24ae39d9f6 |
6
.gitignore
vendored
6
.gitignore
vendored
@ -138,3 +138,9 @@ dmypy.json
|
||||
# Cython debug symbols
|
||||
cython_debug/
|
||||
|
||||
# custom vs code
|
||||
PythonImportHelper-v2-Completion.json
|
||||
appsettings.*.json
|
||||
|
||||
# idea
|
||||
.idea/
|
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
[submodule "src/gismo/config"]
|
||||
path = src/gismo/config
|
||||
url = https://git.sh-edraft.de/sh-edraft.de/sh_gismo_config.git
|
2
LICENSE
2
LICENSE
@ -1,4 +1,4 @@
|
||||
MIT License Copyright (c) <year> <copyright holders>
|
||||
MIT License Copyright (c) 2021-2022 sh-edraft.de
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
33
cpl-workspace.json
Normal file
33
cpl-workspace.json
Normal file
@ -0,0 +1,33 @@
|
||||
{
|
||||
"WorkspaceSettings": {
|
||||
"DefaultProject": "gismo",
|
||||
"Projects": {
|
||||
"gismo": "src/gismo/gismo.json",
|
||||
"gismo-cli": "src/gismo_cli/gismo-cli.json",
|
||||
"gismo-core": "src/gismo_core/gismo-core.json",
|
||||
"gismo-data": "src/gismo_data/gismo-data.json",
|
||||
"boot-log": "src/modules/boot_log/boot-log.json",
|
||||
"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",
|
||||
"permission": "src/modules/permission/permission.json"
|
||||
},
|
||||
"Scripts": {
|
||||
"build-gismo": "cd src/gismo; echo 'gismo:'; cpl build; cd ../../;",
|
||||
"build-gismo-cli": "cd src/gismo_cli; echo 'gismo-cli:'; cpl build; cd ../../;",
|
||||
"build-start": "cpl build-gismo-cli; cpl build-gismo; cd dist/gismo/build/gismo; bash gismo",
|
||||
"bs": "cpl build-start",
|
||||
"build-all": "cpl build-gismo-cli; cpl build-gismo;",
|
||||
"ba": "cpl build-all",
|
||||
"pre-build": "cd ../gismo_cli; echo 'gismo-cli:'; cpl build; echo 'gismo:'",
|
||||
"pre-start": "if [ -z $GISMO_ENVIRONMENT ]; then echo '!WARNING! You should start with the right environment!\nRun cpl start-ENV\nSee workspace for more details.'; sleep 2; fi",
|
||||
"pre-dev": "echo 'development:';",
|
||||
"dev": "export GISMO_ENVIRONMENT=development; export GISMO_NAME=Gismo-dev; cpl start",
|
||||
"pre-test": "echo 'staging:';",
|
||||
"test": "export GISMO_ENVIRONMENT=staging; export GISMO_NAME=Gismo-test; cpl start",
|
||||
"pre-prod": "echo 'production:';",
|
||||
"prod": "export GISMO_ENVIRONMENT=production; export GISMO_NAME=Gismo-prod; cpl start"
|
||||
}
|
||||
}
|
||||
}
|
25
src/gismo/__init__.py
Normal file
25
src/gismo/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
gismo sh-edraft Gismo
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Dicord bot Gismo
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'gismo'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '0.4.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='4', micro='2')
|
46
src/gismo/application.py
Normal file
46
src/gismo/application.py
Normal file
@ -0,0 +1,46 @@
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
|
||||
from gismo_core.abc.bot_service_abc import BotServiceABC
|
||||
from gismo_core.configuration.bot_settings import BotSettings
|
||||
from gismo_core.configuration.server_settings import ServerSettings
|
||||
from gismo_core.service.bot_service import BotService
|
||||
|
||||
|
||||
class Gismo(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
self._bot: BotService = services.get_service(BotServiceABC)
|
||||
self._logger: LoggerABC = services.get_service(LoggerABC)
|
||||
self._bot_settings: BotSettings = config.get_configuration(BotSettings)
|
||||
|
||||
async def configure(self):
|
||||
self._logger.debug(__name__, 'Try to load discord server configs')
|
||||
for server in self._bot_settings.servers:
|
||||
server: ServerSettings = server
|
||||
self._logger.trace(__name__, f'Try to load config for server: {server.id}')
|
||||
self._configuration.add_configuration(f'DSERVER_{server.id}', server)
|
||||
self._logger.trace(__name__, f'Loaded config for server: {server.id}')
|
||||
|
||||
async def main(self):
|
||||
try:
|
||||
self._logger.debug(__name__, f'Starting...\n')
|
||||
self._logger.trace(__name__, f'Try to start {BotService}')
|
||||
await self._bot.start_async()
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, 'Start failed', e)
|
||||
|
||||
async def stop_async(self):
|
||||
try:
|
||||
self._logger.trace(__name__, f'Try to stop {BotService}')
|
||||
await self._bot.close()
|
||||
self._logger.trace(__name__, f'Stopped {BotService}')
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, 'stop failed', e)
|
||||
|
||||
Console.write_line()
|
1
src/gismo/config
Submodule
1
src/gismo/config
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 83fd51adff8a99af2ef3456542901ec78d4e1946
|
24
src/gismo/gismo
Normal file
24
src/gismo/gismo
Normal file
@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
path="`dirname \"$0\"`" # relative
|
||||
path="`( cd \"$path\" && pwd)`" # absolutized and normalized
|
||||
|
||||
cd "$path/../"
|
||||
|
||||
if [[ $1 == "-dev" ]]; then
|
||||
export GISMO_ENVIRONMENT=development
|
||||
export GISMO_NAME=Gismo-dev
|
||||
elif [[ $1 == "-test" ]]; then
|
||||
export GISMO_ENVIRONMENT=staging
|
||||
export GISMO_NAME=Gismo-test
|
||||
elif [[ $1 == "-server" ]]; then
|
||||
export GISMO_ENVIRONMENT=production
|
||||
export GISMO_NAME=Gismo
|
||||
else
|
||||
export GISMO_ENVIRONMENT=production
|
||||
export GISMO_NAME=Gismo-prod
|
||||
fi
|
||||
|
||||
export PYTHONPATH=./:$PYTHONPATH
|
||||
|
||||
python3.9 gismo/main.py
|
57
src/gismo/gismo.json
Normal file
57
src/gismo/gismo.json
Normal file
@ -0,0 +1,57 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "gismo",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "4",
|
||||
"Micro": "2"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
"Description": "sh-edraft Gismo",
|
||||
"LongDescription": "sh-edraft Dicord bot Gismo",
|
||||
"URL": "https://www.sh-edraft.de",
|
||||
"CopyrightDate": "2021 - 2022",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.0",
|
||||
"discord.py==1.7.3",
|
||||
"cpl-query>=2022.6.0"
|
||||
],
|
||||
"DevDependencies": [],
|
||||
"PythonVersion": ">=3.9.2",
|
||||
"PythonPath": {
|
||||
"linux": "../../venv/bin/python"
|
||||
},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"ProjectType": "console",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "gismo.main",
|
||||
"EntryPoint": "gismo",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {
|
||||
"cpl_cli": [
|
||||
"*.json"
|
||||
]
|
||||
},
|
||||
"ProjectReferences": [
|
||||
"../gismo_core/gismo-core.json",
|
||||
"../gismo_data/gismo-data.json",
|
||||
"../modules/boot_log/boot-log.json",
|
||||
"../modules/base/base.json",
|
||||
"../modules/database/database.json",
|
||||
"../modules/permission/permission.json"
|
||||
]
|
||||
}
|
||||
}
|
47
src/gismo/main.py
Normal file
47
src/gismo/main.py
Normal file
@ -0,0 +1,47 @@
|
||||
import asyncio
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
|
||||
from gismo.application import Gismo
|
||||
from gismo.startup import Startup
|
||||
from modules.boot_log.boot_log_extension import BootLogExtension
|
||||
from modules.database.database_extension import DatabaseExtension
|
||||
|
||||
|
||||
class Main:
|
||||
|
||||
def __init__(self):
|
||||
self._gismo: Optional[Gismo] = None
|
||||
|
||||
async def main(self):
|
||||
app_builder = ApplicationBuilder(Gismo)
|
||||
app_builder.use_extension(DatabaseExtension)
|
||||
app_builder.use_extension(BootLogExtension)
|
||||
app_builder.use_startup(Startup)
|
||||
self._gismo = await app_builder.build_async()
|
||||
await self._gismo.run_async()
|
||||
|
||||
async def stop(self):
|
||||
await self._gismo.stop_async()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main = Main()
|
||||
ml = asyncio.get_event_loop()
|
||||
try:
|
||||
ml.run_until_complete(main.main())
|
||||
except KeyboardInterrupt:
|
||||
ml.run_until_complete(main.stop())
|
||||
|
||||
# ((
|
||||
# ( `)
|
||||
# ; / ,
|
||||
# / \/
|
||||
# / |
|
||||
# / ~/
|
||||
# / ) ) ~ edraft
|
||||
# ___// | /
|
||||
# `--' \_~-,
|
||||
|
||||
# happy new year :)
|
126
src/gismo/startup.py
Normal file
126
src/gismo/startup.py
Normal file
@ -0,0 +1,126 @@
|
||||
import os
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.application import StartupABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.database import DatabaseSettings
|
||||
from cpl_core.dependency_injection import ServiceCollectionABC, ServiceProviderABC
|
||||
from cpl_core.environment import ApplicationEnvironment
|
||||
from cpl_core.logging import LoggerABC
|
||||
|
||||
from gismo_core.abc.bot_service_abc import BotServiceABC
|
||||
from gismo_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||
from gismo_core.abc.command_abc import CommandABC
|
||||
from gismo_core.abc.message_service_abc import MessageServiceABC
|
||||
from gismo_core.service.bot_service import BotService
|
||||
from gismo_core.service.client_utils_service import ClientUtilsService
|
||||
from gismo_core.service.message_service import MessageService
|
||||
from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||
from gismo_data.abc.migration_abc import MigrationABC
|
||||
from gismo_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
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.db_context import DBContext
|
||||
from gismo_data.migration.initial_migration import InitialMigration
|
||||
from gismo_data.migration.migration_0_3 import Migration_0_3
|
||||
from gismo_data.migration.migration_0_3_1 import Migration_0_3_1
|
||||
from gismo_data.service.client_repository_service import (
|
||||
ClientRepositoryABC, ClientRepositoryService)
|
||||
from gismo_data.service.known_user_repository_service import \
|
||||
KnownUserRepositoryService
|
||||
from gismo_data.service.migration_service import MigrationService
|
||||
from gismo_data.service.server_repository_service import \
|
||||
ServerRepositoryService
|
||||
from gismo_data.service.user_joined_server_repository_service import UserJoinedServerRepositoryService
|
||||
from gismo_data.service.user_joined_voice_channel_service import UserJoinedVoiceChannelRepositoryService
|
||||
from gismo_data.service.user_repository_service import UserRepositoryService
|
||||
from modules.base.base import Base
|
||||
from modules.base.service.afk_command_service import AFKCommandService
|
||||
from modules.base.service.help_command_service import HelpCommandService
|
||||
from modules.base.service.info_command_service import InfoCommandService
|
||||
from modules.base.service.ping_command_service import PingCommandService
|
||||
from modules.base.service.purge_command_service import PurgeCommandService
|
||||
from modules.base.service.user_info_command_service import UserInfoCommandService
|
||||
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 gismo_core.abc.module_abc import ModuleABC
|
||||
from gismo_core.abc.module_service_abc import ModuleServiceABC
|
||||
from gismo_core.service.module_service import ModuleService
|
||||
from modules.permission.service.permission_service import PermissionService
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
self._start_time = datetime.now()
|
||||
|
||||
self._config: Optional[ConfigurationABC] = None
|
||||
|
||||
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', str(self._start_time))
|
||||
|
||||
self._config = configuration
|
||||
return configuration
|
||||
|
||||
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)
|
||||
services.add_transient(MessageServiceABC, MessageService)
|
||||
services.add_transient(MigrationService)
|
||||
services.add_transient(ClientUtilsServiceABC, ClientUtilsService)
|
||||
|
||||
# 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)
|
||||
|
||||
# module services
|
||||
services.add_singleton(PermissionServiceABC, PermissionService)
|
||||
|
||||
# commands
|
||||
services.add_transient(CommandABC, PingCommandService)
|
||||
services.add_transient(CommandABC, PurgeCommandService)
|
||||
services.add_transient(CommandABC, AFKCommandService)
|
||||
services.add_transient(CommandABC, HelpCommandService)
|
||||
services.add_transient(CommandABC, InfoCommandService)
|
||||
services.add_transient(CommandABC, UserInfoCommandService)
|
||||
|
||||
# modules
|
||||
services.add_transient(ModuleABC, Database)
|
||||
services.add_transient(ModuleABC, BootLog)
|
||||
services.add_singleton(ModuleABC, Permission)
|
||||
services.add_singleton(ModuleABC, Base)
|
||||
|
||||
# migrations
|
||||
services.add_transient(MigrationABC, InitialMigration)
|
||||
services.add_transient(MigrationABC, Migration_0_3)
|
||||
services.add_transient(MigrationABC, Migration_0_3_1)
|
||||
|
||||
startup_init_time = round((datetime.now() - datetime.strptime(self._config.get_configuration('Startup_StartTime'), '%Y-%m-%d %H:%M:%S.%f')).total_seconds(), 2)
|
||||
self._config.add_configuration('Startup_InitTime', str(startup_init_time))
|
||||
provider: ServiceProviderABC = services.build_service_provider()
|
||||
logger: LoggerABC = provider.get_service(LoggerABC)
|
||||
logger.debug(__name__, f'Startup Init time: {startup_init_time}s')
|
||||
|
||||
return provider
|
25
src/gismo_cli/__init__.py
Normal file
25
src/gismo_cli/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
gismo-cli sh-edraft Gismo - CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Dicord bot Gismo - command line interface
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'gismo_cli'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '0.1.0'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='1', micro='0')
|
16
src/gismo_cli/application.py
Normal file
16
src/gismo_cli/application.py
Normal file
@ -0,0 +1,16 @@
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
|
||||
async def configure(self):
|
||||
pass
|
||||
|
||||
async def main(self):
|
||||
Console.write_line('Hello World')
|
15
src/gismo_cli/appsettings.json
Normal file
15
src/gismo_cli/appsettings.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"TimeFormatSettings": {
|
||||
"DateFormat": "%Y-%m-%d",
|
||||
"TimeFormat": "%H:%M:%S",
|
||||
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||
},
|
||||
|
||||
"LoggingSettings": {
|
||||
"Path": "logs/",
|
||||
"Filename": "log_$start_time.log",
|
||||
"ConsoleLogLevel": "ERROR",
|
||||
"FileLogLevel": "WARN"
|
||||
}
|
||||
}
|
48
src/gismo_cli/gismo-cli.json
Normal file
48
src/gismo_cli/gismo-cli.json
Normal file
@ -0,0 +1,48 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "gismo-cli",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "1",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
"Description": "sh-edraft Gismo - CLI",
|
||||
"LongDescription": "sh-edraft Dicord bot Gismo - command line interface",
|
||||
"URL": "https://www.sh-edraft.de",
|
||||
"CopyrightDate": "2021 - 2022",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"sh_cpl-core>=2021.11.0",
|
||||
"sh_cpl-query>=2021.11.0"
|
||||
],
|
||||
"PythonVersion": ">=3.9.2",
|
||||
"PythonPath": {
|
||||
"linux": "../../venv/bin/python"
|
||||
},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"ProjectType": "console",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "gismo.main",
|
||||
"EntryPoint": "gismo",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {
|
||||
"cpl_cli": [
|
||||
"*.json"
|
||||
]
|
||||
},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
18
src/gismo_cli/main.py
Normal file
18
src/gismo_cli/main.py
Normal file
@ -0,0 +1,18 @@
|
||||
import asyncio
|
||||
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
|
||||
from gismo_cli.application import Application
|
||||
from gismo_cli.startup import Startup
|
||||
|
||||
|
||||
async def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app_builder.use_startup(Startup)
|
||||
app: Application = await app_builder.build_async()
|
||||
await app.run_async()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ml = asyncio.get_event_loop()
|
||||
ml.run_until_complete(main())
|
16
src/gismo_cli/startup.py
Normal file
16
src/gismo_cli/startup.py
Normal file
@ -0,0 +1,16 @@
|
||||
from cpl_core.application import StartupABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironment
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
async def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
return configuration
|
||||
|
||||
async def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
return services.build_service_provider()
|
25
src/gismo_core/__init__.py
Normal file
25
src/gismo_core/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
gismo sh-edraft Gismo
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Dicord bot Gismo
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'gismo_core'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '0.4.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='4', micro='2')
|
25
src/gismo_core/abc/__init__.py
Normal file
25
src/gismo_core/abc/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
gismo sh-edraft Gismo
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Dicord bot Gismo
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'gismo_core.abc'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '0.4.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='4', micro='2')
|
16
src/gismo_core/abc/bot_service_abc.py
Normal file
16
src/gismo_core/abc/bot_service_abc.py
Normal file
@ -0,0 +1,16 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
class BotServiceABC(ABC, commands.Bot):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def start_async(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def stop_async(self): pass
|
16
src/gismo_core/abc/client_utils_service_abc.py
Normal file
16
src/gismo_core/abc/client_utils_service_abc.py
Normal file
@ -0,0 +1,16 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class ClientUtilsServiceABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def received_command(self, guild_id: int): pass
|
||||
|
||||
@abstractmethod
|
||||
def moved_user(self, guild_id: int): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_client(self, dc_ic: int, guild_id: int): pass
|
11
src/gismo_core/abc/command_abc.py
Normal file
11
src/gismo_core/abc/command_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from discord.ext import commands
|
||||
|
||||
from gismo_core.commands_meta import CommandsMeta
|
||||
|
||||
|
||||
class CommandABC(ABC, commands.Cog, metaclass=CommandsMeta):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
25
src/gismo_core/abc/events/__init__.py
Normal file
25
src/gismo_core/abc/events/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
gismo sh-edraft Gismo
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Dicord bot Gismo
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'gismo_core.abc.events'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '0.4.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='4', micro='2')
|
11
src/gismo_core/abc/events/on_bulk_message_delete_abc.py
Normal file
11
src/gismo_core/abc/events/on_bulk_message_delete_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnBulkMessageDeleteABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_bulk_message_delete(self, messages: list[discord.Message]): pass
|
10
src/gismo_core/abc/events/on_connect_abc.py
Normal file
10
src/gismo_core/abc/events/on_connect_abc.py
Normal file
@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class OnConnectABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_connect(self): pass
|
10
src/gismo_core/abc/events/on_disconnect_abc.py
Normal file
10
src/gismo_core/abc/events/on_disconnect_abc.py
Normal file
@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class OnDisconnectABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_disconnect(self): pass
|
10
src/gismo_core/abc/events/on_error_abc.py
Normal file
10
src/gismo_core/abc/events/on_error_abc.py
Normal file
@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class OnErrorABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_error(self, event: str, *args, **kwargs): pass
|
12
src/gismo_core/abc/events/on_group_join_abc.py
Normal file
12
src/gismo_core/abc/events/on_group_join_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGroupJoinABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_group_join(
|
||||
self, chhanel: discord.GroupChannel, user: discord.User): pass
|
11
src/gismo_core/abc/events/on_group_remove_abc.py
Normal file
11
src/gismo_core/abc/events/on_group_remove_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
class OnGroupRemoveABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_group_remove(
|
||||
self, chhanel: discord.GroupChannel, user: discord.User): pass
|
11
src/gismo_core/abc/events/on_guild_available_abc.py
Normal file
11
src/gismo_core/abc/events/on_guild_available_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildAvailableABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_available(self, guild: discord.Guild): pass
|
12
src/gismo_core/abc/events/on_guild_channel_create_abc.py
Normal file
12
src/gismo_core/abc/events/on_guild_channel_create_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildChannelCreateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_channel_create(self, channel: discord.abc.GuildChannel): pass
|
||||
|
12
src/gismo_core/abc/events/on_guild_channel_delete_abc.py
Normal file
12
src/gismo_core/abc/events/on_guild_channel_delete_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildChannelDeleteABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_channel_delete(self, channel: discord.abc.GuildChannel): pass
|
||||
|
@ -0,0 +1,14 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildChannelPinsUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_channel_pins_update(self, channel: discord.abc.GuildChannel, list_pin: Optional[datetime]): pass
|
||||
|
11
src/gismo_core/abc/events/on_guild_channel_update_abc.py
Normal file
11
src/gismo_core/abc/events/on_guild_channel_update_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildChannelUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_channel_update(self, before: discord.abc.GuildChannel, after: discord.abc.GuildChannel): pass
|
12
src/gismo_core/abc/events/on_guild_emojis_update_abc.py
Normal file
12
src/gismo_core/abc/events/on_guild_emojis_update_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Sequence
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildEmojisUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_emojis_update(self, guild: discord.Guild, before: Sequence[discord.Emoji], after: Sequence[discord.Emoji]): pass
|
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildIntegrationsUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_integrations_update(self, guild: discord.Guild): pass
|
||||
|
11
src/gismo_core/abc/events/on_guild_join_abc.py
Normal file
11
src/gismo_core/abc/events/on_guild_join_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildJoinABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_join(self, guild: discord.Guild): pass
|
10
src/gismo_core/abc/events/on_guild_remove_abc.py
Normal file
10
src/gismo_core/abc/events/on_guild_remove_abc.py
Normal file
@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildRemoveABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
@abstractmethod
|
||||
async def on_guild_remove(self, guild: discord.Guild): pass
|
11
src/gismo_core/abc/events/on_guild_role_create_abc.py
Normal file
11
src/gismo_core/abc/events/on_guild_role_create_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildRoleCreateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_role_create(self, role: discord.Role): pass
|
11
src/gismo_core/abc/events/on_guild_role_delete_abc.py
Normal file
11
src/gismo_core/abc/events/on_guild_role_delete_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildRoleDeleteABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_role_delete(self, role: discord.Role): pass
|
11
src/gismo_core/abc/events/on_guild_role_update_abc.py
Normal file
11
src/gismo_core/abc/events/on_guild_role_update_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildRoleUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_role_update(self, before: discord.Role, after: discord.Role): pass
|
11
src/gismo_core/abc/events/on_guild_unavailable_abc.py
Normal file
11
src/gismo_core/abc/events/on_guild_unavailable_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildUnavailableABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_unavailable(self, guild: discord.Guild): pass
|
11
src/gismo_core/abc/events/on_guild_update_abc.py
Normal file
11
src/gismo_core/abc/events/on_guild_update_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnGuildUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_update(self, before: discord.Guild, after: discord.Guild): pass
|
12
src/gismo_core/abc/events/on_invite_create_abc.py
Normal file
12
src/gismo_core/abc/events/on_invite_create_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnInviteCreateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_invite_create(self, invite: discord.Invite): pass
|
||||
|
11
src/gismo_core/abc/events/on_invite_delete_abc.py
Normal file
11
src/gismo_core/abc/events/on_invite_delete_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnInviteDeleteABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_invite_delete(self, invite: discord.Invite): pass
|
11
src/gismo_core/abc/events/on_member_ban_abc.py
Normal file
11
src/gismo_core/abc/events/on_member_ban_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnMemberBanABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_member_ban(self, guild: discord.Guild, user: discord.User): pass
|
12
src/gismo_core/abc/events/on_member_join_abc.py
Normal file
12
src/gismo_core/abc/events/on_member_join_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnMemberJoinABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
async def on_member_join(self, member: discord.Member): pass
|
11
src/gismo_core/abc/events/on_member_remove_abc.py
Normal file
11
src/gismo_core/abc/events/on_member_remove_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnMemberRemoveABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_member_remove(self, member: discord.Member): pass
|
11
src/gismo_core/abc/events/on_member_unban_abc.py
Normal file
11
src/gismo_core/abc/events/on_member_unban_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnMemberUnbanABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_member_unban(self, guild: discord.Guild, user: discord.User): pass
|
11
src/gismo_core/abc/events/on_member_update_abc.py
Normal file
11
src/gismo_core/abc/events/on_member_update_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnMemberUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_member_update(self, before: discord.Member, after: discord.Member): pass
|
11
src/gismo_core/abc/events/on_message_abc.py
Normal file
11
src/gismo_core/abc/events/on_message_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnMessageABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_message(self, message: discord.Message): pass
|
11
src/gismo_core/abc/events/on_message_delete_abc.py
Normal file
11
src/gismo_core/abc/events/on_message_delete_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnMessageDeleteABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_message_delete(self, message: discord.Message): pass
|
11
src/gismo_core/abc/events/on_message_edit_abc.py
Normal file
11
src/gismo_core/abc/events/on_message_edit_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnMessageEditABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_message_edit(self, before: discord.Message, after: discord.Message): pass
|
12
src/gismo_core/abc/events/on_private_channel_create_abc.py
Normal file
12
src/gismo_core/abc/events/on_private_channel_create_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnPrivateChannelCreateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_private_channel_create(self, channel: discord.abc.PrivateChannel): pass
|
||||
|
12
src/gismo_core/abc/events/on_private_channel_delete_abc.py
Normal file
12
src/gismo_core/abc/events/on_private_channel_delete_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnPrivateChannelDeleteABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_private_channel_delete(self, channel: discord.abc.PrivateChannel): pass
|
||||
|
@ -0,0 +1,14 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
import discord
|
||||
|
||||
|
||||
class OnPrivateChannelPinsUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_private_channel_pins_update(self, channel: discord.abc.PrivateChannel, list_pin: Optional[datetime]): pass
|
||||
|
12
src/gismo_core/abc/events/on_private_channel_update_abc.py
Normal file
12
src/gismo_core/abc/events/on_private_channel_update_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnPrivateChannelUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_private_channel_update(self, before: discord.GroupChannel, after: discord.GroupChannel): pass
|
||||
|
12
src/gismo_core/abc/events/on_reaction_add_abc.py
Normal file
12
src/gismo_core/abc/events/on_reaction_add_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnReactionAddABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User): pass
|
||||
|
12
src/gismo_core/abc/events/on_reaction_clear_abc.py
Normal file
12
src/gismo_core/abc/events/on_reaction_clear_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnReactionClearABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_reaction_clear(self, message: discord.Message, reactions: list[discord.Reaction]): pass
|
||||
|
12
src/gismo_core/abc/events/on_reaction_clear_emoji_abc.py
Normal file
12
src/gismo_core/abc/events/on_reaction_clear_emoji_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnReactionClearEmojiABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_reaction_clear_emoji(self, reaction: discord.Reaction): pass
|
||||
|
12
src/gismo_core/abc/events/on_reaction_remove_abc.py
Normal file
12
src/gismo_core/abc/events/on_reaction_remove_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnReactionRemoveABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_reaction_remove(self, reaction: discord.Reaction, user: discord.User): pass
|
||||
|
10
src/gismo_core/abc/events/on_ready_abc.py
Normal file
10
src/gismo_core/abc/events/on_ready_abc.py
Normal file
@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class OnReadyABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_ready(self): pass
|
11
src/gismo_core/abc/events/on_relationship_add_abc.py
Normal file
11
src/gismo_core/abc/events/on_relationship_add_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
class OnRelationshipAddABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_relationship_add(self, relationship: discord.Relationship): pass
|
||||
|
11
src/gismo_core/abc/events/on_relationship_remove_abc.py
Normal file
11
src/gismo_core/abc/events/on_relationship_remove_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
class OnRelationshipRemoveABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_relationship_remove(self, relationship: discord.Relationship): pass
|
||||
|
12
src/gismo_core/abc/events/on_relationship_update_abc.py
Normal file
12
src/gismo_core/abc/events/on_relationship_update_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnRelationshipUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_relationship_update(
|
||||
self, before: discord.Relationship, after: discord.Relationship): pass
|
10
src/gismo_core/abc/events/on_resume_abc.py
Normal file
10
src/gismo_core/abc/events/on_resume_abc.py
Normal file
@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class OnResumeABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_resume(self): pass
|
13
src/gismo_core/abc/events/on_typing_abc.py
Normal file
13
src/gismo_core/abc/events/on_typing_abc.py
Normal file
@ -0,0 +1,13 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
from typing import Union
|
||||
import discord
|
||||
|
||||
|
||||
class OnTypingABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_typing(self, channel: discord.abc.Messageable, user: Union[discord.User, discord.Member], when: datetime): pass
|
11
src/gismo_core/abc/events/on_user_update_abc.py
Normal file
11
src/gismo_core/abc/events/on_user_update_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnUserUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_user_update(self, before: discord.User, after: discord.User): pass
|
11
src/gismo_core/abc/events/on_voice_state_update_abc.py
Normal file
11
src/gismo_core/abc/events/on_voice_state_update_abc.py
Normal file
@ -0,0 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnVoiceStateUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState,after: discord.VoiceState): pass
|
12
src/gismo_core/abc/events/on_webhooks_update_abc.py
Normal file
12
src/gismo_core/abc/events/on_webhooks_update_abc.py
Normal file
@ -0,0 +1,12 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import discord
|
||||
|
||||
|
||||
class OnWebhooksUpdateABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
|
||||
@abstractmethod
|
||||
async def on_webhooks_update(self, channel: discord.abc.GuildChannel): pass
|
27
src/gismo_core/abc/message_service_abc.py
Normal file
27
src/gismo_core/abc/message_service_abc.py
Normal file
@ -0,0 +1,27 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Union
|
||||
|
||||
import discord
|
||||
from cpl_query.extension import List
|
||||
from discord.ext.commands import Context
|
||||
|
||||
|
||||
class MessageServiceABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def delete_messages(self, messages: List[discord.Message], guild_id: int): pass
|
||||
|
||||
@abstractmethod
|
||||
async def delete_message(self, message: discord.Message): pass
|
||||
|
||||
@abstractmethod
|
||||
async def send_channel_message(self, channel: discord.TextChannel, message: Union[str, discord.Embed]): pass
|
||||
|
||||
@abstractmethod
|
||||
async def send_dm_message(self, message: Union[str, discord.Embed], receiver: Union[discord.User, discord.Member]): pass
|
||||
|
||||
@abstractmethod
|
||||
async def send_ctx_msg(self, ctx: Context, message: Union[str, discord.Embed], file: discord.File = None, is_persistent: bool = False, wait_before_delete: int = None): pass
|
27
src/gismo_core/abc/module_abc.py
Normal file
27
src/gismo_core/abc/module_abc.py
Normal file
@ -0,0 +1,27 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class ModuleABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self, priorities: dict[type, int], settings_types: list[Optional[type]]):
|
||||
self._priorities = priorities
|
||||
self._success = True
|
||||
self._settings_types = settings_types
|
||||
|
||||
@property
|
||||
def success(self) -> bool:
|
||||
return self._success
|
||||
|
||||
@property
|
||||
def settings_types(self) -> list[type]:
|
||||
return self._settings_types
|
||||
|
||||
def get_priority(self, t: type) -> int:
|
||||
if t not in self._priorities:
|
||||
raise Exception(f'Priority for {t} not found!')
|
||||
return self._priorities[t]
|
||||
|
||||
def stop_propagation(self):
|
||||
self._success = False
|
155
src/gismo_core/abc/module_service_abc.py
Normal file
155
src/gismo_core/abc/module_service_abc.py
Normal file
@ -0,0 +1,155 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
from typing import Optional, Sequence, Union
|
||||
|
||||
import discord
|
||||
|
||||
|
||||
class ModuleServiceABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def load_modules(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_connect(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_disconnect(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_ready(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_resume(self): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_error(self, event: str, *args, **kwargs): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_typing(self, channel: discord.abc.Messageable, user: Union[discord.User, discord.Member], when: datetime): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_message(self, message: discord.Message): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_message_delete(self, message: discord.Message): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_bulk_message_delete(self, messages: list[discord.Message]): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_message_edit(self, before: discord.Message, after: discord.Message): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_reaction_remove(self, reaction: discord.Reaction, user: discord.User): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_reaction_clear(self, message: discord.Message, reactions: list[discord.Reaction]): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_reaction_clear_emoji(self, reaction: discord.Reaction): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_private_channel_delete(self, channel: discord.abc.PrivateChannel): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_private_channel_create(self, channel: discord.abc.PrivateChannel): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_private_channel_update(self, before: discord.GroupChannel, after: discord.GroupChannel): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_private_channel_pins_update(self, channel: discord.abc.PrivateChannel, list_pin: Optional[datetime]): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_channel_delete(self, channel: discord.abc.GuildChannel): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_channel_create(self, channel: discord.abc.GuildChannel): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_channel_update(self, before: discord.abc.GuildChannel, after: discord.abc.GuildChannel): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_channel_pins_update(self, channel: discord.abc.GuildChannel, list_pin: Optional[datetime]): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_integrations_update(self, guild: discord.Guild): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_webhooks_update(self, channel: discord.abc.GuildChannel): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_member_join(self, member: discord.Member): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_member_remove(self, member: discord.Member): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_member_update(self, before: discord.Member, after: discord.Member): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_user_update(self, before: discord.User, after: discord.User): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_join(self, guild: discord.Guild): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_remove(self, guild: discord.Guild): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_update(self, before: discord.Guild, after: discord.Guild): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_role_create(self, role: discord.Role): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_role_delete(self, role: discord.Role): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_role_update(self, before: discord.Role, after: discord.Role): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_emojis_update(self, guild: discord.Guild, before: Sequence[discord.Emoji], after: Sequence[discord.Emoji]): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_available(self, guild: discord.Guild): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_guild_unavailable(self, guild: discord.Guild): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState,after: discord.VoiceState): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_member_ban(self, guild: discord.Guild, user: discord.User): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_member_unban(self, guild: discord.Guild, user: discord.User): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_invite_create(self, invite: discord.Invite): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_invite_delete(self, invite: discord.Invite): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_group_join(self, chhanel: discord.GroupChannel, user: discord.User): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_group_remove(self, chhanel: discord.GroupChannel, user: discord.User): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_relationship_add(self, relationship: discord.Relationship): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_relationship_remove(self, relationship: discord.Relationship): pass
|
||||
|
||||
@abstractmethod
|
||||
async def on_relationship_update(self, before: discord.Relationship, after: discord.Relationship): pass
|
5
src/gismo_core/commands_meta.py
Normal file
5
src/gismo_core/commands_meta.py
Normal file
@ -0,0 +1,5 @@
|
||||
from abc import ABCMeta
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
class CommandsMeta(ABCMeta, commands.CogMeta): pass
|
25
src/gismo_core/configuration/__init__.py
Normal file
25
src/gismo_core/configuration/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
gismo sh-edraft Gismo
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Dicord bot Gismo
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'gismo_core.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '0.4.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='4', micro='2')
|
36
src/gismo_core/configuration/bot_settings.py
Normal file
36
src/gismo_core/configuration/bot_settings.py
Normal file
@ -0,0 +1,36 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_query.extension import List
|
||||
from gismo_core.configuration.server_settings import ServerSettings
|
||||
|
||||
|
||||
class BotSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._prefix: str = ''
|
||||
self._servers: List[ServerSettings] = List()
|
||||
|
||||
@property
|
||||
def prefix(self) -> str:
|
||||
return self._prefix
|
||||
|
||||
@property
|
||||
def servers(self) -> List[ServerSettings]:
|
||||
return self._servers
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._prefix = settings['Prefix']
|
||||
servers = List(ServerSettings)
|
||||
for s in settings['Servers']:
|
||||
st = ServerSettings()
|
||||
st.from_dict(s)
|
||||
servers.append(st)
|
||||
self._servers = servers
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in settings')
|
||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
23
src/gismo_core/configuration/discord_settings.py
Normal file
23
src/gismo_core/configuration/discord_settings.py
Normal file
@ -0,0 +1,23 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class DiscordSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._token: str = ''
|
||||
|
||||
@property
|
||||
def token(self) -> str:
|
||||
return self._token
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._token = settings['Token']
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {__name__} settings')
|
||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
53
src/gismo_core/configuration/embed_description_settings.py
Normal file
53
src/gismo_core/configuration/embed_description_settings.py
Normal file
@ -0,0 +1,53 @@
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_query.extension import List
|
||||
|
||||
from gismo_core.model.embed_description import EmbedDescription
|
||||
from gismo_core.model.embed_description_field import EmbedDescriptionField
|
||||
|
||||
|
||||
class EmbedDescriptionSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._embed_description: Optional[EmbedDescription] = None
|
||||
|
||||
@property
|
||||
def embed_description(self) -> EmbedDescription:
|
||||
return self._embed_description
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
title = ''
|
||||
description = ''
|
||||
url = ''
|
||||
color = ''
|
||||
fields = List(EmbedDescriptionField)
|
||||
footer = ''
|
||||
|
||||
for key in settings:
|
||||
if key == 'Title':
|
||||
title = settings[key]
|
||||
elif key == 'Description':
|
||||
description = settings[key]
|
||||
elif key == 'URL':
|
||||
url = settings[key]
|
||||
elif key == 'Color':
|
||||
color = settings[key]
|
||||
elif key == 'Fields':
|
||||
for field in settings[key]:
|
||||
fields.append(EmbedDescriptionField(field['Name'], field['Value'], bool(field['Inline'])))
|
||||
elif key == 'Footer':
|
||||
footer = settings[key]
|
||||
else:
|
||||
raise Exception(f'Unexpected key {key}')
|
||||
|
||||
self._embed_description = EmbedDescription(title, description, url, color, fields, footer)
|
||||
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
35
src/gismo_core/configuration/server_settings.py
Normal file
35
src/gismo_core/configuration/server_settings.py
Normal file
@ -0,0 +1,35 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class ServerSettings(ConfigurationModelABC):
|
||||
|
||||
def __init__(self):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._id: int = 0
|
||||
self._message_delete_timer: int = 0
|
||||
self._bot_has_no_permission_message: str = ''
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def message_delete_timer(self) -> int:
|
||||
return self._message_delete_timer
|
||||
|
||||
@property
|
||||
def bot_has_no_permission_message(self) -> str:
|
||||
return self._bot_has_no_permission_message
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._id = int(settings['Id'])
|
||||
self._message_delete_timer = int(settings['MessageDeleteTimer'])
|
||||
self._bot_has_no_permission_message = settings['BotHasNoPermissionMessage']
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in settings')
|
||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
44
src/gismo_core/gismo-core.json
Normal file
44
src/gismo_core/gismo-core.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "gismo-core",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "1",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
"Description": "sh-edraft Gismo - core",
|
||||
"LongDescription": "sh-edraft Dicord bot Gismo - core library",
|
||||
"URL": "https://www.sh-edraft.de",
|
||||
"CopyrightDate": "2021 - 2022",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"sh_cpl-core>=2021.11.0",
|
||||
"sh_cpl-query>=2021.11.0"
|
||||
],
|
||||
"PythonVersion": ">=3.9.2",
|
||||
"PythonPath": {
|
||||
"linux": "../../venv/bin/python"
|
||||
},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"ProjectType": "library",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "",
|
||||
"EntryPoint": "",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
25
src/gismo_core/model/__init__.py
Normal file
25
src/gismo_core/model/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
gismo sh-edraft Gismo
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Dicord bot Gismo
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'gismo_core.model'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '0.4.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='4', micro='2')
|
60
src/gismo_core/model/embed_description.py
Normal file
60
src/gismo_core/model/embed_description.py
Normal file
@ -0,0 +1,60 @@
|
||||
from cpl_query.extension import List
|
||||
|
||||
from gismo_core.model.embed_description_field import EmbedDescriptionField
|
||||
|
||||
|
||||
class EmbedDescription:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
title: str = None,
|
||||
description: str = None,
|
||||
url: str = None,
|
||||
color: str = None,
|
||||
fields: list[EmbedDescriptionField] = None,
|
||||
footer: str = None
|
||||
):
|
||||
self._title = title
|
||||
self._description = description
|
||||
self._url = url
|
||||
self._color = color
|
||||
self._fields = fields
|
||||
self._footer = footer
|
||||
|
||||
@property
|
||||
def title(self) -> str:
|
||||
return self._title
|
||||
|
||||
@title.setter
|
||||
def title(self, value: str):
|
||||
self._title = value
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return self._description
|
||||
|
||||
@description.setter
|
||||
def description(self, value: str):
|
||||
self._description = value
|
||||
|
||||
@property
|
||||
def url(self) -> str:
|
||||
return self._url
|
||||
|
||||
@property
|
||||
def color(self) -> str:
|
||||
return self._color
|
||||
|
||||
@property
|
||||
def fields(self) -> list[EmbedDescriptionField]:
|
||||
return self._fields
|
||||
|
||||
@fields.setter
|
||||
def fields(self, value: list[EmbedDescriptionField]):
|
||||
self._fields = value
|
||||
|
||||
@property
|
||||
def footer(self) -> str:
|
||||
return self._footer
|
||||
|
||||
|
27
src/gismo_core/model/embed_description_field.py
Normal file
27
src/gismo_core/model/embed_description_field.py
Normal file
@ -0,0 +1,27 @@
|
||||
class EmbedDescriptionField:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
value: str,
|
||||
inline: bool
|
||||
):
|
||||
self._name = name
|
||||
self._value = value
|
||||
self._inline = inline
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
||||
|
||||
@value.setter
|
||||
def value(self, value: str):
|
||||
self._value = value
|
||||
|
||||
@property
|
||||
def inline(self) -> bool:
|
||||
return self._inline
|
25
src/gismo_core/service/__init__.py
Normal file
25
src/gismo_core/service/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
gismo sh-edraft Gismo
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Dicord bot Gismo
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'gismo_core.service'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '0.4.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='4', micro='2')
|
64
src/gismo_core/service/bot_service.py
Normal file
64
src/gismo_core/service/bot_service.py
Normal file
@ -0,0 +1,64 @@
|
||||
import discord
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_core.logging import LoggerABC, LoggingLevelEnum, LoggingSettings
|
||||
from discord.ext import commands
|
||||
from gismo_core.abc.bot_service_abc import BotServiceABC
|
||||
from gismo_core.configuration.bot_settings import BotSettings
|
||||
from gismo_core.configuration.discord_settings import DiscordSettings
|
||||
from gismo_core.configuration.server_settings import ServerSettings
|
||||
from gismo_core.abc.module_service_abc import ModuleServiceABC
|
||||
from gismo_core.service.module_service import ModuleService
|
||||
|
||||
|
||||
class BotService(BotServiceABC, commands.Bot):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: LoggerABC,
|
||||
modules: ModuleService,
|
||||
discord_settings: DiscordSettings,
|
||||
bot_settings: BotSettings,
|
||||
env: ApplicationEnvironmentABC,
|
||||
logging_st: LoggingSettings,
|
||||
):
|
||||
# services
|
||||
self._logger = logger
|
||||
self._modules = modules
|
||||
self._env = env
|
||||
self._logging_st = logging_st
|
||||
|
||||
# settings
|
||||
self._discord_settings = discord_settings
|
||||
|
||||
# setup super
|
||||
commands.Bot.__init__(self, command_prefix=bot_settings.prefix, help_command=None, intents=discord.Intents().all())
|
||||
|
||||
async def start_async(self):
|
||||
self._logger.trace(__name__, 'Try to connect to discord')
|
||||
|
||||
self._modules.load_modules()
|
||||
|
||||
await self.start(self._discord_settings.token)
|
||||
# continue at on_ready
|
||||
|
||||
async def stop_async(self):
|
||||
self._logger.debug(__name__, f'Try to stop {BotService}')
|
||||
try:
|
||||
pass
|
||||
# save data
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, 'Stop failed', e)
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.info(__name__, 'Connected to discord')
|
||||
|
||||
self._logger.header(f'{self.user.name}:')
|
||||
if self._logging_st.console.value >= LoggingLevelEnum.INFO.value:
|
||||
Console.banner(self._env.application_name if self._env.application_name != '' else 'Gismo')
|
||||
|
||||
self.add_cog(self._modules)
|
||||
|
||||
await self._modules.on_ready()
|
41
src/gismo_core/service/client_utils_service.py
Normal file
41
src/gismo_core/service/client_utils_service.py
Normal file
@ -0,0 +1,41 @@
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
|
||||
from gismo_core.abc.bot_service_abc import BotServiceABC
|
||||
from gismo_core.abc.client_utils_service_abc import ClientUtilsServiceABC
|
||||
from gismo_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from gismo_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
|
||||
|
||||
class ClientUtilsService(ClientUtilsServiceABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
bot: BotServiceABC,
|
||||
servers: ServerRepositoryABC,
|
||||
clients: ClientRepositoryABC,
|
||||
db: DatabaseContextABC
|
||||
):
|
||||
ClientUtilsServiceABC.__init__(self)
|
||||
self._bot = bot
|
||||
self._servers = servers
|
||||
self._clients = clients
|
||||
self._db = db
|
||||
|
||||
def received_command(self, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client.received_command_count += 1
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def moved_user(self, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
client.moved_users_count += 1
|
||||
self._clients.update_client(client)
|
||||
self._db.save_changes()
|
||||
|
||||
def get_client(self, dc_ic: int, guild_id: int):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
client = self._clients.find_client_by_discord_id_and_server_id(self._bot.user.id, server.server_id)
|
||||
return client
|
23
src/gismo_core/service/embed_service.py
Normal file
23
src/gismo_core/service/embed_service.py
Normal file
@ -0,0 +1,23 @@
|
||||
import discord
|
||||
|
||||
from gismo_core.model.embed_description import EmbedDescription
|
||||
|
||||
|
||||
class EmbedService:
|
||||
|
||||
@staticmethod
|
||||
def get_embed(description: EmbedDescription) -> discord.Embed:
|
||||
embed = discord.Embed(
|
||||
title=description.title,
|
||||
url=description.url,
|
||||
description=description.description,
|
||||
color=int(description.color, 16)
|
||||
)
|
||||
|
||||
for field in description.fields:
|
||||
embed.add_field(name=field.name, value=field.value, inline=field.inline)
|
||||
|
||||
if description.footer is not None:
|
||||
embed.set_footer(text=description.footer)
|
||||
|
||||
return embed
|
105
src/gismo_core/service/message_service.py
Normal file
105
src/gismo_core/service/message_service.py
Normal file
@ -0,0 +1,105 @@
|
||||
import asyncio
|
||||
from typing import Union
|
||||
|
||||
import discord
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.database.context.database_context_abc import DatabaseContextABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_query.extension import List
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from gismo_core.abc.bot_service_abc import BotServiceABC
|
||||
from gismo_core.abc.message_service_abc import MessageServiceABC
|
||||
from gismo_core.configuration.server_settings import ServerSettings
|
||||
from gismo_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
|
||||
|
||||
class MessageService(MessageServiceABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, logger: LoggerABC, bot: BotServiceABC, clients: ClientRepositoryABC, db: DatabaseContextABC):
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._bot = bot
|
||||
self._clients = clients
|
||||
self._db = db
|
||||
|
||||
async def delete_messages(self, messages: List[discord.Message], guild_id: int):
|
||||
self._logger.debug(__name__, f'Try to delete {messages.count()} messages')
|
||||
server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{guild_id}')
|
||||
await asyncio.sleep(server_st.message_delete_timer)
|
||||
for message in messages:
|
||||
await self.delete_message(message, mass_delete=True)
|
||||
self._logger.debug(__name__, 'Deleting messages finished')
|
||||
|
||||
async def delete_message(self, message: discord.Message, mass_delete=False):
|
||||
server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{message.guild.id}')
|
||||
if not mass_delete:
|
||||
await asyncio.sleep(server_st.message_delete_timer)
|
||||
self._logger.debug(__name__, f'Try to delete message:\n\t{message}\n\t{message.content}')
|
||||
guild_id = message.guild.id
|
||||
try:
|
||||
await message.delete()
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Deleting message failed', e)
|
||||
else:
|
||||
self._clients.append_deleted_message_count(self._bot.user.id, guild_id, 1)
|
||||
self._db.save_changes()
|
||||
self._logger.info(__name__, f'Deleted message {message}')
|
||||
|
||||
async def send_channel_message(self, channel: discord.TextChannel, message: Union[str, discord.Embed]):
|
||||
self._logger.debug(__name__, f'Try to send message\n\t{message}\n\tto: {channel}')
|
||||
msg = None
|
||||
try:
|
||||
if isinstance(message, discord.Embed):
|
||||
msg = await channel.send(embed=message)
|
||||
else:
|
||||
msg = await channel.send(message)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Send message to channel {channel.id} failed', e)
|
||||
else:
|
||||
self._logger.info(__name__, f'Sent message to channel {channel.id}')
|
||||
self._clients.append_sent_message_count(self._bot.user.id, channel.guild.id, 1)
|
||||
self._db.save_changes()
|
||||
await self.delete_message(msg)
|
||||
|
||||
async def send_dm_message(self, message: Union[str, discord.Embed], receiver: Union[discord.User, discord.Member]):
|
||||
self._logger.debug(__name__, f'Try to send message\n\t{message}\n\tto: {receiver}')
|
||||
try:
|
||||
if isinstance(message, discord.Embed):
|
||||
msg = await receiver.send(embed=message)
|
||||
else:
|
||||
msg = await receiver.send(message)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Send message to user {receiver.id} failed', e)
|
||||
else:
|
||||
self._clients.append_sent_message_count(self._bot.user.id, receiver.guild.id, 1)
|
||||
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.Embed], file: discord.File = None, is_persistent: bool = False, wait_before_delete: int = None):
|
||||
if ctx is None:
|
||||
self._logger.warn(__name__, 'Message context is empty')
|
||||
self._logger.debug(__name__, f'Message: {message}')
|
||||
return
|
||||
|
||||
self._logger.debug(__name__, f'Try to send message\t\t{message}\n\tto: {ctx.channel}')
|
||||
msg = None
|
||||
try:
|
||||
if isinstance(message, discord.Embed):
|
||||
msg = await ctx.send(embed=message, file=file)
|
||||
else:
|
||||
msg = await ctx.send(message, file=file)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Send message to channel {ctx.channel.id} failed', e)
|
||||
else:
|
||||
self._logger.info(__name__, f'Sent message to channel {ctx.channel.id}')
|
||||
self._clients.append_sent_message_count(self._bot.user.id, ctx.guild.id, 1)
|
||||
self._db.save_changes()
|
||||
if wait_before_delete is not None:
|
||||
await asyncio.sleep(wait_before_delete)
|
||||
|
||||
if is_persistent:
|
||||
await self.delete_message(ctx.message)
|
||||
return
|
||||
|
||||
await self.delete_messages(List(discord.Message, [msg, ctx.message]), ctx.guild.id)
|
357
src/gismo_core/service/module_service.py
Normal file
357
src/gismo_core/service/module_service.py
Normal file
@ -0,0 +1,357 @@
|
||||
from abc import ABC, ABCMeta
|
||||
from datetime import datetime
|
||||
import json
|
||||
from typing import Optional, Sequence, Union, Type
|
||||
|
||||
import discord
|
||||
from cpl_core.configuration import ConfigurationModelABC, ConfigurationABC
|
||||
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, 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
|
||||
from gismo_core.abc.events.on_disconnect_abc import OnDisconnectABC
|
||||
from gismo_core.abc.events.on_group_join_abc import OnGroupJoinABC
|
||||
from gismo_core.abc.events.on_group_remove_abc import OnGroupRemoveABC
|
||||
from gismo_core.abc.events.on_guild_available_abc import OnGuildAvailableABC
|
||||
from gismo_core.abc.events.on_guild_channel_create_abc import OnGuildChannelCreateABC
|
||||
from gismo_core.abc.events.on_guild_channel_delete_abc import OnGuildChannelDeleteABC
|
||||
from gismo_core.abc.events.on_guild_channel_pins_update_abc import OnGuildChannelPinsUpdateABC
|
||||
from gismo_core.abc.events.on_guild_channel_update_abc import OnGuildChannelUpdateABC
|
||||
from gismo_core.abc.events.on_guild_emojis_update_abc import OnGuildEmojisUpdateABC
|
||||
from gismo_core.abc.events.on_guild_integrations_update_abc import OnGuildIntegrationsUpdateABC
|
||||
from gismo_core.abc.events.on_guild_join_abc import OnGuildJoinABC
|
||||
from gismo_core.abc.events.on_guild_remove_abc import OnGuildRemoveABC
|
||||
from gismo_core.abc.events.on_guild_role_create_abc import OnGuildRoleCreateABC
|
||||
from gismo_core.abc.events.on_guild_role_delete_abc import OnGuildRoleDeleteABC
|
||||
from gismo_core.abc.events.on_guild_role_update_abc import OnGuildRoleUpdateABC
|
||||
from gismo_core.abc.events.on_guild_unavailable_abc import OnGuildUnavailableABC
|
||||
from gismo_core.abc.events.on_guild_update_abc import OnGuildUpdateABC
|
||||
from gismo_core.abc.events.on_invite_create_abc import OnInviteCreateABC
|
||||
from gismo_core.abc.events.on_invite_delete_abc import OnInviteDeleteABC
|
||||
from gismo_core.abc.events.on_member_ban_abc import OnMemberBanABC
|
||||
from gismo_core.abc.events.on_member_join_abc import OnMemberJoinABC
|
||||
from gismo_core.abc.events.on_member_remove_abc import OnMemberRemoveABC
|
||||
from gismo_core.abc.events.on_member_unban_abc import OnMemberUnbanABC
|
||||
from gismo_core.abc.events.on_member_update_abc import OnMemberUpdateABC
|
||||
from gismo_core.abc.events.on_message_abc import OnMessageABC
|
||||
from gismo_core.abc.events.on_message_delete_abc import OnMessageDeleteABC
|
||||
from gismo_core.abc.events.on_message_edit_abc import OnMessageEditABC
|
||||
from gismo_core.abc.events.on_private_channel_create_abc import OnPrivateChannelCreateABC
|
||||
from gismo_core.abc.events.on_private_channel_delete_abc import OnPrivateChannelDeleteABC
|
||||
from gismo_core.abc.events.on_private_channel_pins_update_abc import OnPrivateChannelPinsUpdateABC
|
||||
from gismo_core.abc.events.on_private_channel_update_abc import OnPrivateChannelUpdateABC
|
||||
from gismo_core.abc.events.on_reaction_add_abc import OnReactionAddABC
|
||||
from gismo_core.abc.events.on_reaction_clear_abc import OnReactionClearABC
|
||||
from gismo_core.abc.events.on_reaction_clear_emoji_abc import OnReactionClearEmojiABC
|
||||
from gismo_core.abc.events.on_reaction_remove_abc import OnReactionRemoveABC
|
||||
from gismo_core.abc.events.on_ready_abc import OnReadyABC
|
||||
from gismo_core.abc.events.on_relationship_add_abc import OnRelationshipAddABC
|
||||
from gismo_core.abc.events.on_relationship_remove_abc import OnRelationshipRemoveABC
|
||||
from gismo_core.abc.events.on_relationship_update_abc import OnRelationshipUpdateABC
|
||||
from gismo_core.abc.events.on_resume_abc import OnResumeABC
|
||||
from gismo_core.abc.events.on_typing_abc import OnTypingABC
|
||||
from gismo_core.abc.events.on_user_update_abc import OnUserUpdateABC
|
||||
from gismo_core.abc.events.on_voice_state_update_abc import OnVoiceStateUpdateABC
|
||||
from gismo_core.abc.events.on_webhooks_update_abc import OnWebhooksUpdateABC
|
||||
from gismo_core.abc.module_abc import ModuleABC
|
||||
from gismo_core.abc.module_service_abc import ModuleServiceABC
|
||||
from gismo_core.commands_meta import CommandsMeta
|
||||
|
||||
|
||||
class ModuleService(ModuleServiceABC, commands.Cog, metaclass=CommandsMeta):
|
||||
|
||||
def __init__(self, logger: LoggerABC, config: ConfigurationABC, services: ServiceProviderABC, env: ApplicationEnvironmentABC):
|
||||
self._logger = logger
|
||||
self._config = config
|
||||
self._services = services
|
||||
self._env = env
|
||||
self._modules_types: List[Type[ModuleABC]] = List()
|
||||
self._modules_types.extend(ModuleABC.__subclasses__())
|
||||
self._modules: List[ModuleABC] = List(ModuleABC)
|
||||
|
||||
async def _handle_event(self, event: type, *args):
|
||||
self._logger.debug(__name__, f'Start {event} modules')
|
||||
# modules = self._get_modules(event)
|
||||
modules = self._modules.where(lambda m: isinstance(m, event)).order_by(lambda m: m.get_priority(event))
|
||||
|
||||
if modules.count() < 1:
|
||||
self._logger.debug(__name__, f'Stopped {event} modules')
|
||||
return
|
||||
|
||||
try:
|
||||
func_name = String.convert_to_snake_case(event.__name__.split('ABC')[0])
|
||||
for module in modules:
|
||||
self._logger.trace(__name__, f'Start {type(module)} module')
|
||||
func = getattr(module, func_name)
|
||||
await func(*args)
|
||||
if not module.success:
|
||||
self._logger.debug(__name__, f'Stopped propagation for {event} from {type(module)}')
|
||||
break
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Start {event} modules failed', e)
|
||||
|
||||
self._logger.debug(__name__, f'Stopped {event} modules')
|
||||
|
||||
def load_modules(self):
|
||||
self._logger.debug(__name__, f'Start loading modules')
|
||||
for module_type in self._modules_types:
|
||||
module: ModuleABC = self._services.get_service(module_type)
|
||||
if module is None:
|
||||
self._logger.warn(__name__, f'Module {module_type} not found in services!')
|
||||
break
|
||||
|
||||
loaded_settings: list[str] = []
|
||||
for settings_type in module.settings_types:
|
||||
settings_name = settings_type.__name__.split('Settings')[0]
|
||||
if settings_name in loaded_settings:
|
||||
continue
|
||||
|
||||
with open(f'config/{String.convert_to_snake_case(settings_name).lower()}.json', encoding='utf-8') as cfg:
|
||||
json_cfg = json.load(cfg)
|
||||
for index in json_cfg:
|
||||
settings: ConfigurationModelABC = settings_type()
|
||||
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}')
|
||||
|
||||
loaded_settings.append(settings_name)
|
||||
|
||||
self._modules.append(module)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_connect(self):
|
||||
self._logger.trace(__name__, f'Received on_connect')
|
||||
await self._handle_event(OnConnectABC)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_disconnect(self):
|
||||
self._logger.trace(__name__, f'Received on_disconnect')
|
||||
await self._handle_event(OnDisconnectABC)
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.trace(__name__, f'Received on_ready')
|
||||
await self._handle_event(OnReadyABC)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_resume(self):
|
||||
self._logger.trace(__name__, f'Received on_resume')
|
||||
await self._handle_event(OnResumeABC)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_error(self, event: str, *args, **kwargs):
|
||||
self._logger.trace(__name__, f'Received on_error:\n\t{event}\n\t{args}\n\t{kwargs}')
|
||||
await self._handle_event(OnReadyABC, event, *args, **kwargs)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_typing(self, channel: discord.abc.Messageable, user: Union[discord.User, discord.Member], when: datetime):
|
||||
self._logger.trace(__name__, f'Received on_typing:\n\t{channel}\n\t{user}\n\t{when}')
|
||||
await self._handle_event(OnTypingABC, channel, user, when)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message: discord.Message):
|
||||
self._logger.trace(__name__, f'Received on_message:\n\t{message}\n\t{message.content}')
|
||||
await self._handle_event(OnMessageABC, message)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message_delete(self, message: discord.Message):
|
||||
self._logger.trace(__name__, f'Received on_message_delete:\n\t{message}\n\t{message.content}')
|
||||
await self._handle_event(OnMessageDeleteABC, message)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_bulk_message_delete(self, messages: list[discord.Message]):
|
||||
self._logger.trace(__name__, f'Received on_bulk_message_delete:\n\t{len(messages)}')
|
||||
await self._handle_event(OnBulkMessageDeleteABC, messages)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message_edit(self, before: discord.Message, after: discord.Message):
|
||||
self._logger.trace(__name__, f'Received on_message_edit:\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnMessageEditABC, before, after)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_reaction_add(self, reaction: discord.Reaction, user: discord.User):
|
||||
self._logger.trace(__name__, f'Received on_reaction_add:\n\t{reaction}\n\t{user}')
|
||||
await self._handle_event(OnReactionAddABC, reaction, user)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_reaction_remove(self, reaction: discord.Reaction, user: discord.User):
|
||||
self._logger.trace(__name__, f'Received on_reaction_remove:\n\t{reaction}\n\t{user}')
|
||||
await self._handle_event(OnReactionRemoveABC, reaction, user)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_reaction_clear(self, message: discord.Message, reactions: list[discord.Reaction]):
|
||||
self._logger.trace(__name__, f'Received on_reaction_reon_reaction_clearmove:\n\t{message}\n\t{len(reactions)}')
|
||||
await self._handle_event(OnReactionClearABC, message, reactions)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_reaction_clear_emoji(self, reaction: discord.Reaction):
|
||||
self._logger.trace(__name__, f'Received on_reaction_clear_emoji:\n\t{reaction}')
|
||||
await self._handle_event(OnReactionClearEmojiABC, reaction)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_private_channel_delete(self, channel: discord.abc.PrivateChannel):
|
||||
self._logger.trace(__name__, f'Received on_private_channel_delete:\n\t{channel}')
|
||||
await self._handle_event(OnPrivateChannelDeleteABC, channel)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_private_channel_create(self, channel: discord.abc.PrivateChannel):
|
||||
self._logger.trace(__name__, f'Received on_private_channel_create:\n\t{channel}')
|
||||
await self._handle_event(OnPrivateChannelCreateABC, channel)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_private_channel_update(self, before: discord.GroupChannel, after: discord.GroupChannel):
|
||||
self._logger.trace(__name__, f'Received on_private_channel_update:\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnPrivateChannelUpdateABC, before, after)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_private_channel_pins_update(self, channel: discord.abc.PrivateChannel, list_pin: Optional[datetime]):
|
||||
self._logger.trace(__name__, f'Received on_private_channel_pins_update:\n\t{channel}\n\t{list_pin}')
|
||||
await self._handle_event(OnPrivateChannelPinsUpdateABC, channel, list_pin)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_channel_delete(self, channel: discord.abc.GuildChannel):
|
||||
self._logger.trace(__name__, f'Received on_guild_channel_delete:\n\t{channel}')
|
||||
await self._handle_event(OnGuildChannelDeleteABC, channel)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_channel_create(self, channel: discord.abc.GuildChannel):
|
||||
self._logger.trace(__name__, f'Received on_guild_channel_create:\n\t{channel}')
|
||||
await self._handle_event(OnGuildChannelCreateABC, channel)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_channel_update(self, before: discord.abc.GuildChannel, after: discord.abc.GuildChannel):
|
||||
self._logger.trace(__name__, f'Received on_guild_channel_update:\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnGuildChannelUpdateABC, before, after)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_channel_pins_update(self, channel: discord.abc.GuildChannel, list_pin: Optional[datetime]):
|
||||
self._logger.trace(__name__, f'Received on_guild_channel_pins_update:\n\t{channel}\n\t{list_pin}')
|
||||
await self._handle_event(OnGuildChannelPinsUpdateABC, channel, list_pin)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_integrations_update(self, guild: discord.Guild):
|
||||
self._logger.trace(__name__, f'Received on_guild_integrations_update:\n\t{guild}')
|
||||
await self._handle_event(OnGuildIntegrationsUpdateABC, guild)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_webhooks_update(self, channel: discord.abc.GuildChannel):
|
||||
self._logger.trace(__name__, f'Received on_webhooks_update:\n\t{channel}')
|
||||
await self._handle_event(OnWebhooksUpdateABC, channel)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_join(self, member: discord.Member):
|
||||
self._logger.trace(__name__, f'Received on_member_join:\n\t{member}')
|
||||
await self._handle_event(OnMemberJoinABC, member)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_remove(self, member: discord.Member):
|
||||
self._logger.trace(__name__, f'Received on_member_remove:\n\t{member}')
|
||||
await self._handle_event(OnMemberRemoveABC, member)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_update(self, before: discord.Member, after: discord.Member):
|
||||
self._logger.trace(__name__, f'Received on_member_update:\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnMemberUpdateABC, before, after)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_user_update(self, before: discord.User, after: discord.User):
|
||||
self._logger.trace(__name__, f'Received on_user_update:\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnUserUpdateABC, before, after)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_join(self, guild: discord.Guild):
|
||||
self._logger.trace(__name__, f'Received on_guild_join:\n\t{guild}')
|
||||
await self._handle_event(OnGuildJoinABC, guild)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_remove(self, guild: discord.Guild):
|
||||
self._logger.trace(__name__, f'Received on_guild_remove:\n\t{guild}')
|
||||
await self._handle_event(OnGuildRemoveABC, guild)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_update(self, before: discord.Guild, after: discord.Guild):
|
||||
self._logger.trace(__name__, f'Received on_guild_update:\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnGuildUpdateABC, before, after)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_role_create(self, role: discord.Role):
|
||||
self._logger.trace(__name__, f'Received on_guild_role_create:\n\t{role}')
|
||||
await self._handle_event(OnGuildRoleCreateABC, role)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_role_delete(self, role: discord.Role):
|
||||
self._logger.trace(__name__, f'Received on_guild_role_delete:\n\t{role}')
|
||||
await self._handle_event(OnGuildRoleDeleteABC, role)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_role_update(self, before: discord.Role, after: discord.Role):
|
||||
self._logger.trace(__name__, f'Received on_guild_role_update:\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnGuildRoleUpdateABC, before, after)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_emojis_update(self, guild: discord.Guild, before: Sequence[discord.Emoji], after: Sequence[discord.Emoji]):
|
||||
self._logger.trace(__name__, f'Received on_guild_emojis_update:\n\t{guild}\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnGuildEmojisUpdateABC, guild, before, after)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_available(self, guild: discord.Guild):
|
||||
self._logger.trace(__name__, f'Received on_guild_available:\n\t{guild}')
|
||||
await self._handle_event(OnGuildAvailableABC, guild)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_unavailable(self, guild: discord.Guild):
|
||||
self._logger.trace(__name__, f'Received on_guild_unavailable:\n\t{guild}')
|
||||
await self._handle_event(OnGuildUnavailableABC, guild)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState):
|
||||
self._logger.trace(__name__, f'Received on_voice_state_update:\n\t{member}\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnVoiceStateUpdateABC, member, before, after)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_ban(self, guild: discord.Guild, user: discord.User):
|
||||
self._logger.trace(__name__, f'Received on_member_ban:\n\t{guild}\n\t{user}')
|
||||
await self._handle_event(OnMemberBanABC, guild, user)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_unban(self, guild: discord.Guild, user: discord.User):
|
||||
self._logger.trace(__name__, f'Received on_member_unban:\n\t{guild}\n\t{user}')
|
||||
await self._handle_event(OnMemberUnbanABC, guild, user)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_invite_create(self, invite: discord.Invite):
|
||||
self._logger.trace(__name__, f'Received on_invite_create:\n\t{invite}')
|
||||
await self._handle_event(OnInviteCreateABC, invite)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_invite_delete(self, invite: discord.Invite):
|
||||
self._logger.trace(__name__, f'Received on_invite_create:\n\t{invite}')
|
||||
await self._handle_event(OnInviteDeleteABC, invite)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_group_join(self, channel: discord.GroupChannel, user: discord.User):
|
||||
self._logger.trace(__name__, f'Received on_group_join:\n\t{channel}\n\t{user}')
|
||||
await self._handle_event(OnGroupJoinABC, channel, user)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_group_remove(self, channel: discord.GroupChannel, user: discord.User):
|
||||
self._logger.trace(__name__, f'Received on_group_remove:\n\t{channel}\n\t{user}')
|
||||
await self._handle_event(OnGroupRemoveABC, channel, user)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_relationship_add(self, relationship: discord.Relationship):
|
||||
self._logger.trace(__name__, f'Received on_relationship_add:\n\t{relationship}')
|
||||
await self._handle_event(OnRelationshipAddABC, relationship)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_relationship_remove(self, relationship: discord.Relationship):
|
||||
self._logger.trace(__name__, f'Received on_relationship_remove:\n\t{relationship}')
|
||||
await self._handle_event(OnRelationshipRemoveABC, relationship)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_relationship_update(self, before: discord.Relationship, after: discord.Relationship):
|
||||
self._logger.trace(__name__, f'Received on_relationship_update:\n\t{before}\n\t{after}')
|
||||
await self._handle_event(OnRelationshipUpdateABC, before, after)
|
25
src/gismo_data/__init__.py
Normal file
25
src/gismo_data/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
gismo sh-edraft Gismo
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Dicord bot Gismo
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'gismo_data'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '0.4.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='4', micro='2')
|
25
src/gismo_data/abc/__init__.py
Normal file
25
src/gismo_data/abc/__init__.py
Normal file
@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
gismo sh-edraft Gismo
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Dicord bot Gismo
|
||||
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'gismo_data.abc'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '0.4.2'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='0', minor='4', micro='2')
|
53
src/gismo_data/abc/client_repository_abc.py
Normal file
53
src/gismo_data/abc/client_repository_abc.py
Normal file
@ -0,0 +1,53 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
from gismo_data.model.client import Client
|
||||
|
||||
|
||||
class ClientRepositoryABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_clients(self) -> List[Client]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_client_by_id(self, client_id: int) -> Client: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_client_by_discord_id(self, discord_id: int) -> Client: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_client_by_server_id(self, server_id: int) -> Optional[Client]: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_client_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[Client]: pass
|
||||
|
||||
@abstractmethod
|
||||
def add_client(self, client: Client): pass
|
||||
|
||||
@abstractmethod
|
||||
def update_client(self, client: Client): pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_client(self, client: Client): pass
|
||||
|
||||
@abstractmethod
|
||||
def append_sent_message_count(self, client_id: int, server_id: int, value: int): pass
|
||||
|
||||
@abstractmethod
|
||||
def append_received_message_count(self, client_id: int, server_id: int, value: int): pass
|
||||
|
||||
@abstractmethod
|
||||
def append_deleted_message_count(self, client_id: int, server_id: int, value: int): pass
|
||||
|
||||
@abstractmethod
|
||||
def append_received_command_count(self, client_id: int, server_id: int, value: int): pass
|
||||
|
||||
@abstractmethod
|
||||
def append_moved_users_count(self, client_id: int, server_id: int, value: int): pass
|
30
src/gismo_data/abc/known_user_repository_abc.py
Normal file
30
src/gismo_data/abc/known_user_repository_abc.py
Normal file
@ -0,0 +1,30 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from gismo_data.model.known_user import KnownUser
|
||||
|
||||
|
||||
class KnownUserRepositoryABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users(self) -> List[KnownUser]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_id(self, id: int) -> KnownUser: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_discord_id(self, discord_id: int) -> KnownUser: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_by_discord_id(self, discord_id: int) -> Optional[KnownUser]: pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user(self, known_user: KnownUser): pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user(self, known_user: KnownUser): pass
|
13
src/gismo_data/abc/migration_abc.py
Normal file
13
src/gismo_data/abc/migration_abc.py
Normal file
@ -0,0 +1,13 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class MigrationABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def upgrade(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def downgrade(self): pass
|
33
src/gismo_data/abc/server_repository_abc.py
Normal file
33
src/gismo_data/abc/server_repository_abc.py
Normal file
@ -0,0 +1,33 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from gismo_data.model.server import Server
|
||||
|
||||
|
||||
class ServerRepositoryABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_servers(self) -> List[Server]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_server_by_id(self, id: int) -> Server: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_server_by_discord_id(self, discord_id: int) -> Server: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_server_by_discord_id(self, discord_id: int) -> Optional[Server]: pass
|
||||
|
||||
@abstractmethod
|
||||
def add_server(self, server: Server): pass
|
||||
|
||||
@abstractmethod
|
||||
def update_server(self, server: Server): pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_server(self, server: Server): pass
|
35
src/gismo_data/abc/user_joined_server_repository_abc.py
Normal file
35
src/gismo_data/abc/user_joined_server_repository_abc.py
Normal file
@ -0,0 +1,35 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
from gismo_data.model.user_joined_server import UserJoinedServer
|
||||
|
||||
|
||||
class UserJoinedServerRepositoryABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_servers(self) -> List[UserJoinedServer]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_server_by_id(self, id: int) -> UserJoinedServer: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_servers_by_user_id(self, user_id: int) -> list[UserJoinedServer]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_active_user_joined_server_by_user_id(self, user_id: int) -> UserJoinedServer: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_server_by_user_id(self, user_id: int) -> Optional[UserJoinedServer]: pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_joined_server(self, user_joined_server: UserJoinedServer): pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_joined_server(self, user_joined_server: UserJoinedServer): pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_joined_server(self, user_joined_server: UserJoinedServer): pass
|
37
src/gismo_data/abc/user_joined_voice_channel_abc.py
Normal file
37
src/gismo_data/abc/user_joined_voice_channel_abc.py
Normal file
@ -0,0 +1,37 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel
|
||||
|
||||
class UserJoinedVoiceChannelRepositoryABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_voice_channels(self) -> List[UserJoinedVoiceChannel]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_voice_channel_by_id(self, id: int) -> UserJoinedVoiceChannel: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_joined_voice_channels_by_user_id(self, user_id: int) -> list[UserJoinedVoiceChannel]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_active_user_joined_voice_channel_by_user_id(self, user_id: int) -> UserJoinedVoiceChannel: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_voice_channel_by_user_id(self, user_id: int) -> Optional[UserJoinedVoiceChannel]: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_active_user_joined_voice_channels_by_user_id(self, user_id: int) -> List[Optional[UserJoinedVoiceChannel]]: pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel): pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel): pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel): pass
|
36
src/gismo_data/abc/user_repository_abc.py
Normal file
36
src/gismo_data/abc/user_repository_abc.py
Normal file
@ -0,0 +1,36 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from gismo_data.model.user import User
|
||||
|
||||
|
||||
class UserRepositoryABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users(self) -> List[User]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_id(self, id: int) -> User: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users_by_discord_id(self, discord_id: int) -> List[User]: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[User]: pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user(self, user: User): pass
|
||||
|
||||
@abstractmethod
|
||||
def update_user(self, user: User): pass
|
||||
|
||||
@abstractmethod
|
||||
def delete_user(self, user: User): pass
|
33
src/gismo_data/db_context.py
Normal file
33
src/gismo_data/db_context.py
Normal file
@ -0,0 +1,33 @@
|
||||
from cpl_core.database import DatabaseSettings
|
||||
from cpl_core.database.context import DatabaseContext
|
||||
from cpl_core.logging import LoggerABC
|
||||
|
||||
|
||||
class DBContext(DatabaseContext):
|
||||
|
||||
def __init__(self, logger: LoggerABC):
|
||||
|
||||
self._logger = logger
|
||||
|
||||
DatabaseContext.__init__(self)
|
||||
|
||||
def connect(self, database_settings: DatabaseSettings):
|
||||
try:
|
||||
self._logger.debug(__name__, "Connecting to database")
|
||||
self._db.connect(database_settings)
|
||||
|
||||
self.save_changes()
|
||||
self._logger.info(__name__, "Connected to database")
|
||||
except Exception as e:
|
||||
self._logger.fatal(__name__, "Connecting to database failed", e)
|
||||
|
||||
def save_changes(self):
|
||||
try:
|
||||
self._logger.trace(__name__, "Save changes")
|
||||
super(DBContext, self).save_changes()
|
||||
self._logger.debug(__name__, "Saved changes")
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, "Saving changes failed", e)
|
||||
|
||||
def select(self, statement: str) -> list[tuple]:
|
||||
return super(DBContext, self).select(statement)
|
44
src/gismo_data/gismo-data.json
Normal file
44
src/gismo_data/gismo-data.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "gismo-data",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "1",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
"Description": "sh-edraft Gismo - data",
|
||||
"LongDescription": "sh-edraft Dicord bot Gismo - data library",
|
||||
"URL": "https://www.sh-edraft.de",
|
||||
"CopyrightDate": "2021 - 2022",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"sh_cpl-core>=2021.11.0",
|
||||
"sh_cpl-query>=2021.11.0"
|
||||
],
|
||||
"PythonVersion": ">=3.9.2",
|
||||
"PythonPath": {
|
||||
"linux": "../../venv/bin/python"
|
||||
},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"ProjectType": "library",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "",
|
||||
"EntryPoint": "",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user