From 0fcd56b52f63a1933c953b1bd2917295563e34e3 Mon Sep 17 00:00:00 2001 From: Toby Jones Date: Mon, 18 Mar 2024 15:54:16 +0000 Subject: [PATCH] feat(verify): Add unverified role, which is removed on verify and re-added on unverify --- config.example.json | 6 +++++- harmony_services/db.py | 9 ++++++--- harmony_ui/verify.py | 12 ++++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/config.example.json b/config.example.json index 3fb894c..f7039c2 100644 --- a/config.example.json +++ b/config.example.json @@ -9,7 +9,8 @@ "bot_token": "", "guild_id": 0, "harmony_management_role_id": 0, - "verified_role_id": 0 + "verified_role_id": 0, + "unverified_role_id": 0 }, "reddit": { "client_id": "", @@ -78,5 +79,8 @@ "rate_limit_seconds": 3600 } ] + }, + "feedback": { + "feedback_channel_id": 0 } } \ No newline at end of file diff --git a/harmony_services/db.py b/harmony_services/db.py index 7159bd5..c7331ab 100644 --- a/harmony_services/db.py +++ b/harmony_services/db.py @@ -4,16 +4,19 @@ import harmony_models.feedback as feedback_models import harmony_models.message_rate_limiter as message_rate_limiter_models +from loguru import logger from harmony_config import config db_name = config.get_configuration_key("db.db_name", required=True) db_host = config.get_configuration_key("db.hostname", required=True) db_port = config.get_configuration_key("db.port", required=True, expected_type=int) -db_username = config.get_configuration_key("db.username", required=True) -db_password = config.get_configuration_key("db.password", required=True) +db_username = config.get_configuration_key("db.username") +db_password = config.get_configuration_key("db.password") db_replica_set = config.get_configuration_key("db.replica_set_name") -_mongodb_connection_string = f"mongodb://{db_username}:{db_password}@{db_host}:{db_port}/{db_name}" +_mongodb_connection_string_credentials = f"{db_username}:{db_password}@" if db_username and db_password else "" + +_mongodb_connection_string = f"mongodb://{_mongodb_connection_string_credentials}{db_host}:{db_port}/{db_name}" if db_replica_set: _mongodb_connection_string += f"?replicaSet={db_replica_set}" diff --git a/harmony_ui/verify.py b/harmony_ui/verify.py index 4d12e7e..34c635c 100644 --- a/harmony_ui/verify.py +++ b/harmony_ui/verify.py @@ -22,6 +22,11 @@ required=True, expected_type=int )) +unverified_role = discord.Object(config.get_configuration_key( + "discord.unverified_role_id", + required=True, + expected_type=int +)) user_management_role = discord.Object(config.get_configuration_key( "discord.harmony_management_role_id", required=True, @@ -246,12 +251,13 @@ def update_db(pending_verification: verify_models.PendingVerification): pending_verification.delete() @staticmethod - async def assign_role(member: discord.Member) -> typing.NoReturn: + async def update_roles(member: discord.Member) -> typing.NoReturn: """ Assign the configured role to the specified member. :param member: The member to whom the role should be assigned. :return: Nothing. """ + await member.remove_roles(unverified_role, reason="Verified using Harmony Bot") await member.add_roles(verified_role, reason="Verified using Harmony Bot") async def complete_verification(self, interaction: discord.Interaction) -> typing.NoReturn: @@ -261,7 +267,7 @@ async def complete_verification(self, interaction: discord.Interaction) -> typin if pending_verification.pending_verification_data.verification_code == entered_code: self.update_db(pending_verification) - await self.assign_role(interaction.user) + await self.update_roles(interaction.user) await interaction.response.send_message("Done! You've successfully linked your Reddit account.", ephemeral=True) @@ -290,6 +296,8 @@ async def unverify(self, interaction: discord.Interaction): verification_data.delete() await interaction.user.remove_roles(verified_role, reason="Unverified using Harmony Bot") + await interaction.user.add_roles(unverified_role, reason="Unverified using Harmony Bot") + await interaction.response.send_message("Unverified successfully.", ephemeral=True) else: await interaction.response.send_message(