Merge branch 'master' into 1.0.0-fix
# Conflicts: # kdb-bot/src/bot/__init__.py # kdb-bot/src/bot/bot.json # kdb-bot/src/bot/config # kdb-bot/src/bot/extension/__init__.py # kdb-bot/src/bot_api/__init__.py # kdb-bot/src/bot_api/abc/__init__.py # kdb-bot/src/bot_api/bot-api.json # kdb-bot/src/bot_api/configuration/__init__.py # kdb-bot/src/bot_api/controller/__init__.py # kdb-bot/src/bot_api/event/__init__.py # kdb-bot/src/bot_api/exception/__init__.py # kdb-bot/src/bot_api/filter/__init__.py # kdb-bot/src/bot_api/filter/discord/__init__.py # kdb-bot/src/bot_api/logging/__init__.py # kdb-bot/src/bot_api/model/__init__.py # kdb-bot/src/bot_api/model/discord/__init__.py # kdb-bot/src/bot_api/route/__init__.py # kdb-bot/src/bot_api/service/__init__.py # kdb-bot/src/bot_api/transformer/__init__.py # kdb-bot/src/bot_core/__init__.py # kdb-bot/src/bot_core/abc/__init__.py # kdb-bot/src/bot_core/bot-core.json # kdb-bot/src/bot_core/configuration/__init__.py # kdb-bot/src/bot_core/core_extension/__init__.py # kdb-bot/src/bot_core/events/__init__.py # kdb-bot/src/bot_core/exception/__init__.py # kdb-bot/src/bot_core/helper/__init__.py # kdb-bot/src/bot_core/logging/__init__.py # kdb-bot/src/bot_core/pipes/__init__.py # kdb-bot/src/bot_core/service/__init__.py # kdb-bot/src/bot_data/__init__.py # kdb-bot/src/bot_data/abc/__init__.py # kdb-bot/src/bot_data/bot-data.json # kdb-bot/src/bot_data/migration/__init__.py # kdb-bot/src/bot_data/model/__init__.py # kdb-bot/src/bot_data/service/__init__.py # kdb-bot/src/bot_graphql/__init__.py # kdb-bot/src/bot_graphql/abc/__init__.py # kdb-bot/src/bot_graphql/filter/__init__.py # kdb-bot/src/bot_graphql/mutations/__init__.py # kdb-bot/src/modules/auto_role/__init__.py # kdb-bot/src/modules/auto_role/auto-role.json # kdb-bot/src/modules/auto_role/command/__init__.py # kdb-bot/src/modules/auto_role/events/__init__.py # kdb-bot/src/modules/auto_role/helper/__init__.py # kdb-bot/src/modules/base/__init__.py # kdb-bot/src/modules/base/abc/__init__.py # kdb-bot/src/modules/base/base.json # kdb-bot/src/modules/base/command/__init__.py # kdb-bot/src/modules/base/configuration/__init__.py # kdb-bot/src/modules/base/events/__init__.py # kdb-bot/src/modules/base/events/base_on_voice_state_update_event.py # kdb-bot/src/modules/base/helper/__init__.py # kdb-bot/src/modules/base/model/__init__.py # kdb-bot/src/modules/base/service/__init__.py # kdb-bot/src/modules/base/thread/__init__.py # kdb-bot/src/modules/boot_log/__init__.py # kdb-bot/src/modules/boot_log/boot-log.json # kdb-bot/src/modules/boot_log/configuration/__init__.py # kdb-bot/src/modules/database/__init__.py # kdb-bot/src/modules/database/database.json # kdb-bot/src/modules/level/__init__.py # kdb-bot/src/modules/level/command/__init__.py # kdb-bot/src/modules/level/configuration/__init__.py # kdb-bot/src/modules/level/events/__init__.py # kdb-bot/src/modules/level/level.json # kdb-bot/src/modules/level/service/__init__.py # kdb-bot/src/modules/permission/__init__.py # kdb-bot/src/modules/permission/abc/__init__.py # kdb-bot/src/modules/permission/configuration/__init__.py # kdb-bot/src/modules/permission/events/__init__.py # kdb-bot/src/modules/permission/permission.json # kdb-bot/src/modules/permission/service/__init__.py # kdb-bot/src/modules/stats/service/__init__.py # kdb-bot/src/modules/stats/stats.json # kdb-bot/src/modules/technician/__init__.py # kdb-bot/src/modules/technician/command/__init__.py # kdb-bot/src/modules/technician/technician.json # kdb-bot/tools/get_version/get-version.json # kdb-bot/tools/post_build/post-build.json # kdb-bot/tools/set_version/set-version.json
This commit is contained in:
commit
468ebb5f79
@ -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"
|
||||
|
@ -14,5 +14,6 @@ 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
|
||||
|
||||
CMD [ "bash", "/app/bot/bot"]
|
||||
|
@ -1,12 +1,12 @@
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_discord.service import DiscordBotServiceABC
|
||||
from discord import RawReactionActionEvent
|
||||
|
||||
from bot_core.abc.client_utils_abc import ClientUtilsABC
|
||||
from bot_core.helper.log_message_helper import LogMessageHelper
|
||||
from bot_core.logging.message_logger import MessageLogger
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from modules.base.abc.base_helper_abc import BaseHelperABC
|
||||
@ -16,7 +16,7 @@ from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
class BaseReactionHandler:
|
||||
def __init__(
|
||||
self,
|
||||
logger: LoggerABC,
|
||||
logger: MessageLogger,
|
||||
bot: DiscordBotServiceABC,
|
||||
servers: ServerRepositoryABC,
|
||||
users: UserRepositoryABC,
|
||||
|
@ -274,6 +274,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
self._logger.debug(__name__, f"Start checking UserJoinedVoiceChannel table")
|
||||
for guild in self._bot.guilds:
|
||||
guild: discord.Guild = guild
|
||||
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{guild.id}")
|
||||
|
||||
server = self._servers.find_server_by_discord_id(guild.id)
|
||||
if server is None:
|
||||
@ -299,7 +300,6 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
f"Active UserJoinedVoiceChannel found in database: {guild.id}:{member.id}@{join.joined_on}",
|
||||
)
|
||||
join.leaved_on = datetime.now()
|
||||
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{guild.id}")
|
||||
|
||||
if (
|
||||
(join.leaved_on - join.joined_on).total_seconds() / 60 / 60
|
||||
@ -315,7 +315,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
||||
self._logger.trace(__name__, f"User {member.id} is ignored, because its a bot")
|
||||
continue
|
||||
|
||||
if member.voice is None:
|
||||
if member.voice is None or member.voice.channel.id in settings.afk_channel_ids:
|
||||
continue
|
||||
|
||||
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)
|
||||
|
4088
kdb-bot/tools/checks/UserJoinedVoiceChannel.json
Normal file
4088
kdb-bot/tools/checks/UserJoinedVoiceChannel.json
Normal file
File diff suppressed because it is too large
Load Diff
1
kdb-bot/tools/checks/__init__.py
Normal file
1
kdb-bot/tools/checks/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# imports
|
44
kdb-bot/tools/checks/checks.json
Normal file
44
kdb-bot/tools/checks/checks.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "checks",
|
||||
"Version": {
|
||||
"Major": "1",
|
||||
"Minor": "0",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
"Description": "CPL internal tool to set version from branch name",
|
||||
"LongDescription": "CPL internal tool to set version from branch name",
|
||||
"URL": "https://www.sh-edraft.de",
|
||||
"CopyrightDate": "2022",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core==2022.12.0"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli==2022.12.0"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"ProjectType": "library",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "checks.main",
|
||||
"EntryPoint": "checks",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
81
kdb-bot/tools/checks/get_ontime_overlaps.py
Normal file
81
kdb-bot/tools/checks/get_ontime_overlaps.py
Normal file
@ -0,0 +1,81 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
|
||||
class UserJoinedVoiceChannel:
|
||||
def __init__(self):
|
||||
self.JoinId = None
|
||||
self.UserId = None
|
||||
self.DiscordChannelId = None
|
||||
self.JoinedOn = None
|
||||
self.LeavedOn = None
|
||||
self.CreatedAt = None
|
||||
self.LastModifiedAt = None
|
||||
|
||||
@property
|
||||
def ontime(self) -> int:
|
||||
return round((self.LeavedOn - self.JoinedOn).total_seconds() / 3600, 2)
|
||||
|
||||
def from_dict(self, data: dict):
|
||||
self.JoinId = data["JoinId"]
|
||||
self.UserId = data["UserId"]
|
||||
self.DiscordChannelId = data["DiscordChannelId"]
|
||||
self.JoinedOn = datetime.strptime(data["JoinedOn"], "%Y-%m-%d %H:%M:%S.%f")
|
||||
self.LeavedOn = datetime.strptime(data["LeavedOn"], "%Y-%m-%d %H:%M:%S.%f")
|
||||
self.CreatedAt = data["CreatedAt"]
|
||||
self.LastModifiedAt = data["LastModifiedAt"]
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.JoinId}: {self.UserId} {self.JoinedOn} {self.LeavedOn}"
|
||||
|
||||
|
||||
def main():
|
||||
data = json.loads(open("UserJoinedVoiceChannel.json", "r").read())
|
||||
ujvcs = List(UserJoinedVoiceChannel)
|
||||
for x in data:
|
||||
ujvc = UserJoinedVoiceChannel()
|
||||
ujvc.from_dict(x)
|
||||
ujvcs.append(ujvc)
|
||||
|
||||
users = ujvcs.order_by(lambda x: x.UserId).select(lambda x: x.UserId).distinct()
|
||||
groups = {}
|
||||
for user in users:
|
||||
groups[user] = List(UserJoinedVoiceChannel)
|
||||
groups[user].extend(ujvcs.where(lambda x: x.UserId == user))
|
||||
|
||||
for group in groups:
|
||||
|
||||
values: List[UserJoinedVoiceChannel] = groups[group]
|
||||
|
||||
def find_overlaps(x: UserJoinedVoiceChannel) -> bool:
|
||||
for y in values:
|
||||
if x == y:
|
||||
continue
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
Range = namedtuple("Range", ["start", "end"])
|
||||
r1 = Range(start=x.JoinedOn, end=x.LeavedOn)
|
||||
r2 = Range(start=y.LeavedOn, end=y.LeavedOn)
|
||||
latest_start = max(r1.start, r2.start)
|
||||
earliest_end = min(r1.end, r2.end)
|
||||
delta = (earliest_end - latest_start).days + 1
|
||||
overlap = max(0, delta)
|
||||
if overlap > 0:
|
||||
return True
|
||||
|
||||
overlaps = values.where(find_overlaps)
|
||||
if overlaps.count() == 0:
|
||||
continue
|
||||
|
||||
print(overlaps.select(lambda x: x.JoinId))
|
||||
print(f"{group} has {overlaps.count()} of {values.count()}")
|
||||
ontime = overlaps.sum(lambda x: x.ontime)
|
||||
print(f"ontime: {ontime}")
|
||||
print(f"xp: {ontime * 8}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user