Compare commits
130 Commits
54b0086a14
...
1.0.7
Author | SHA1 | Date | |
---|---|---|---|
ff009ffb61 | |||
074b03eecf | |||
5ea698ef97 | |||
400e54a501 | |||
3c0233e8b3 | |||
8d2ae38d85 | |||
2b866b5ab1 | |||
4da87ae3cb | |||
1ebad89c97 | |||
b8320c83fe | |||
0ee26ccf3d | |||
31ca9cd8f4 | |||
089de53136 | |||
280b22af55 | |||
ebdf375283 | |||
c058312af7 | |||
2befa921ea | |||
1792359e68 | |||
faaf14d63e | |||
49d1ec75c8 | |||
629556b5fc | |||
9ece541e52 | |||
fd51db8cac | |||
2005d93f44 | |||
010dafc655 | |||
bea9dd1590 | |||
ef0da25f11 | |||
c01a6b97fe | |||
059bd3aaf1 | |||
a9d180fdf1 | |||
c71b1092f2 | |||
c1e8274f46 | |||
583218b215 | |||
e05e67785b | |||
72d3ccded3 | |||
f30bd119df | |||
858fc062b3 | |||
6d622a70d3 | |||
4a0a6a4631 | |||
17c2acd77c | |||
27363522d3 | |||
1960b18058 | |||
91034cee09 | |||
a4d3cffa93 | |||
809c6d4cb9 | |||
2fecbf2c31 | |||
c439d5925f | |||
1777a32899 | |||
3e5301b2d8 | |||
653562b908 | |||
8025c31339 | |||
ccf41bec79 | |||
f75d8f2068 | |||
da02aca7e4 | |||
3762f16c7e | |||
b3099121ab | |||
6a750ee31b | |||
3c371ec074 | |||
d818eafb9d | |||
b4a5fdb258 | |||
cf69436168 | |||
ccf171e876 | |||
5a312bf660 | |||
0003255d7c | |||
27a4c140e4 | |||
3183461195 | |||
cb4f8d870c | |||
7c447bb0f2 | |||
4debe4e2ba | |||
3cd3df3e5f | |||
b4a631d4e4 | |||
7ba0247519 | |||
209e75fdcc | |||
3bca3f86eb | |||
657a8fa586 | |||
3c8a092f40 | |||
61bf508cea | |||
75ad07477a | |||
132d41f0a2 | |||
707a835672 | |||
f56dbf8e2a | |||
c311e534d7 | |||
87b277515c | |||
e6c614dfdc | |||
24d5bbf4d8 | |||
52035af0cc | |||
fdc9a118c8 | |||
ba1f4ee955 | |||
35d161c080 | |||
818163cbed | |||
468ebb5f79 | |||
085726bf60 | |||
223abbe66f | |||
4c5a8baed5 | |||
59162408e5 | |||
634b81d23b | |||
c0cd5bb70e | |||
cc0a0a5c69 | |||
4420c0e11c | |||
7be40ed236 | |||
ff415c354d | |||
283eaabef6 | |||
b7e72888f7 | |||
b29227e8d5 | |||
9f57182fc1 | |||
699377be54 | |||
efba1a4ce8 | |||
68fa1b8c2d | |||
8b79d69e41 | |||
c1b75dff78 | |||
5f284597aa | |||
e1b1a68b07 | |||
b1a0115e8b | |||
ad00dce5d9 | |||
e3c47ce5b1 | |||
68026e4b47 | |||
ee503f76f2 | |||
a1f7b8b2dc | |||
b8e4146b33 | |||
51f0ee5744 | |||
69ce659328 | |||
325a17b5a8 | |||
5df0501505 | |||
c3ef7a746f | |||
bca33c6e56 | |||
d24d3fa4de | |||
1755efb5d9 | |||
e1c89814da | |||
53cdaf3fa0 | |||
b11ce18ac9 |
9
LICENSE
9
LICENSE
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022-2023 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 in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
@@ -14,6 +14,7 @@
|
||||
"level": "src/modules/level/level.json",
|
||||
"permission": "src/modules/permission/permission.json",
|
||||
"technician": "src/modules/technician/technician.json",
|
||||
"checks": "tools/checks/checks.json",
|
||||
"get-version": "tools/get_version/get-version.json",
|
||||
"post-build": "tools/post_build/post-build.json",
|
||||
"set-version": "tools/set_version/set-version.json"
|
||||
|
Submodule kdb-bot/docker updated: 22b8bce69b...62475d6546
@@ -15,4 +15,7 @@ RUN apk add nano
|
||||
RUN pip install -r requirements.txt --extra-index-url https://pip.sh-edraft.de
|
||||
RUN pip install flask[async]
|
||||
|
||||
# RUN pip install dnspython==2.2.1 # https://stackoverflow.com/questions/75137717/eventlet-dns-python-attribute-error-module-dns-rdtypes-has-no-attribute-any
|
||||
# ^ probably fixed py package updates
|
||||
|
||||
CMD [ "bash", "/app/bot/bot"]
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -52,7 +52,7 @@ class Application(DiscordBotApplicationABC):
|
||||
self._api.join()
|
||||
return
|
||||
|
||||
self._logger.trace(__name__, f"Try to start {DiscordBotService.__name__}")
|
||||
self._logger.info(__name__, f"Try to start {DiscordBotService.__name__}")
|
||||
await self._bot.start_async()
|
||||
await self._bot.stop_async()
|
||||
except Exception as e:
|
||||
@@ -64,9 +64,12 @@ class Application(DiscordBotApplicationABC):
|
||||
|
||||
self._is_stopping = True
|
||||
try:
|
||||
self._logger.trace(__name__, f"Try to stop {DiscordBotService.__name__}")
|
||||
self._logger.info(__name__, f"Try to stop {DiscordBotService.__name__}")
|
||||
if self._feature_flags.get_flag(FeatureFlagsEnum.api_module):
|
||||
self._api.stop()
|
||||
|
||||
await self._bot.close()
|
||||
self._logger.trace(__name__, f"Stopped {DiscordBotService.__name__}")
|
||||
self._logger.info(__name__, f"Stopped {DiscordBotService.__name__}")
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, "stop failed", e)
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0.rc1"
|
||||
"Micro": "7"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@@ -18,7 +18,8 @@
|
||||
"Dependencies": [
|
||||
"cpl-core==2022.12.1.post3",
|
||||
"cpl-translation==2022.12.1",
|
||||
"cpl-query==2022.12.2.post1",
|
||||
"cpl-query==2022.12.2.post2",
|
||||
"cpl-discord==2022.12.2.post1",
|
||||
"Flask==2.2.2",
|
||||
"Flask-Classful==0.14.2",
|
||||
"Flask-Cors==3.0.10",
|
||||
@@ -28,8 +29,7 @@
|
||||
"eventlet==0.33.3",
|
||||
"requests-oauthlib==1.3.1",
|
||||
"icmplib==3.0.3",
|
||||
"ariadne==0.17.1",
|
||||
"cpl-discord==2022.12.2"
|
||||
"ariadne==0.17.1"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli==2022.12.1.post3",
|
||||
|
Submodule kdb-bot/src/bot/config updated: 781aa3f6ab...0c94637537
@@ -15,7 +15,7 @@ __title__ = "bot.extension"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -39,6 +39,7 @@ class Program:
|
||||
)
|
||||
self.app: Application = await app_builder.build_async()
|
||||
await self.app.run_async()
|
||||
Console.write_line(f"[ INFO ] [ {__name__} ]: Finished app.run_async")
|
||||
|
||||
async def stop(self):
|
||||
if self.app is None:
|
||||
|
@@ -25,10 +25,10 @@ class ModuleList:
|
||||
DataModule,
|
||||
GraphQLModule,
|
||||
PermissionModule,
|
||||
LevelModule,
|
||||
DatabaseModule,
|
||||
AutoRoleModule,
|
||||
BaseModule,
|
||||
LevelModule,
|
||||
ApiModule,
|
||||
TechnicianModule,
|
||||
# has to be last!
|
||||
|
@@ -8,6 +8,7 @@ from bot_data.migration.api_key_migration import ApiKeyMigration
|
||||
from bot_data.migration.api_migration import ApiMigration
|
||||
from bot_data.migration.auto_role_fix1_migration import AutoRoleFix1Migration
|
||||
from bot_data.migration.auto_role_migration import AutoRoleMigration
|
||||
from bot_data.migration.db_history_migration import DBHistoryMigration
|
||||
from bot_data.migration.initial_migration import InitialMigration
|
||||
from bot_data.migration.level_migration import LevelMigration
|
||||
from bot_data.migration.remove_stats_migration import RemoveStatsMigration
|
||||
@@ -40,3 +41,4 @@ class StartupMigrationExtension(StartupExtensionABC):
|
||||
services.add_transient(MigrationABC, UserJoinedGameServerMigration) # 12.02.2023 #181 - 1.0.0
|
||||
services.add_transient(MigrationABC, RemoveStatsMigration) # 19.02.2023 #190 - 1.0.0
|
||||
services.add_transient(MigrationABC, UserWarningMigration) # 21.02.2023 #35 - 1.0.0
|
||||
services.add_transient(MigrationABC, DBHistoryMigration) # 06.03.2023 #246 - 1.0.0
|
||||
|
@@ -86,10 +86,10 @@
|
||||
"no_permission_message": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯",
|
||||
"not_implemented_yet": "Ey Alter, das kann ich noch nicht...",
|
||||
"presence": {
|
||||
"booting": "{} Ich fahre gerade hoch...",
|
||||
"restart": "{} Muss neue Kekse holen...",
|
||||
"running": "{} Ich esse Kekse :D",
|
||||
"shutdown": "{} Ich werde bestimmt wieder kommen..."
|
||||
"booting": "Ich fahre gerade hoch...",
|
||||
"restart": "Muss neue Kekse holen...",
|
||||
"running": "Ich esse Kekse :D",
|
||||
"shutdown": "Ich werde bestimmt wieder kommen..."
|
||||
}
|
||||
},
|
||||
"modules": {
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -1,8 +1,9 @@
|
||||
import socket
|
||||
import sys
|
||||
import textwrap
|
||||
import uuid
|
||||
from functools import partial
|
||||
from typing import Union
|
||||
from typing import Union, Optional
|
||||
|
||||
import eventlet
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
@@ -53,10 +54,15 @@ class Api(Flask):
|
||||
self.register_error_handler(exc_class, self.handle_exception)
|
||||
|
||||
# websockets
|
||||
self._socketio = SocketIO(self, cors_allowed_origins="*", path="/api/socket.io")
|
||||
# Added async_mode see link below
|
||||
# https://github.com/miguelgrinberg/Flask-SocketIO/discussions/1849
|
||||
# https://stackoverflow.com/questions/39370848/flask-socket-io-sometimes-client-calls-freeze-the-server
|
||||
self._socketio = SocketIO(self, cors_allowed_origins="*", path="/api/socket.io", async_mode="eventlet")
|
||||
self._socketio.on_event("connect", self.on_connect)
|
||||
self._socketio.on_event("disconnect", self.on_disconnect)
|
||||
|
||||
self._socket: Optional[socket] = None
|
||||
|
||||
self._requests = {}
|
||||
|
||||
@staticmethod
|
||||
@@ -149,7 +155,14 @@ class Api(Flask):
|
||||
# from waitress import serve
|
||||
# https://docs.pylonsproject.org/projects/waitress/en/stable/arguments.html
|
||||
# serve(self, host=self._apt_settings.host, port=self._apt_settings.port, threads=10, connection_limit=1000, channel_timeout=10)
|
||||
wsgi.server(eventlet.listen((self._api_settings.host, self._api_settings.port)), self, log_output=False)
|
||||
self._socket = eventlet.listen((self._api_settings.host, self._api_settings.port))
|
||||
wsgi.server(self._socket, self, log_output=False)
|
||||
|
||||
def stop(self):
|
||||
if self._socket is None:
|
||||
return
|
||||
self._socket.shutdown(socket.SHUT_RDWR)
|
||||
self._socket.close()
|
||||
|
||||
def on_connect(self):
|
||||
self._logger.info(__name__, f"Client connected")
|
||||
|
@@ -17,3 +17,10 @@ class ApiThread(threading.Thread):
|
||||
self._api.start()
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, "Start failed", e)
|
||||
|
||||
def stop(self):
|
||||
try:
|
||||
self._logger.trace(__name__, f"Try to stop {type(self._api).__name__}")
|
||||
self._api.stop()
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, "Stop failed", e)
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0.rc1"
|
||||
"Micro": "7"
|
||||
},
|
||||
"Author": "",
|
||||
"AuthorEmail": "",
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.configuration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.controller"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -129,7 +129,6 @@ class AuthController:
|
||||
return "", 200
|
||||
|
||||
@Route.post(f"{BasePath}/refresh")
|
||||
@Route.authorize
|
||||
async def refresh(self) -> Response:
|
||||
dto: TokenDTO = JSONProcessor.process(TokenDTO, request.get_json(force=True, silent=True))
|
||||
result = await self._auth_service.refresh_async(dto)
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.event"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.exception"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.filter"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.filter.discord"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.logging"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.model"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.model.discord"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.route"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.service"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -483,18 +483,19 @@ class AuthService(AuthServiceABC):
|
||||
if user_dto is None:
|
||||
raise ServiceException(ServiceErrorCode.InvalidData, "User not set")
|
||||
|
||||
members = self._users.get_users_by_discord_id(dc_id)
|
||||
if members.count() == 0:
|
||||
raise ServiceException(ServiceErrorCode.InvalidUser, f"Member not found")
|
||||
|
||||
added_user = False
|
||||
db_user = self._auth_users.find_auth_user_by_email(user_dto.email)
|
||||
if db_user is None:
|
||||
self.add_auth_user(user_dto)
|
||||
added_user = True
|
||||
# raise ServiceException(ServiceErrorCode.InvalidUser, f'User not found')
|
||||
|
||||
db_user = self._auth_users.get_auth_user_by_email(user_dto.email)
|
||||
if db_user.users.count() == 0:
|
||||
self._users.get_users_by_discord_id(dc_id).for_each(
|
||||
lambda x: self._auth_users.add_auth_user_user_rel(AuthUserUsersRelation(db_user, x))
|
||||
)
|
||||
members.for_each(lambda x: self._auth_users.add_auth_user_user_rel(AuthUserUsersRelation(db_user, x)))
|
||||
|
||||
if db_user.confirmation_id is not None and not added_user:
|
||||
raise ServiceException(ServiceErrorCode.Forbidden, "E-Mail not verified")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_api.transformer"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_core"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_core.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -2,9 +2,11 @@ from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
from typing import Callable
|
||||
|
||||
import discord
|
||||
from cpl_query.extension import List
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from bot_data.model.auto_role_rule import AutoRoleRule
|
||||
from bot_data.model.user import User
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
@@ -59,3 +61,9 @@ class ClientUtilsABC(ABC):
|
||||
@abstractmethod
|
||||
def get_ontime_for_user(self, user: User) -> float:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def react_to_message_by_auto_role_rule(
|
||||
self, discord_channel_id: int, discord_message_id: int, rule: AutoRoleRule, guild: discord.Guild
|
||||
):
|
||||
pass
|
||||
|
@@ -25,7 +25,9 @@ class MessageServiceABC(ABC):
|
||||
self,
|
||||
channel: discord.TextChannel,
|
||||
message: Union[str, discord.Embed],
|
||||
without_tracking=True,
|
||||
is_persistent: bool = False,
|
||||
wait_before_delete: int = None,
|
||||
without_tracking=False,
|
||||
):
|
||||
pass
|
||||
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0.rc1"
|
||||
"Micro": "7"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_core.configuration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -10,11 +10,12 @@ class FeatureFlagsEnum(Enum):
|
||||
boot_log_module = "BootLogModule"
|
||||
core_module = "CoreModule"
|
||||
core_extension_module = "CoreExtensionModule"
|
||||
data_module = ("DataModule",)
|
||||
database_module = ("DatabaseModule",)
|
||||
data_module = "DataModule"
|
||||
database_module = "DatabaseModule"
|
||||
level_module = "LevelModule"
|
||||
moderator_module = "ModeratorModule"
|
||||
permission_module = "PermissionModule"
|
||||
# features
|
||||
api_only = "ApiOnly"
|
||||
presence = "Presence"
|
||||
version_in_presence = "VersionInPresence"
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import traceback
|
||||
from typing import Optional, Callable
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
@@ -27,6 +26,7 @@ class FeatureFlagsSettings(ConfigurationModelABC):
|
||||
# features
|
||||
FeatureFlagsEnum.api_only.value: False, # 13.10.2022 #70
|
||||
FeatureFlagsEnum.presence.value: True, # 03.10.2022 #56
|
||||
FeatureFlagsEnum.version_in_presence.value: False, # 21.03.2023 #253
|
||||
}
|
||||
|
||||
def get_flag(self, key: FeatureFlagsEnum) -> bool:
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_core.core_extension"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_core.events"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_core.exception"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_core.helper"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -1,13 +1,9 @@
|
||||
from typing import Optional
|
||||
|
||||
from cpl_translation import TranslatePipe
|
||||
from discord.ext import commands
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.exception.check_error import CheckError
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
class EventChecks:
|
||||
@@ -23,7 +19,7 @@ class EventChecks:
|
||||
@classmethod
|
||||
def check_is_ready(cls):
|
||||
async def check_if_bot_is_ready() -> bool:
|
||||
result = await cls._client_utils.check_if_bot_is_ready()
|
||||
result = await cls._client_utils.check_if_bot_is_ready_yet()
|
||||
if not result:
|
||||
raise CheckError(f"Bot is not ready")
|
||||
return result
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_core.logging"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_core.pipes"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_core.service"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -9,6 +9,7 @@ from cpl_core.time import TimeFormatSettings
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from cpl_query.extension import List
|
||||
from cpl_translation import TranslatePipe
|
||||
from discord import Guild
|
||||
from discord.ext.commands import Context
|
||||
|
||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||
@@ -23,6 +24,7 @@ from bot_data.abc.user_joined_voice_channel_repository_abc import (
|
||||
from bot_data.abc.user_message_count_per_hour_repository_abc import (
|
||||
UserMessageCountPerHourRepositoryABC,
|
||||
)
|
||||
from bot_data.model.auto_role_rule import AutoRoleRule
|
||||
from bot_data.model.user import User
|
||||
from bot_data.model.user_message_count_per_hour import UserMessageCountPerHour
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
@@ -111,7 +113,11 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
|
||||
import bot
|
||||
|
||||
name = self._t.transform(t_key).format(bot.__version__)
|
||||
if self._feature_flags.get_flag(FeatureFlagsEnum.version_in_presence):
|
||||
name = f"{bot.__version__} {self._t.transform(t_key)}"
|
||||
else:
|
||||
name = self._t.transform(t_key)
|
||||
|
||||
await self._bot.change_presence(activity=discord.Game(name=name))
|
||||
self._logger.info(__name__, f"Set presence {name}")
|
||||
|
||||
@@ -188,3 +194,27 @@ class ClientUtilsService(ClientUtilsABC):
|
||||
.sum(lambda join: (join.leaved_on - join.joined_on).total_seconds() / 3600),
|
||||
2,
|
||||
)
|
||||
|
||||
async def react_to_message_by_auto_role_rule(
|
||||
self, discord_channel_id: int, discord_message_id: int, rule: AutoRoleRule, guild: discord.Guild
|
||||
):
|
||||
try:
|
||||
guild: Guild = self._bot.guilds.where(lambda g: g == guild).single()
|
||||
channel = guild.get_channel(discord_channel_id)
|
||||
message = await channel.fetch_message(discord_message_id)
|
||||
emoji = List(discord.Emoji, guild.emojis).where(lambda x: x.name == rule.emoji_name).single()
|
||||
|
||||
if emoji is None:
|
||||
self._logger.debug(__name__, f"Emoji {rule.emoji_name} not found")
|
||||
return
|
||||
await message.add_reaction(emoji)
|
||||
self._logger.debug(
|
||||
__name__,
|
||||
f"Added reaction {rule.emoji_name} to message: {discord_message_id}",
|
||||
)
|
||||
except Exception as e:
|
||||
self._logger.error(
|
||||
__name__,
|
||||
f"Cannot add reaction {rule.emoji_name} to message: {discord_message_id}",
|
||||
e,
|
||||
)
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_data"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_data.abc"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
27
kdb-bot/src/bot_data/abc/history_table_abc.py
Normal file
27
kdb-bot/src/bot_data/abc/history_table_abc.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class HistoryTableABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
self._id = 0
|
||||
self._deleted = False
|
||||
self._date_from = datetime.now().isoformat()
|
||||
self._date_to = datetime.now().isoformat()
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def deleted(self) -> bool:
|
||||
return self._deleted
|
||||
|
||||
@property
|
||||
def date_from(self) -> str:
|
||||
return self._date_from
|
||||
|
||||
@property
|
||||
def date_to(self) -> str:
|
||||
return self._date_to
|
@@ -3,6 +3,7 @@ from abc import ABC, abstractmethod
|
||||
|
||||
class MigrationABC(ABC):
|
||||
name = None
|
||||
prio = 0
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
|
15
kdb-bot/src/bot_data/abc/table_with_id_abc.py
Normal file
15
kdb-bot/src/bot_data/abc/table_with_id_abc.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
|
||||
class TableWithIdABC(TableABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
self.__init__()
|
||||
|
||||
self._id = 0
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0.rc1"
|
||||
"Micro": "7"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
|
@@ -27,6 +27,7 @@ from bot_data.abc.user_warnings_repository_abc import UserWarningsRepositoryABC
|
||||
from bot_data.service.api_key_repository_service import ApiKeyRepositoryService
|
||||
from bot_data.service.auth_user_repository_service import AuthUserRepositoryService
|
||||
from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService
|
||||
from bot_data.service.cache_service import CacheService
|
||||
from bot_data.service.client_repository_service import ClientRepositoryService
|
||||
from bot_data.service.game_server_repository_service import GameServerRepositoryService
|
||||
from bot_data.service.known_user_repository_service import KnownUserRepositoryService
|
||||
@@ -56,6 +57,8 @@ class DataModule(ModuleABC):
|
||||
pass
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services.add_singleton(CacheService)
|
||||
|
||||
services.add_transient(ApiKeyRepositoryABC, ApiKeyRepositoryService)
|
||||
services.add_transient(AuthUserRepositoryABC, AuthUserRepositoryService)
|
||||
services.add_transient(ServerRepositoryABC, ServerRepositoryService)
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import time
|
||||
|
||||
from cpl_core.database import DatabaseSettings
|
||||
from cpl_core.database.context import DatabaseContext
|
||||
|
||||
@@ -31,4 +33,9 @@ class DBContext(DatabaseContext):
|
||||
return super(DBContext, self).select(statement)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f"Database error caused by {statement}", e)
|
||||
try:
|
||||
time.sleep(0.5)
|
||||
return self.select(statement)
|
||||
except Exception as e:
|
||||
pass
|
||||
return []
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_data.migration"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class ApiKeyMigration(MigrationABC):
|
||||
name = "1.0_ApiKeyMigration"
|
||||
name = "1.0.0_ApiKeyMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
|
65
kdb-bot/src/bot_data/migration/db_history_migration.py
Normal file
65
kdb-bot/src/bot_data/migration/db_history_migration.py
Normal file
@@ -0,0 +1,65 @@
|
||||
import os
|
||||
|
||||
from bot_core.logging.database_logger import DatabaseLogger
|
||||
from bot_data.abc.migration_abc import MigrationABC
|
||||
from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class DBHistoryMigration(MigrationABC):
|
||||
name = "1.0.0_DBHistoryMigration"
|
||||
prio = 1
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
self._logger = logger
|
||||
self._db = db
|
||||
self._cursor = db.cursor
|
||||
|
||||
def _exec(self, file: str):
|
||||
path = f"{os.path.dirname(os.path.realpath(__file__))}/db_history_scripts"
|
||||
sql = open(f"{path}/{file}").read()
|
||||
|
||||
for statement in sql.split("\n\n"):
|
||||
self._cursor.execute(statement + ";")
|
||||
|
||||
def upgrade(self):
|
||||
self._logger.debug(__name__, "Running upgrade")
|
||||
|
||||
self._exec("api_keys.sql")
|
||||
self._exec("auth_users.sql")
|
||||
self._exec("auth_user_users_relation.sql")
|
||||
self._exec("auto_role_rules.sql")
|
||||
self._exec("auto_roles.sql")
|
||||
self._exec("clients.sql")
|
||||
self._exec("game_servers.sql")
|
||||
self._exec("known_users.sql")
|
||||
self._exec("levels.sql")
|
||||
self._exec("servers.sql")
|
||||
self._exec("user_game_idents.sql")
|
||||
self._exec("user_joined_game_servers.sql")
|
||||
self._exec("user_joined_servers.sql")
|
||||
self._exec("user_joined_voice_channel.sql")
|
||||
self._exec("user_message_count_per_hour.sql")
|
||||
self._exec("users.sql")
|
||||
self._exec("user_warnings.sql")
|
||||
|
||||
self._logger.debug(__name__, "Finished history upgrade")
|
||||
|
||||
def downgrade(self):
|
||||
self._cursor.execute("DROP TABLE `ApiKeysHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AuthUsersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AuthUserUsersRelationsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AutoRoleRulesHistory`;")
|
||||
self._cursor.execute("DROP TABLE `AutoRolesHistory`;")
|
||||
self._cursor.execute("DROP TABLE `ClientsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `GameServersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `KnownUsersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `LevelsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `ServersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserGameIdentsHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedGameServerHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedServersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserJoinedVoiceChannelHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserMessageCountPerHourHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UsersHistory`;")
|
||||
self._cursor.execute("DROP TABLE `UserWarningsHistory`;")
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `ApiKeys`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `ApiKeys`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ApiKeysHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Identifier` VARCHAR(255) NOT NULL,
|
||||
`Key` VARCHAR(255) NOT NULL,
|
||||
`CreatorId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ApiKeysUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_ApiKeysUpdate`
|
||||
AFTER UPDATE
|
||||
ON `ApiKeys`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ApiKeysHistory` (
|
||||
`Id`, `Identifier`, `Key`, `CreatorId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Identifier, OLD.Key, OLD.CreatorId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ApiKeysDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_ApiKeysDelete`
|
||||
AFTER DELETE
|
||||
ON `ApiKeys`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ApiKeysHistory` (
|
||||
`Id`, `Identifier`, `Key`, `CreatorId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Identifier, OLD.Key, OLD.CreatorId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `AuthUserUsersRelations`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AuthUserUsersRelations`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AuthUserUsersRelationsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`AuthUserId` BIGINT(20) DEFAULT NULL,
|
||||
`UserId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUserUsersRelationsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUserUsersRelationsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AuthUserUsersRelations`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUserUsersRelationsHistory` (
|
||||
`Id`, `AuthUserId`, `UserId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.AuthUserId, OLD.UserId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUserUsersRelationsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUserUsersRelationsDelete`
|
||||
AFTER DELETE
|
||||
ON `AuthUserUsersRelations`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUserUsersRelationsHistory` (
|
||||
`Id`, `AuthUserId`, `UserId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.AuthUserId, OLD.UserId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,62 @@
|
||||
ALTER TABLE `AuthUsers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AuthUsers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AuthUsersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`FirstName` VARCHAR(255) DEFAULT NULL,
|
||||
`LastName` VARCHAR(255) DEFAULT NULL,
|
||||
`EMail` VARCHAR(255) DEFAULT NULL,
|
||||
`Password` VARCHAR(255) DEFAULT NULL,
|
||||
`PasswordSalt` VARCHAR(255) DEFAULT NULL,
|
||||
`RefreshToken` VARCHAR(255) DEFAULT NULL,
|
||||
`ConfirmationId` VARCHAR(255) DEFAULT NULL,
|
||||
`ForgotPasswordId` VARCHAR(255) DEFAULT NULL,
|
||||
`OAuthId` VARCHAR(255) DEFAULT NULL,
|
||||
`RefreshTokenExpiryTime` DATETIME(6) NOT NULL,
|
||||
`AuthRole` BIGINT(11) NOT NULL DEFAULT 0,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUsersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUsersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AuthUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUsersHistory` (
|
||||
`Id`, `FirstName`, `LastName`, `EMail`, `Password`, `PasswordSalt`,
|
||||
`RefreshToken`, `ConfirmationId`, `ForgotPasswordId`, `OAuthId`,
|
||||
`RefreshTokenExpiryTime`, `AuthRole`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.FirstName, OLD.LastName, OLD.EMail, OLD.Password, OLD.PasswordSalt, OLD.RefreshToken,
|
||||
OLD.ConfirmationId, OLD.ForgotPasswordId, OLD.OAuthId, OLD.RefreshTokenExpiryTime, OLD.AuthRole,
|
||||
OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AuthUsersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AuthUsersDelete`
|
||||
AFTER DELETE
|
||||
ON `AuthUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AuthUsersHistory` (
|
||||
`Id`, `FirstName`, `LastName`, `EMail`, `Password`, `PasswordSalt`, `RefreshToken`,
|
||||
`ConfirmationId`, `ForgotPasswordId`, `OAuthId`, `RefreshTokenExpiryTime`,
|
||||
`AuthRole`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.FirstName, OLD.LastName, OLD.EMail, OLD.Password, OLD.PasswordSalt, OLD.RefreshToken,
|
||||
OLD.ConfirmationId, OLD.ForgotPasswordId, OLD.OAuthId, OLD.RefreshTokenExpiryTime, OLD.AuthRole, TRUE,
|
||||
OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `AutoRoleRules`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AutoRoleRules`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AutoRoleRulesHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`AutoRoleId` BIGINT(20) DEFAULT NULL,
|
||||
`DiscordEmojiName` VARCHAR(64) DEFAULT NULL,
|
||||
`DiscordRoleId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRoleRulesUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRoleRulesUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AutoRoleRules`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRoleRulesHistory` (
|
||||
`Id`, `AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleRuleId, OLD.AutoRoleId, OLD.DiscordEmojiName, OLD.DiscordRoleId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRoleRulesDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRoleRulesDelete`
|
||||
AFTER DELETE
|
||||
ON `AutoRoleRules`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRoleRulesHistory` (
|
||||
`Id`, `AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleRuleId, OLD.AutoRoleId, OLD.DiscordEmojiName, OLD.DiscordRoleId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,48 @@
|
||||
ALTER TABLE `AutoRoles`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `AutoRoles`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `AutoRolesHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`DiscordChannelId` BIGINT(20) NOT NULL,
|
||||
`DiscordMessageId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRolesUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRolesUpdate`
|
||||
AFTER UPDATE
|
||||
ON `AutoRoles`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRolesHistory` (
|
||||
`Id`, `ServerId`, `DiscordChannelId`, `DiscordMessageId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleId, OLD.ServerId, OLD.DiscordChannelId, OLD.DiscordMessageId, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_AutoRolesDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_AutoRolesDelete`
|
||||
AFTER DELETE
|
||||
ON `AutoRoles`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `AutoRolesHistory` (
|
||||
`Id`, `ServerId`, `DiscordChannelId`, `DiscordMessageId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.AutoRoleId, OLD.ServerId, OLD.DiscordChannelId, OLD.DiscordMessageId, TRUE, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,54 @@
|
||||
ALTER TABLE `Clients`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Clients`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ClientsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`SentMessageCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ReceivedMessageCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`DeletedMessageCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ReceivedCommandsCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`MovedUsersCount` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ClientsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_ClientsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Clients`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ClientsHistory` (
|
||||
`Id`, `DiscordId`, `SentMessageCount`, `ReceivedMessageCount`, `DeletedMessageCount`,
|
||||
`ReceivedCommandsCount`, `MovedUsersCount`, `ServerId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ClientId, OLD.DiscordClientId, OLD.SentMessageCount, OLD.ReceivedMessageCount, OLD.DeletedMessageCount,
|
||||
OLD.ReceivedCommandsCount, OLD.MovedUsersCount, OLD.ServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ClientsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_ClientsDelete`
|
||||
AFTER DELETE
|
||||
ON `Clients`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ClientsHistory` (
|
||||
`Id`, `DiscordId`, `SentMessageCount`, `ReceivedMessageCount`, `DeletedMessageCount`,
|
||||
`ReceivedCommandsCount`, `MovedUsersCount`, `ServerId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ClientId, OLD.DiscordClientId, OLD.SentMessageCount, OLD.ReceivedMessageCount, OLD.DeletedMessageCount,
|
||||
OLD.ReceivedCommandsCount, OLD.MovedUsersCount, OLD.ServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `GameServers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `GameServers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `GameServersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`ServerId` BIGINT(20) NOT NULL,
|
||||
`ApiKeyId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_GameServersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_GameServersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `GameServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `GameServersHistory` (
|
||||
`Id`, `Name`, `ServerId`, `ApiKeyId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.ServerId, OLD.ApiKeyId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_GameServersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_GameServersDelete`
|
||||
AFTER DELETE
|
||||
ON `GameServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `GameServersHistory` (
|
||||
`Id`, `Name`, `ServerId`, `ApiKeyId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.ServerId, OLD.ApiKeyId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,44 @@
|
||||
ALTER TABLE `KnownUsers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `KnownUsers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `KnownUsersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_KnownUsersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_KnownUsersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `KnownUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `KnownUsersHistory` (
|
||||
`Id`, `DiscordId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.KnownUserId, OLD.DiscordId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_KnownUsersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_KnownUsersDelete`
|
||||
AFTER DELETE
|
||||
ON `KnownUsers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `KnownUsersHistory` (
|
||||
`Id`, `DiscordId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.KnownUserId, OLD.DiscordId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
50
kdb-bot/src/bot_data/migration/db_history_scripts/levels.sql
Normal file
50
kdb-bot/src/bot_data/migration/db_history_scripts/levels.sql
Normal file
@@ -0,0 +1,50 @@
|
||||
ALTER TABLE `Levels`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Levels`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `LevelsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Name` VARCHAR(255) NOT NULL,
|
||||
`Color` VARCHAR(8) NOT NULL,
|
||||
`MinXp` BIGINT(20) NOT NULL,
|
||||
`PermissionInt` BIGINT(20) NOT NULL,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_LevelsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_LevelsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Levels`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `LevelsHistory` (
|
||||
`Id`, `Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.Color, OLD.MinXp, OLD.PermissionInt, OLD.ServerId, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_LevelsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_LevelsDelete`
|
||||
AFTER DELETE
|
||||
ON `Levels`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `LevelsHistory` (
|
||||
`Id`, `Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Name, OLD.Color, OLD.MinXp, OLD.PermissionInt, OLD.ServerId, TRUE, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,44 @@
|
||||
ALTER TABLE `Servers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Servers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `ServersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ServersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_ServersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Servers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ServersHistory` (
|
||||
`Id`, `DiscordId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ServerId, OLD.DiscordServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_ServersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_ServersDelete`
|
||||
AFTER DELETE
|
||||
ON `Servers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `ServersHistory` (
|
||||
`Id`, `DiscordId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.ServerId, OLD.DiscordServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `UserGameIdents`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserGameIdents`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserGameIdentsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`GameServerId` BIGINT(20) NOT NULL,
|
||||
`Ident` VARCHAR(255) NOT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserGameIdentsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserGameIdentsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserGameIdents`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserGameIdentsHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `Ident`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.Ident, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserGameIdentsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserGameIdentsDelete`
|
||||
AFTER DELETE
|
||||
ON `UserGameIdents`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserGameIdentsHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `Ident`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.Ident, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,47 @@
|
||||
ALTER TABLE `UserJoinedGameServer`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserJoinedGameServer`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedGameServerHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`GameServerId` BIGINT(20) NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedGameServerUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedGameServerUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserJoinedGameServer`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedGameServerHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedGameServerDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedGameServerDelete`
|
||||
AFTER DELETE
|
||||
ON `UserJoinedGameServer`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedGameServerHistory` (
|
||||
`Id`, `UserId`, `GameServerId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.GameServerId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `UserJoinedServers`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserJoinedServers`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedServersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedServersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedServersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserJoinedServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedServersHistory` (
|
||||
`Id`, `UserId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedServersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedServersDelete`
|
||||
AFTER DELETE
|
||||
ON `UserJoinedServers`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedServersHistory` (
|
||||
`Id`, `UserId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,49 @@
|
||||
ALTER TABLE `UserJoinedVoiceChannel`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserJoinedVoiceChannel`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserJoinedVoiceChannelHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`DiscordChannelId` BIGINT(20) NOT NULL,
|
||||
`JoinedOn` DATETIME(6) NOT NULL,
|
||||
`LeavedOn` DATETIME(6) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedVoiceChannelUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedVoiceChannelUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserJoinedVoiceChannel`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedVoiceChannelHistory` (
|
||||
`Id`, `UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.DiscordChannelId, OLD.JoinedOn, OLD.LeavedOn, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserJoinedVoiceChannelDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserJoinedVoiceChannelDelete`
|
||||
AFTER DELETE
|
||||
ON `UserJoinedVoiceChannel`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserJoinedVoiceChannelHistory` (
|
||||
`Id`, `UserId`, `DiscordChannelId`, `JoinedOn`, `LeavedOn`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.JoinId, OLD.UserId, OLD.DiscordChannelId, OLD.JoinedOn, OLD.LeavedOn, TRUE, OLD.LastModifiedAt,
|
||||
CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,47 @@
|
||||
ALTER TABLE `UserMessageCountPerHour`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserMessageCountPerHour`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserMessageCountPerHourHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Date` DATETIME(6) NOT NULL,
|
||||
`Hour` BIGINT(20) DEFAULT NULL,
|
||||
`XPCount` BIGINT(20) DEFAULT NULL,
|
||||
`UserId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserMessageCountPerHourUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserMessageCountPerHourUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserMessageCountPerHour`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserMessageCountPerHourHistory` (
|
||||
`Id`, `UserId`, `Date`, `Hour`, `XPCount`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.Date, OLD.Hour, OLD.XPCount, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserMessageCountPerHourDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserMessageCountPerHourDelete`
|
||||
AFTER DELETE
|
||||
ON `UserMessageCountPerHour`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserMessageCountPerHourHistory` (
|
||||
`Id`, `UserId`, `Date`, `Hour`, `XPCount`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.UserId, OLD.Date, OLD.Hour, OLD.XPCount, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `UserWarnings`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `UserWarnings`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UserWarningsHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`Description` VARCHAR(255) NOT NULL,
|
||||
`UserId` BIGINT(20) NOT NULL,
|
||||
`Author` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserWarningsUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UserWarningsUpdate`
|
||||
AFTER UPDATE
|
||||
ON `UserWarnings`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserWarningsHistory` (
|
||||
`Id`, `Description`, `UserId`, `Author`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Description, OLD.UserId, OLD.Author, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UserWarningsDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UserWarningsDelete`
|
||||
AFTER DELETE
|
||||
ON `UserWarnings`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UserWarningsHistory` (
|
||||
`Id`, `Description`, `UserId`, `Author`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.Id, OLD.Description, OLD.UserId, OLD.Author, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
46
kdb-bot/src/bot_data/migration/db_history_scripts/users.sql
Normal file
46
kdb-bot/src/bot_data/migration/db_history_scripts/users.sql
Normal file
@@ -0,0 +1,46 @@
|
||||
ALTER TABLE `Users`
|
||||
CHANGE `CreatedAt` `CreatedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6);
|
||||
|
||||
ALTER TABLE `Users`
|
||||
CHANGE `LastModifiedAt` `LastModifiedAt` DATETIME(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `UsersHistory`
|
||||
(
|
||||
`Id` BIGINT(20) NOT NULL,
|
||||
`DiscordId` BIGINT(20) NOT NULL,
|
||||
`XP` BIGINT(20) NOT NULL DEFAULT 0,
|
||||
`ServerId` BIGINT(20) DEFAULT NULL,
|
||||
`Deleted` BOOL DEFAULT FALSE,
|
||||
`DateFrom` DATETIME(6) NOT NULL,
|
||||
`DateTo` DATETIME(6) NOT NULL
|
||||
);
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UsersUpdate`;
|
||||
|
||||
CREATE TRIGGER `TR_UsersUpdate`
|
||||
AFTER UPDATE
|
||||
ON `Users`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UsersHistory` (
|
||||
`Id`, `DiscordId`, `XP`, `ServerId`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ServerId, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
||||
|
||||
DROP TRIGGER IF EXISTS `TR_UsersDelete`;
|
||||
|
||||
CREATE TRIGGER `TR_UsersDelete`
|
||||
AFTER DELETE
|
||||
ON `Users`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
INSERT INTO `UsersHistory` (
|
||||
`Id`, `DiscordId`, `XP`, `ServerId`, `Deleted`, `DateFrom`, `DateTo`
|
||||
)
|
||||
VALUES (
|
||||
OLD.UserId, OLD.DiscordId, OLD.XP, OLD.ServerId, TRUE, OLD.LastModifiedAt, CURRENT_TIMESTAMP(6)
|
||||
);
|
||||
END;
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class RemoveStatsMigration(MigrationABC):
|
||||
name = "1.0_RemoveStatsMigration"
|
||||
name = "1.0.0_RemoveStatsMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class UserJoinedGameServerMigration(MigrationABC):
|
||||
name = "1.0_UserJoinedGameServerMigration"
|
||||
name = "1.0.0_UserJoinedGameServerMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
|
@@ -4,7 +4,7 @@ from bot_data.db_context import DBContext
|
||||
|
||||
|
||||
class UserWarningMigration(MigrationABC):
|
||||
name = "1.0_UserWarningMigration"
|
||||
name = "1.0.0_UserWarningMigration"
|
||||
|
||||
def __init__(self, logger: DatabaseLogger, db: DBContext):
|
||||
MigrationABC.__init__(self)
|
||||
|
@@ -15,7 +15,7 @@ __title__ = "bot_data.model"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2022 - 2023 sh-edraft.de"
|
||||
__version__ = "1.0.0rc1"
|
||||
__version__ = "1.0.7"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -23,4 +23,4 @@ from collections import namedtuple
|
||||
# imports
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="0.rc1")
|
||||
version_info = VersionInfo(major="1", minor="0", micro="7")
|
||||
|
@@ -82,13 +82,11 @@ class ApiKey(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `ApiKeys` (
|
||||
`Identifier`, `Key`, `CreatorId`, `CreatedAt`, `LastModifiedAt`
|
||||
`Identifier`, `Key`, `CreatorId`
|
||||
) VALUES (
|
||||
'{self._identifier}',
|
||||
'{self._key}',
|
||||
{"NULL" if self._creator is None else f"'{self._creator.id}'"},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{"NULL" if self._creator is None else f"'{self._creator.id}'"}
|
||||
);
|
||||
"""
|
||||
)
|
||||
@@ -100,8 +98,7 @@ class ApiKey(TableABC):
|
||||
UPDATE `ApiKeys`
|
||||
SET `Identifier` = '{self._identifier}',
|
||||
`Key` = '{self._key}',
|
||||
`CreatorId` = {"NULL" if self._creator is None else f"'{self._creator.id}'"},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
`CreatorId` = {"NULL" if self._creator is None else f"'{self._creator.id}'"}
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
@@ -220,9 +220,7 @@ class AuthUser(TableABC):
|
||||
`ForgotPasswordId`,
|
||||
`OAuthId`,
|
||||
`RefreshTokenExpiryTime`,
|
||||
`AuthRole`,
|
||||
`CreatedAt`,
|
||||
`LastModifiedAt`
|
||||
`AuthRole`
|
||||
) VALUES (
|
||||
{self._auth_user_id},
|
||||
'{self._first_name}',
|
||||
@@ -235,9 +233,7 @@ class AuthUser(TableABC):
|
||||
{"NULL" if self._forgot_password_id is None else f"'{self._forgot_password_id}'"},
|
||||
{"NULL" if self._oauth_id is None else f"'{self._oauth_id}'"},
|
||||
'{self._refresh_token_expire_time.isoformat()}',
|
||||
{self._auth_role_id.value},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{self._auth_role_id.value}
|
||||
)
|
||||
"""
|
||||
)
|
||||
@@ -257,8 +253,7 @@ class AuthUser(TableABC):
|
||||
`ForgotPasswordId` = {"NULL" if self._forgot_password_id is None else f"'{self._forgot_password_id}'"},
|
||||
`OAuthId` = {"NULL" if self._oauth_id is None else f"'{self._oauth_id}'"},
|
||||
`RefreshTokenExpiryTime` = '{self._refresh_token_expire_time.isoformat()}',
|
||||
`AuthRole` = {self._auth_role_id.value},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
`AuthRole` = {self._auth_role_id.value}
|
||||
WHERE `AuthUsers`.`Id` = {self._auth_user_id};
|
||||
"""
|
||||
)
|
||||
|
@@ -68,12 +68,10 @@ class AuthUserUsersRelation(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AuthUserUsersRelations` (
|
||||
`AuthUserId`, `UserId`, `CreatedAt`, `LastModifiedAt`
|
||||
`AuthUserId`, `UserId`
|
||||
) VALUES (
|
||||
{self._auth_user.id},
|
||||
{self._user.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{self._user.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
@@ -83,9 +81,8 @@ class AuthUserUsersRelation(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `AuthUserUsersRelations`
|
||||
SET `AuthUserId` = '{self._auth_user.id}',,
|
||||
SET `AuthUserId` = '{self._auth_user.id}',
|
||||
`UserId` = '{self._user.id}'
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `AuthUserId` = {self._auth_user.id}
|
||||
AND `UserId` = {self._user.id};
|
||||
"""
|
||||
|
@@ -97,13 +97,11 @@ class AutoRole(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AutoRoles` (
|
||||
`ServerId`, `DiscordChannelId`, `DiscordMessageId`, `CreatedAt`, `LastModifiedAt`
|
||||
`ServerId`, `DiscordChannelId`, `DiscordMessageId`
|
||||
) VALUES (
|
||||
{self._server.id},
|
||||
{self._discord_channel_id},
|
||||
{self._discord_message_id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{self._discord_message_id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
@@ -115,8 +113,7 @@ class AutoRole(TableABC):
|
||||
UPDATE `AutoRoles`
|
||||
SET `ServerId` = {self._server.id},
|
||||
`DiscordChannelId` = {self._discord_channel_id},
|
||||
`DiscordMessageId` = {self._discord_message_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
`DiscordMessageId` = {self._discord_message_id}
|
||||
WHERE `AutoRoleId` = {self._auto_role_id};
|
||||
"""
|
||||
)
|
||||
|
49
kdb-bot/src/bot_data/model/auto_role_history.py
Normal file
49
kdb-bot/src/bot_data/model/auto_role_history.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class AutoRoleHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
server: int,
|
||||
channel_id: int,
|
||||
dc_message_id: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._auto_role_id = id
|
||||
self._server = server
|
||||
self._discord_channel_id = channel_id
|
||||
self._discord_message_id = dc_message_id
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._auto_role_id
|
||||
|
||||
@property
|
||||
def server(self) -> int:
|
||||
return self._server
|
||||
|
||||
@property
|
||||
def discord_channel_id(self) -> int:
|
||||
return self._discord_channel_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def discord_channel_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
channel = bot.get_channel(self.discord_channel_id)
|
||||
return None if channel is None else channel.name
|
||||
|
||||
@property
|
||||
def discord_message_id(self) -> int:
|
||||
return self._discord_message_id
|
@@ -87,13 +87,11 @@ class AutoRoleRule(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `AutoRoleRules` (
|
||||
`AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`, `CreatedAt`, `LastModifiedAt`
|
||||
`AutoRoleId`, `DiscordEmojiName`, `DiscordRoleId`
|
||||
) VALUES (
|
||||
{self._auto_role.id},
|
||||
'{self._discord_emoji_name}',
|
||||
{self._discord_role_id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{self._discord_role_id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
@@ -105,8 +103,7 @@ class AutoRoleRule(TableABC):
|
||||
UPDATE `AutoRoleRules`
|
||||
SET `AutoRoleId` = {self._auto_role.id},
|
||||
`DiscordEmojiName` = '{self._discord_emoji_name}',
|
||||
`DiscordRoleId` = {self._discord_role_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
`DiscordRoleId` = {self._discord_role_id}
|
||||
WHERE `AutoRoleRuleId` = {self._auto_role_rule_id};
|
||||
"""
|
||||
)
|
||||
|
48
kdb-bot/src/bot_data/model/auto_role_rule_history.py
Normal file
48
kdb-bot/src/bot_data/model/auto_role_rule_history.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class AutoRoleRuleHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
auto_role: int,
|
||||
discord_emoji_name: str,
|
||||
discord_role_id: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
self._auto_role_rule_id = id
|
||||
self._auto_role = auto_role
|
||||
self._discord_emoji_name = discord_emoji_name
|
||||
self._discord_role_id = discord_role_id
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._auto_role_rule_id
|
||||
|
||||
@property
|
||||
def auto_role(self) -> int:
|
||||
return self._auto_role
|
||||
|
||||
@property
|
||||
def emoji_name(self) -> str:
|
||||
return self._discord_emoji_name
|
||||
|
||||
@property
|
||||
def role_id(self) -> int:
|
||||
return self._discord_role_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def role_name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.auto_role.server.discord_id)
|
||||
return guild.get_role(self.role_id).name
|
@@ -53,7 +53,6 @@ class Client(TableABC):
|
||||
|
||||
@sent_message_count.setter
|
||||
def sent_message_count(self, value: int):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._sent_message_count = value
|
||||
|
||||
@property
|
||||
@@ -62,7 +61,6 @@ class Client(TableABC):
|
||||
|
||||
@received_message_count.setter
|
||||
def received_message_count(self, value: int):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._received_message_count = value
|
||||
|
||||
@property
|
||||
@@ -71,7 +69,6 @@ class Client(TableABC):
|
||||
|
||||
@deleted_message_count.setter
|
||||
def deleted_message_count(self, value: int):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._deleted_message_count = value
|
||||
|
||||
@property
|
||||
@@ -80,7 +77,6 @@ class Client(TableABC):
|
||||
|
||||
@received_command_count.setter
|
||||
def received_command_count(self, value: int):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._received_command_count = value
|
||||
|
||||
@property
|
||||
@@ -89,7 +85,6 @@ class Client(TableABC):
|
||||
|
||||
@moved_users_count.setter
|
||||
def moved_users_count(self, value: int):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._moved_users_count = value
|
||||
|
||||
@property
|
||||
@@ -152,9 +147,7 @@ class Client(TableABC):
|
||||
`DeletedMessageCount`,
|
||||
`ReceivedCommandsCount`,
|
||||
`MovedUsersCount`,
|
||||
`ServerId`,
|
||||
`CreatedAt`,
|
||||
`LastModifiedAt`
|
||||
`ServerId`
|
||||
) VALUES (
|
||||
{self._discord_client_id},
|
||||
{self._sent_message_count},
|
||||
@@ -162,9 +155,7 @@ class Client(TableABC):
|
||||
{self._deleted_message_count},
|
||||
{self._received_message_count},
|
||||
{self._moved_users_count},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{self._server.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
@@ -178,8 +169,7 @@ class Client(TableABC):
|
||||
`ReceivedMessageCount` = {self._received_message_count},
|
||||
`DeletedMessageCount` = {self._deleted_message_count},
|
||||
`ReceivedCommandsCount` = {self._received_command_count},
|
||||
`MovedUsersCount` = {self._moved_users_count},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
`MovedUsersCount` = {self._moved_users_count}
|
||||
WHERE `ClientId` = {self._client_id};
|
||||
"""
|
||||
)
|
||||
|
72
kdb-bot/src/bot_data/model/client_history.py
Normal file
72
kdb-bot/src/bot_data/model/client_history.py
Normal file
@@ -0,0 +1,72 @@
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class ClientHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
dc_id: int,
|
||||
smc: int,
|
||||
rmc: int,
|
||||
dmc: int,
|
||||
rcc: int,
|
||||
muc: int,
|
||||
server: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._client_id = id
|
||||
self._discord_client_id = dc_id
|
||||
self._sent_message_count = smc
|
||||
self._received_message_count = rmc
|
||||
self._deleted_message_count = dmc
|
||||
self._received_command_count = rcc
|
||||
self._moved_users_count = muc
|
||||
self._server = server
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._client_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_client_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
return bot.user.name
|
||||
|
||||
@property
|
||||
def sent_message_count(self) -> int:
|
||||
return self._sent_message_count
|
||||
|
||||
@property
|
||||
def received_message_count(self) -> int:
|
||||
return self._received_message_count
|
||||
|
||||
@property
|
||||
def deleted_message_count(self) -> int:
|
||||
return self._deleted_message_count
|
||||
|
||||
@property
|
||||
def received_command_count(self) -> int:
|
||||
return self._received_command_count
|
||||
|
||||
@property
|
||||
def moved_users_count(self) -> int:
|
||||
return self._moved_users_count
|
||||
|
||||
@property
|
||||
def server(self) -> int:
|
||||
return self._server
|
@@ -102,13 +102,11 @@ class GameServer(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `GameServers` (
|
||||
`Name`, `ServerId`, `ApiKeyId`, `CreatedAt`, `LastModifiedAt`
|
||||
`Name`, `ServerId`, `ApiKeyId`
|
||||
) VALUES (
|
||||
'{self._name}',
|
||||
{self._server.id},
|
||||
{self._api_key.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{self._api_key.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
@@ -118,7 +116,7 @@ class GameServer(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `GameServers`
|
||||
SET `LastModifiedAt` = '{self._modified_at}'
|
||||
SET `Name` = '{self._name}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
@@ -57,11 +57,9 @@ class KnownUser(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `KnownUsers` (
|
||||
`DiscordId`, `CreatedAt`, `LastModifiedAt`
|
||||
`DiscordId`
|
||||
) VALUES (
|
||||
{self._discord_id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{self._discord_id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
28
kdb-bot/src/bot_data/model/known_user_history.py
Normal file
28
kdb-bot/src/bot_data/model/known_user_history.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class KnownUserHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
dc_id: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._known_user_id = id
|
||||
self._discord_id = dc_id
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._known_user_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_id
|
@@ -39,7 +39,6 @@ class Level(TableABC):
|
||||
|
||||
@name.setter
|
||||
def name(self, value: str):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._name = value
|
||||
|
||||
@property
|
||||
@@ -48,7 +47,6 @@ class Level(TableABC):
|
||||
|
||||
@color.setter
|
||||
def color(self, value: str):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._color = value
|
||||
|
||||
@property
|
||||
@@ -57,7 +55,6 @@ class Level(TableABC):
|
||||
|
||||
@min_xp.setter
|
||||
def min_xp(self, value: int):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._min_xp = value
|
||||
|
||||
@property
|
||||
@@ -66,7 +63,6 @@ class Level(TableABC):
|
||||
|
||||
@permissions.setter
|
||||
def permissions(self, value: int):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._permissions = value
|
||||
|
||||
@property
|
||||
@@ -75,7 +71,6 @@ class Level(TableABC):
|
||||
|
||||
@server.setter
|
||||
def server(self, value: Server):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._server = value
|
||||
|
||||
@staticmethod
|
||||
@@ -109,15 +104,13 @@ class Level(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Levels` (
|
||||
`Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`, `CreatedAt`, `LastModifiedAt`
|
||||
`Name`, `Color`, `MinXp`, `PermissionInt`, `ServerId`
|
||||
) VALUES (
|
||||
'{self._name}',
|
||||
'{self._color}',
|
||||
{self._min_xp},
|
||||
{self._permissions},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{self._server.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
@@ -130,8 +123,7 @@ class Level(TableABC):
|
||||
SET `Name` = '{self._name}',
|
||||
`Color` = '{self._color}',
|
||||
`MinXp` = {self._min_xp},
|
||||
`PermissionInt` = {self._permissions},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
`PermissionInt` = {self._permissions}
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
|
55
kdb-bot/src/bot_data/model/level_history.py
Normal file
55
kdb-bot/src/bot_data/model/level_history.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from typing import Optional
|
||||
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class LevelHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
color: str,
|
||||
min_xp: int,
|
||||
permissions: int,
|
||||
server: Optional[Server],
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._id = id
|
||||
self._name = name
|
||||
self._color = color
|
||||
self._min_xp = min_xp
|
||||
self._permissions = permissions
|
||||
self._server = server
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def color(self) -> str:
|
||||
return self._color
|
||||
|
||||
@property
|
||||
def min_xp(self) -> int:
|
||||
return self._min_xp
|
||||
|
||||
@property
|
||||
def permissions(self) -> int:
|
||||
return self._permissions
|
||||
|
||||
@property
|
||||
def server(self) -> Server:
|
||||
return self._server
|
@@ -71,11 +71,9 @@ class Server(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Servers` (
|
||||
`DiscordServerId`, `CreatedAt`, `LastModifiedAt`
|
||||
`DiscordServerId`
|
||||
) VALUES (
|
||||
{self._discord_server_id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{self._discord_server_id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
@@ -85,8 +83,7 @@ class Server(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Servers`
|
||||
SET `DiscordServerId` = {self._discord_server_id},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
SET `DiscordServerId` = {self._discord_server_id}
|
||||
WHERE `ServerId` = {self._server_id};
|
||||
"""
|
||||
)
|
||||
|
43
kdb-bot/src/bot_data/model/server_history.py
Normal file
43
kdb-bot/src/bot_data/model/server_history.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class ServerHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
dc_id: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._server_id = id
|
||||
self._discord_server_id = dc_id
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._server_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_server_id
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def name(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.discord_id)
|
||||
return None if guild is None else guild.name
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def icon_url(self, bot: DiscordBotServiceABC) -> str:
|
||||
guild = bot.get_guild(self.discord_id)
|
||||
return None if guild is None else guild.icon.url
|
@@ -57,7 +57,6 @@ class User(TableABC):
|
||||
|
||||
@xp.setter
|
||||
def xp(self, value: int):
|
||||
self._modified_at = datetime.now().isoformat()
|
||||
self._xp = value
|
||||
|
||||
@property
|
||||
@@ -152,13 +151,11 @@ class User(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `Users` (
|
||||
`DiscordId`, `XP`, `ServerId`, `CreatedAt`, `LastModifiedAt`
|
||||
`DiscordId`, `XP`, `ServerId`
|
||||
) VALUES (
|
||||
{self._discord_id},
|
||||
{self._xp},
|
||||
{self._server.id},
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
{self._server.id}
|
||||
);
|
||||
"""
|
||||
)
|
||||
@@ -168,8 +165,7 @@ class User(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `Users`
|
||||
SET `XP` = {self._xp},
|
||||
`LastModifiedAt` = '{self._modified_at}'
|
||||
SET `XP` = {self._xp}
|
||||
WHERE `UserId` = {self._user_id};
|
||||
"""
|
||||
)
|
||||
|
@@ -91,26 +91,18 @@ class UserGameIdent(TableABC):
|
||||
return str(
|
||||
f"""
|
||||
INSERT INTO `UserGameIdents` (
|
||||
`UserId`, `GameServerId`, `Ident`, `CreatedAt`, `LastModifiedAt`
|
||||
`UserId`, `GameServerId`, `Ident`
|
||||
) VALUES (
|
||||
{self._user.id},
|
||||
'{self._game_server.id}',
|
||||
'{self._ident}',
|
||||
'{self._created_at}',
|
||||
'{self._modified_at}'
|
||||
'{self._ident}'
|
||||
);
|
||||
"""
|
||||
)
|
||||
|
||||
@property
|
||||
def udpate_string(self) -> str:
|
||||
return str(
|
||||
f"""
|
||||
UPDATE `UserGameIdents`
|
||||
SET `LastModifiedAt` = '{self._modified_at}'
|
||||
WHERE `Id` = {self._id};
|
||||
"""
|
||||
)
|
||||
return ""
|
||||
|
||||
@property
|
||||
def delete_string(self) -> str:
|
||||
|
65
kdb-bot/src/bot_data/model/user_history.py
Normal file
65
kdb-bot/src/bot_data/model/user_history.py
Normal file
@@ -0,0 +1,65 @@
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.abc.history_table_abc import HistoryTableABC
|
||||
|
||||
|
||||
class UserHistory(HistoryTableABC):
|
||||
def __init__(
|
||||
self,
|
||||
dc_id: int,
|
||||
xp: int,
|
||||
server: int,
|
||||
deleted: bool,
|
||||
date_from: str,
|
||||
date_to: str,
|
||||
id=0,
|
||||
):
|
||||
HistoryTableABC.__init__(self)
|
||||
|
||||
self._user_id = id
|
||||
self._discord_id = dc_id
|
||||
self._xp = xp
|
||||
self._server = server
|
||||
|
||||
self._deleted = deleted
|
||||
self._date_from = date_from
|
||||
self._date_to = date_to
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
return self._user_id
|
||||
|
||||
@property
|
||||
def discord_id(self) -> int:
|
||||
return self._discord_id
|
||||
|
||||
@property
|
||||
def xp(self) -> int:
|
||||
return self._xp
|
||||
|
||||
@property
|
||||
def server(self) -> int:
|
||||
return self._server
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def left_server(
|
||||
self,
|
||||
services: ServiceProviderABC,
|
||||
) -> bool:
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
|
||||
ujs: UserJoinedServerRepositoryABC = services.get_service(UserJoinedServerRepositoryABC)
|
||||
return ujs.find_active_user_joined_server_by_user_id(self.id) is None
|
||||
|
||||
@property
|
||||
@ServiceProviderABC.inject
|
||||
def game_idents(
|
||||
self,
|
||||
services: ServiceProviderABC,
|
||||
) -> List["UserGameIdent"]:
|
||||
from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryABC
|
||||
|
||||
game_idents_repo: UserGameIdentRepositoryABC = services.get_service(UserGameIdentRepositoryABC)
|
||||
return game_idents_repo.get_user_game_idents_by_user_id(self.id)
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user