From a79358725c0274ad160d627cc02a60def1fade87 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sat, 16 Jul 2022 12:12:52 +0200 Subject: [PATCH] Added cpl-discord project --- cpl-workspace.json | 28 ++++++++--- src/cpl_discord/__init__.py | 1 + src/cpl_discord/command/__init__.py | 0 src/cpl_discord/command/command_abc.py | 11 +++++ src/cpl_discord/command/commands_meta.py | 5 ++ src/cpl_discord/configuration/__init__.py | 1 + src/cpl_discord/configuration/bot_settings.py | 29 +++++++++++ src/cpl_discord/cpl-discord.json | 48 +++++++++++++++++++ src/cpl_discord/events/__init__.py | 0 src/cpl_discord/service/__init__.py | 0 src/cpl_discord/service/bot_service_abc.py | 16 +++++++ 11 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 src/cpl_discord/__init__.py create mode 100644 src/cpl_discord/command/__init__.py create mode 100644 src/cpl_discord/command/command_abc.py create mode 100644 src/cpl_discord/command/commands_meta.py create mode 100644 src/cpl_discord/configuration/__init__.py create mode 100644 src/cpl_discord/configuration/bot_settings.py create mode 100644 src/cpl_discord/cpl-discord.json create mode 100644 src/cpl_discord/events/__init__.py create mode 100644 src/cpl_discord/service/__init__.py create mode 100644 src/cpl_discord/service/bot_service_abc.py diff --git a/cpl-workspace.json b/cpl-workspace.json index e4b287c3..d07c8cae 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -2,8 +2,9 @@ "WorkspaceSettings": { "DefaultProject": "cpl-cli", "Projects": { - "cpl-core": "src/cpl_core/cpl-core.json", "cpl-cli": "src/cpl_cli/cpl-cli.json", + "cpl-core": "src/cpl_core/cpl-core.json", + "cpl-discord": "src/cpl_discord/cpl-discord.json", "cpl-query": "src/cpl_query/cpl-query.json", "cpl-translation": "src/cpl_translation/cpl-translation.json", "set-version": "tools/set_version/set-version.json", @@ -33,20 +34,22 @@ "test": "cpl run unittests", "pre-build-all": "cpl sv $ARGS; cpl spu $ARGS;", - "build-all": "cpl build-cli; cpl build-core; cpl build-query; cpl build-translation; cpl build-set-pip-urls; cpl build-set-version", + "build-all": "cpl build-cli; cpl build-core; cpl build-discord; cpl build-query; cpl build-translation; cpl build-set-pip-urls; cpl build-set-version", "ba": "cpl build-all $ARGS", "build-cli": "echo 'Build cpl-cli'; cd ./src/cpl_cli; cpl build; cd ../../;", "build-core": "echo 'Build cpl-core'; cd ./src/cpl_core; cpl build; cd ../../;", + "build-discord": "echo 'Build cpl-discord'; cd ./src/cpl_discord; cpl build; cd ../../;", "build-query": "echo 'Build cpl-query'; cd ./src/cpl_query; cpl build; cd ../../;", "build-translation": "echo 'Build cpl-translation'; cd ./src/cpl_translation; cpl build; cd ../../;", "build-set-pip-urls": "echo 'Build set-pip-urls'; cd ./tools/set_pip_urls; cpl build; cd ../../;", "build-set-version": "echo 'Build set-version'; cd ./tools/set_version; cpl build; cd ../../;", "pre-publish-all": "cpl sv $ARGS; cpl spu $ARGS;", - "publish-all": "cpl publish-cli; cpl publish-core; cpl publish-query; cpl publish-translation;", + "publish-all": "cpl publish-cli; cpl publish-core; cpl publish-discord; cpl publish-query; cpl publish-translation;", "pa": "cpl build-all $ARGS", "publish-cli": "echo 'Publish cpl-cli'; cd ./src/cpl_cli; cpl publish; cd ../../;", "publish-core": "echo 'Publish cpl-core'; cd ./src/cpl_core; cpl publish; cd ../../;", + "publish-discord": "echo 'Publish cpl-discord'; cd ./src/cpl_discord; cpl publish; cd ../../;", "publish-query": "echo 'Publish cpl-query'; cd ./src/cpl_query; cpl publish; cd ../../;", "publish-translation": "echo 'Publish cpl-translation'; cd ./src/cpl_translation; cpl publish; cd ../../;", @@ -56,6 +59,9 @@ "upload-prod-core": "echo 'PROD Upload cpl-core'; cpl upl-prod-core;", "upl-prod-core": "twine upload -r pip.sh-edraft.de dist/cpl-core/publish/setup/*", + "upload-prod-discord": "echo 'PROD Upload cpl-discord'; cpl upl-prod-discord;", + "upl-prod-discord": "twine upload -r pip.sh-edraft.de dist/cpl-discord/publish/setup/*", + "upload-prod-query": "echo 'PROD Upload cpl-query'; cpl upl-prod-query;", "upl-prod-query": "twine upload -r pip.sh-edraft.de dist/cpl-query/publish/setup/*", @@ -68,6 +74,9 @@ "upload-exp-core": "echo 'EXP Upload cpl-core'; cpl upl-exp-core;", "upl-exp-core": "twine upload -r pip-exp.sh-edraft.de dist/cpl-core/publish/setup/*", + "upload-exp-discord": "echo 'EXP Upload cpl-discord'; cpl upl-exp-discord;", + "upl-exp-discord": "twine upload -r pip-exp.sh-edraft.de dist/cpl-discord/publish/setup/*", + "upload-exp-query": "echo 'EXP Upload cpl-query'; cpl upl-exp-query;", "upl-exp-query": "twine upload -r pip-exp.sh-edraft.de dist/cpl-query/publish/setup/*", @@ -80,6 +89,9 @@ "upload-dev-core": "echo 'DEV Upload cpl-core'; cpl upl-dev-core;", "upl-dev-core": "twine upload -r pip-dev.sh-edraft.de dist/cpl-core/publish/setup/*", + "upload-dev-discord": "echo 'DEV Upload cpl-discord'; cpl upl-dev-discord;", + "upl-dev-discord": "twine upload -r pip-dev.sh-edraft.de dist/cpl-discord/publish/setup/*", + "upload-dev-query": "echo 'DEV Upload cpl-query'; cpl upl-dev-query;", "upl-dev-query": "twine upload -r pip-dev.sh-edraft.de dist/cpl-query/publish/setup/*", @@ -87,26 +99,29 @@ "upl-dev-translation": "twine upload -r pip-dev.sh-edraft.de dist/cpl-translation/publish/setup/*", "pre-deploy-prod": "cpl sv $ARGS; cpl spu --environment=production;", - "deploy-prod": "cpl deploy-prod-cli; cpl deploy-prod-core; cpl deploy-prod-query; cpl deploy-prod-translation;", + "deploy-prod": "cpl deploy-prod-cli; cpl deploy-prod-core; cpl deploy-prod-discord; cpl deploy-prod-query; cpl deploy-prod-translation;", "dp": "cpl deploy-prod $ARGS", "deploy-prod-cli": "cpl publish-cli; cpl upload-prod-cli", "deploy-prod-core": "cpl publish-core; cpl upload-prod-core", "deploy-prod-query": "cpl publish-query; cpl upload-prod-query", + "deploy-prod-discord": "cpl publish-discord; cpl upload-prod-discord", "deploy-prod-translation": "cpl publish-translation; cpl upload-prod-translation", "pre-deploy-exp": "cpl sv $ARGS; cpl spu --environment=staging;", - "deploy-exp": "cpl deploy-exp-cli; cpl deploy-exp-core; cpl deploy-exp-query; cpl deploy-exp-translation;", + "deploy-exp": "cpl deploy-exp-cli; cpl deploy-exp-core; cpl deploy-exp-discord; cpl deploy-exp-query; cpl deploy-exp-translation;", "de": "cpl deploy-exp $ARGS", "deploy-exp-cli": "cpl publish-cli; cpl upload-exp-cli", "deploy-exp-core": "cpl publish-core; cpl upload-exp-core", + "deploy-exp-discord": "cpl publish-discord; cpl upload-exp-discord", "deploy-exp-query": "cpl publish-query; cpl upload-exp-query", "deploy-exp-translation": "cpl publish-translation; cpl upload-exp-translation", "pre-deploy-dev": "cpl sv $ARGS; cpl spu --environment=development;", - "deploy-dev": "cpl deploy-dev-cli; cpl deploy-dev-core; cpl deploy-dev-query; cpl deploy-dev-translation;", + "deploy-dev": "cpl deploy-dev-cli; cpl deploy-dev-core; cpl deploy-dev-discord; cpl deploy-dev-query; cpl deploy-dev-translation;", "dd": "cpl deploy-dev $ARGS", "deploy-dev-cli": "cpl publish-cli; cpl upload-dev-cli", "deploy-dev-core": "cpl publish-core; cpl upload-dev-core", + "deploy-dev-discord": "cpl publish-discord; cpl upload-dev-discord", "deploy-dev-query": "cpl publish-query; cpl upload-dev-query", "deploy-dev-translation": "cpl publish-query; cpl upload-dev-translation", @@ -114,6 +129,7 @@ "di": "cpl dev-install", "di-core": "pip install cpl-core --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de", "di-cli": "pip install cpl-cli --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de", + "di-discord": "pip install cpl-discord --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de", "di-query": "pip install cpl-query --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de", "di-translation": "pip install cpl-translation --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de" } diff --git a/src/cpl_discord/__init__.py b/src/cpl_discord/__init__.py new file mode 100644 index 00000000..425ab6c1 --- /dev/null +++ b/src/cpl_discord/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/cpl_discord/command/__init__.py b/src/cpl_discord/command/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/cpl_discord/command/command_abc.py b/src/cpl_discord/command/command_abc.py new file mode 100644 index 00000000..b8dc17ca --- /dev/null +++ b/src/cpl_discord/command/command_abc.py @@ -0,0 +1,11 @@ +from abc import ABC, abstractmethod + +from discord.ext import commands + +from commands_meta import CommandsMeta + + +class CommandABC(ABC, commands.Cog, metaclass=CommandsMeta): + + @abstractmethod + def __init__(self): pass diff --git a/src/cpl_discord/command/commands_meta.py b/src/cpl_discord/command/commands_meta.py new file mode 100644 index 00000000..8b66f164 --- /dev/null +++ b/src/cpl_discord/command/commands_meta.py @@ -0,0 +1,5 @@ +from abc import ABCMeta +from discord.ext import commands + + +class CommandsMeta(ABCMeta, commands.CogMeta): pass diff --git a/src/cpl_discord/configuration/__init__.py b/src/cpl_discord/configuration/__init__.py new file mode 100644 index 00000000..425ab6c1 --- /dev/null +++ b/src/cpl_discord/configuration/__init__.py @@ -0,0 +1 @@ +# imports diff --git a/src/cpl_discord/configuration/bot_settings.py b/src/cpl_discord/configuration/bot_settings.py new file mode 100644 index 00000000..7b151d36 --- /dev/null +++ b/src/cpl_discord/configuration/bot_settings.py @@ -0,0 +1,29 @@ +import traceback + +from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC +from cpl_core.console import Console + + +class BotSettings(ConfigurationModelABC): + + def __init__(self): + ConfigurationModelABC.__init__(self) + + self._token = '' + self._prefix = '' + + @property + def token(self) -> str: + return self._token + + @property + def prefix(self) -> str: + return self._prefix + + def from_dict(self, settings: dict): + try: + self._token = settings['Token'] + self._prefix = settings['Prefix'] + except Exception as e: + Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {__name__} settings') + Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') diff --git a/src/cpl_discord/cpl-discord.json b/src/cpl_discord/cpl-discord.json new file mode 100644 index 00000000..09b9df18 --- /dev/null +++ b/src/cpl_discord/cpl-discord.json @@ -0,0 +1,48 @@ +{ + "ProjectSettings": { + "Name": "cpl-discord", + "Version": { + "Major": "2022", + "Minor": "7", + "Micro": "0" + }, + "Author": "Sven Heidemann", + "AuthorEmail": "sven.heidemann@sh-edraft.de", + "Description": "sh-edraft Common Python library Discord", + "LongDescription": "sh-edraft Common Python library link between discord.py and CPL", + "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.7.0", + "discord.py==1.7.3", + "cpl-query==2022.6.0" + ], + "DevDependencies": [ + "cpl-cli>=2022.7.0" + ], + "PythonVersion": ">=3.10.4", + "PythonPath": { + "linux": "" + }, + "Classifiers": [] + }, + "BuildSettings": { + "ProjectType": "library", + "SourcePath": "", + "OutputPath": "../../dist", + "Main": "cpl_discord.main", + "EntryPoint": "cpl-discord", + "IncludePackageData": false, + "Included": [], + "Excluded": [ + "*/__pycache__", + "*/logs", + "*/tests" + ], + "PackageData": {}, + "ProjectReferences": [] + } +} \ No newline at end of file diff --git a/src/cpl_discord/events/__init__.py b/src/cpl_discord/events/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/cpl_discord/service/__init__.py b/src/cpl_discord/service/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/cpl_discord/service/bot_service_abc.py b/src/cpl_discord/service/bot_service_abc.py new file mode 100644 index 00000000..91f714d6 --- /dev/null +++ b/src/cpl_discord/service/bot_service_abc.py @@ -0,0 +1,16 @@ +from abc import ABC, abstractmethod + +import discord +from discord.ext import commands + + +class BotServiceABC(ABC, commands.Bot): + + def __init__(self): + ABC.__init__(self) + + @abstractmethod + async def start_async(self): pass + + @abstractmethod + async def stop_async(self): pass