1.0.0-fix #254

Merged
edraft merged 6 commits from 1.0.0-fix into 1.0.0 2023-03-20 14:41:33 +01:00
5 changed files with 70 additions and 28 deletions
Showing only changes of commit e1c89814da - Show all commits

View File

@ -14,25 +14,32 @@
"permission": "src/modules/permission/permission.json",
"stats": "src/modules/stats/stats.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",
"tools/checks": "tools/tools/checks/tools/checks.json"
"set-version": "tools/set_version/set-version.json"
},
"Scripts": {
"format": "black ./",
"sv": "cpl set-version $ARGS",
"set-version": "cpl run set-version $ARGS --dev; echo '';",
"gv": "cpl get-version",
"get-version": "export VERSION=$(cpl run get-version --dev); echo $VERSION;",
"pre-build": "cpl set-version $ARGS; black ./;",
"post-build": "cpl run post-build --dev; black ./;",
"pre-prod": "cpl build",
"prod": "export KDB_ENVIRONMENT=production; export KDB_NAME=KDB-Prod; cpl start;",
"pre-stage": "cpl build",
"stage": "export KDB_ENVIRONMENT=staging; export KDB_NAME=KDB-Stage; cpl start;",
"pre-dev": "cpl build",
"dev": "export KDB_ENVIRONMENT=development; export KDB_NAME=KDB-Dev; cpl start;",
"docker-build": "cpl build $ARGS; docker build -t kdb-bot/kdb-bot:$(cpl gv) .;",
"dc-up": "docker-compose up -d",
"dc-down": "docker-compose down",

View File

@ -16,7 +16,7 @@
"LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [
"cpl-core==2022.12.1.post2",
"cpl-core==2022.12.1.post3",
"cpl-translation==2022.12.1",
"cpl-query==2022.12.2.post1",
"cpl-discord==2022.12.1.post2",
@ -31,7 +31,7 @@
"icmplib==3.0.3"
],
"DevDependencies": [
"cpl-cli==2022.12.1.post2"
"cpl-cli==2022.12.1.post3"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {},

View File

@ -48,7 +48,7 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
self._logger.info(__name__, f"Module {type(self)} loaded")
def _update_voice_state(self, joined: bool, dc_user_id: int, dc_channel_id: int, server: Server, switch=False):
def _switch_voice_state(self, dc_user_id: int, before_dc_channel_id: int, after_dc_channel_id: int, server: Server):
user: Optional[User] = None
try:
user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, server.server_id)
@ -62,16 +62,50 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
try:
end_date = datetime.now()
if joined and not switch:
join = UserJoinedVoiceChannel(user, before_dc_channel_id, end_date)
self._user_joins_vc.add_user_joined_voice_channel(join)
settings: BaseServerSettings = self._base_helper.get_config(server.discord_server_id)
join = self._user_joins_vc.get_active_user_joined_voice_channel_by_user_id(user.user_id)
join.leaved_on = end_date
# ontime as hours
ontime = round((join.leaved_on - join.joined_on).total_seconds() / 3600, 2)
old_xp = user.xp
user.xp += round(ontime * settings.xp_per_ontime_hour)
self._user_joins_vc.update_user_joined_voice_channel(join)
self._users.update_user(user)
self._db.save_changes()
self._logger.debug(
__name__,
f"User {user} leaved_on {join.leaved_on}. Ontime: {ontime}h | xp: from {old_xp} to {user.xp}",
)
except Exception as e:
self._logger.error(__name__, f"Ontime validation failed", e)
def _update_voice_state(self, joined: bool, dc_user_id: int, dc_channel_id: int, server: Server):
user: Optional[User] = None
try:
user = self._users.get_user_by_discord_id_and_server_id(dc_user_id, server.server_id)
except Exception as e:
self._logger.error(__name__, f"Cannot get user {dc_user_id}", e)
return
if user is None:
self._logger.error(__name__, f"User not found {dc_user_id}")
return
try:
end_date = datetime.now()
if joined:
join = UserJoinedVoiceChannel(user, dc_channel_id, end_date)
self._user_joins_vc.add_user_joined_voice_channel(join)
self._db.save_changes()
return
elif joined and switch:
join = UserJoinedVoiceChannel(user, dc_channel_id, end_date)
self._user_joins_vc.add_user_joined_voice_channel(join)
settings: BaseServerSettings = self._base_helper.get_config(server.discord_server_id)
join = self._user_joins_vc.get_active_user_joined_voice_channel_by_user_id(user.user_id)
@ -139,8 +173,11 @@ class BaseOnVoiceStateUpdateEvent(OnVoiceStateUpdateABC):
self._logger.trace(__name__, f"User {member.id} left {before.channel}")
self._update_voice_state(False, member.id, before.channel.id, server)
else:
elif (
before.channel.id not in settings.afk_channel_ids
and after.channel.id not in settings.afk_channel_ids
):
self._logger.trace(__name__, f"User {member.id} switched to {after.channel}")
self._update_voice_state(True, member.id, before.channel.id, server, True)
self._switch_voice_state(member.id, before.channel.id, after.channel.id, server)
except Exception as e:
self._logger.error(__name__, f"Cannot handle voice state for user {member.id}", e)

View File

@ -271,6 +271,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:
@ -296,7 +297,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
@ -312,7 +312,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.server_id)

View File

@ -6,25 +6,23 @@
"Minor": "0",
"Micro": "0"
},
"Author": "",
"AuthorEmail": "",
"Description": "",
"LongDescription": "",
"URL": "",
"CopyrightDate": "",
"CopyrightName": "",
"LicenseName": "",
"LicenseDescription": "",
"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.1.post3"
"cpl-core==2022.12.0"
],
"DevDependencies": [
"cpl-cli>=2022.12.1.post3"
"cpl-cli==2022.12.0"
],
"PythonVersion": ">=3.10.4",
"PythonPath": {
"linux": ""
},
"PythonPath": {},
"Classifiers": []
},
"BuildSettings": {