Merge pull request '1.0.0-fix' (#254) from 1.0.0-fix into 1.0.0

Reviewed-on: sh-edraft.de/kd_discord_bot#254
This commit is contained in:
Sven Heidemann 2023-03-20 14:41:33 +01:00
commit ba1f4ee955
8 changed files with 4221 additions and 4 deletions

View File

@ -14,6 +14,7 @@
"level": "src/modules/level/level.json", "level": "src/modules/level/level.json",
"permission": "src/modules/permission/permission.json", "permission": "src/modules/permission/permission.json",
"technician": "src/modules/technician/technician.json", "technician": "src/modules/technician/technician.json",
"checks": "tools/checks/checks.json",
"get-version": "tools/get_version/get-version.json", "get-version": "tools/get_version/get-version.json",
"post-build": "tools/post_build/post-build.json", "post-build": "tools/post_build/post-build.json",
"set-version": "tools/set_version/set-version.json" "set-version": "tools/set_version/set-version.json"

View File

@ -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 -r requirements.txt --extra-index-url https://pip.sh-edraft.de
RUN pip install flask[async] 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"] CMD [ "bash", "/app/bot/bot"]

View File

@ -1,12 +1,12 @@
from datetime import datetime from datetime import datetime
from cpl_core.database.context import DatabaseContextABC from cpl_core.database.context import DatabaseContextABC
from cpl_core.logging import LoggerABC
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from discord import RawReactionActionEvent from discord import RawReactionActionEvent
from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_core.abc.client_utils_abc import ClientUtilsABC
from bot_core.helper.log_message_helper import LogMessageHelper 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.server_repository_abc import ServerRepositoryABC
from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC
from modules.base.abc.base_helper_abc import BaseHelperABC from modules.base.abc.base_helper_abc import BaseHelperABC
@ -16,7 +16,7 @@ from modules.base.configuration.base_server_settings import BaseServerSettings
class BaseReactionHandler: class BaseReactionHandler:
def __init__( def __init__(
self, self,
logger: LoggerABC, logger: MessageLogger,
bot: DiscordBotServiceABC, bot: DiscordBotServiceABC,
servers: ServerRepositoryABC, servers: ServerRepositoryABC,
users: UserRepositoryABC, users: UserRepositoryABC,

View File

@ -274,6 +274,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
self._logger.debug(__name__, f"Start checking UserJoinedVoiceChannel table") self._logger.debug(__name__, f"Start checking UserJoinedVoiceChannel table")
for guild in self._bot.guilds: for guild in self._bot.guilds:
guild: discord.Guild = guild guild: discord.Guild = guild
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{guild.id}")
server = self._servers.find_server_by_discord_id(guild.id) server = self._servers.find_server_by_discord_id(guild.id)
if server is None: if server is None:
@ -299,7 +300,6 @@ class DatabaseOnReadyEvent(OnReadyABC):
f"Active UserJoinedVoiceChannel found in database: {guild.id}:{member.id}@{join.joined_on}", f"Active UserJoinedVoiceChannel found in database: {guild.id}:{member.id}@{join.joined_on}",
) )
join.leaved_on = datetime.now() join.leaved_on = datetime.now()
settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{guild.id}")
if ( if (
(join.leaved_on - join.joined_on).total_seconds() / 60 / 60 (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") self._logger.trace(__name__, f"User {member.id} is ignored, because its a bot")
continue continue
if member.voice is None: if member.voice is None or member.voice.channel.id in settings.afk_channel_ids:
continue continue
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id) user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
# imports

View 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": []
}
}

View File

@ -0,0 +1,80 @@
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()