1.0.0 #253
@ -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