Improved warning handling #35
This commit is contained in:
parent
19f47a01e5
commit
1eb625fe7a
@ -213,7 +213,8 @@
|
||||
"messages": {
|
||||
"first": "Bei der nächsten verwarnung, wirst du auf das vorherige Level zurückgesetzt!",
|
||||
"second": "Bei der nächsten verwarnung, wirst du auf das erste Level zurückgesetzt!",
|
||||
"third": "Bei der nächsten verwarnung, wirst du gekickt und zurückgesetzt!"
|
||||
"third": "Bei der nächsten verwarnung, wirst du gekickt und zurückgesetzt!",
|
||||
"kick": "Ich musste {} aufgrund zu vieler Verwarnungen kicken"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -57,4 +57,4 @@ class BaseOnVoiceStateUpdateEventHelpChannel(OnVoiceStateUpdateABC):
|
||||
a,
|
||||
)
|
||||
|
||||
self._logger.debug(__name__, f"Module {type(self)} stopped")
|
||||
self._logger.debug(__name__, f"Module {type(self)} stopped")
|
||||
|
@ -10,6 +10,7 @@ from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.abc.user_warning_repository_abc import UserWarningsRepositoryABC
|
||||
from bot_data.model.user_warnings import UserWarnings
|
||||
from modules.level.service.level_service import LevelService
|
||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||
|
||||
|
||||
class UserWarningsService:
|
||||
@ -25,6 +26,7 @@ class UserWarningsService:
|
||||
level_service: LevelService,
|
||||
message_service: MessageServiceABC,
|
||||
t: TranslatePipe,
|
||||
permissions: PermissionServiceABC,
|
||||
):
|
||||
self._logger = logger
|
||||
self._db = db
|
||||
@ -36,6 +38,7 @@ class UserWarningsService:
|
||||
self._level_service = level_service
|
||||
self._message_service = message_service
|
||||
self._t = t
|
||||
self._permissions = permissions
|
||||
|
||||
async def add_warnings(self, guild_id: int, member_id: int, description: str, author_id: int = None):
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
@ -57,41 +60,49 @@ class UserWarningsService:
|
||||
self._t.transform("modules.base.warnings.message").format(warning.description), member
|
||||
)
|
||||
|
||||
match existing_warnings.count():
|
||||
case 1:
|
||||
await self._message_service.send_dm_message(
|
||||
self._t.transform("modules.base.warnings.messages.first"), member
|
||||
)
|
||||
case 2:
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member_id, server.id)
|
||||
level = self._level_service.get_level(user)
|
||||
levels = self._levels.get_levels_by_server_id(server.id).order_by(lambda l: l.min_xp)
|
||||
if existing_warnings.count() == 1:
|
||||
await self._message_service.send_dm_message(
|
||||
self._t.transform("modules.base.warnings.messages.first"), member
|
||||
)
|
||||
elif existing_warnings.count() == 2:
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member_id, server.id)
|
||||
level = self._level_service.get_level(user)
|
||||
levels = self._levels.get_levels_by_server_id(server.id).order_by(lambda l: l.min_xp)
|
||||
|
||||
new_level = levels.where(lambda l: l.min_xp < level.min_xp).last()
|
||||
user.xp = new_level.min_xp
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
await self._message_service.send_dm_message(
|
||||
self._t.transform("modules.base.warnings.messages.second"), member
|
||||
)
|
||||
case 3:
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member_id, server.id)
|
||||
levels = self._levels.get_levels_by_server_id(server.id)
|
||||
new_level = levels.where(lambda l: l.min_xp < level.min_xp).last()
|
||||
user.xp = new_level.min_xp
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
await self._message_service.send_dm_message(
|
||||
self._t.transform("modules.base.warnings.messages.second"), member
|
||||
)
|
||||
elif existing_warnings.count() == 3:
|
||||
server = self._servers.get_server_by_discord_id(guild_id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member_id, server.id)
|
||||
levels = self._levels.get_levels_by_server_id(server.id)
|
||||
|
||||
new_level = levels.where(lambda l: l.min_xp > 0).order_by(lambda l: l.min_xp).last()
|
||||
user.xp = new_level.min_xp
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
new_level = levels.where(lambda l: l.min_xp > 0).order_by(lambda l: l.min_xp).last()
|
||||
user.xp = new_level.min_xp
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
await self._message_service.send_dm_message(
|
||||
self._t.transform("modules.base.warnings.messages.third"), member
|
||||
)
|
||||
elif existing_warnings.count() >= 4:
|
||||
user.xp = 0
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
await member.kick()
|
||||
mods = [
|
||||
*self._permissions.get_admins(member.guild.id),
|
||||
*self._permissions.get_moderators(member.guild.id),
|
||||
]
|
||||
for a in mods:
|
||||
await self._message_service.send_dm_message(
|
||||
self._t.transform("modules.base.warnings.messages.third"), member
|
||||
self._t.transform("modules.base.warnings.messages.kick").format(member.mention),
|
||||
a,
|
||||
)
|
||||
case 4:
|
||||
user.xp = 0
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
await member.kick()
|
||||
|
||||
def remove_warnings(self, id: int):
|
||||
warning = self._warnings.get_user_warnings_by_id(id)
|
||||
|
Loading…
Reference in New Issue
Block a user