Skip to content

Commit

Permalink
Merge pull request #26 from hwsuk/feat/unverify-role
Browse files Browse the repository at this point in the history
feat(verify): Add unverified role, which is removed on verify and re-added on unverify
  • Loading branch information
emberdex authored Mar 18, 2024
2 parents af2beb9 + 0fcd56b commit e72d3d3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 5 additions & 1 deletion config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Expand Down Expand Up @@ -78,5 +79,8 @@
"rate_limit_seconds": 3600
}
]
},
"feedback": {
"feedback_channel_id": 0
}
}
9 changes: 6 additions & 3 deletions harmony_services/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
12 changes: 10 additions & 2 deletions harmony_ui/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e72d3d3

Please sign in to comment.