Skip to content

Commit 76ec103

Browse files
authored
Merge pull request #148 from 0xEmma/sherlock
Add Sherlock Creator Role
2 parents 6993353 + f05b789 commit 76ec103

File tree

6 files changed

+234
-58
lines changed

6 files changed

+234
-58
lines changed

.test.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ ROLE_VIP_PLUS=9583772910112769506
6363

6464
ROLE_CHALLENGE_CREATOR=8215461011276950716
6565
ROLE_BOX_CREATOR=8215471011276950716
66+
ROLE_SHERLOCK_CREATOR=1384037506349011044
6667

6768
ROLE_RANK_ONE=7419955631011276950
6869
ROLE_RANK_TEN=7419955611011276950

src/core/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class Roles(BaseSettings):
119119
# Content Creation
120120
CHALLENGE_CREATOR: int
121121
BOX_CREATOR: int
122+
SHERLOCK_CREATOR: int
122123

123124
# Positions
124125
RANK_ONE: int
@@ -247,6 +248,7 @@ def get_post_or_rank(self, what: str) -> Optional[int]:
247248
"dedivip": self.roles.VIP_PLUS,
248249
"Challenge Creator": self.roles.CHALLENGE_CREATOR,
249250
"Box Creator": self.roles.BOX_CREATOR,
251+
"Sherlock Creator": self.roles.SHERLOCK_CREATOR,
250252
}.get(what)
251253

252254
def get_season(self, what: str):
@@ -347,6 +349,7 @@ def load_settings(env_file: str | None = None):
347349
"ALL_CREATORS": [
348350
global_settings.roles.BOX_CREATOR,
349351
global_settings.roles.CHALLENGE_CREATOR,
352+
global_settings.roles.SHERLOCK_CREATOR,
350353
],
351354
"ALL_POSITIONS": [
352355
global_settings.roles.RANK_ONE,

src/helpers/verification.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ def _process_creator_roles(htb_user_content: dict, guild: Guild) -> list[Role]:
473473
if challenge_creator_role:
474474
logger.debug("Adding challenge creator role to user.")
475475
roles.append(challenge_creator_role)
476+
477+
if htb_user_content.get("sherlocks"):
478+
sherlock_creator_role = guild.get_role(settings.roles.SHERLOCK_CREATOR)
479+
if sherlock_creator_role:
480+
logger.debug("Adding sherlock creator role to user.")
481+
roles.append(sherlock_creator_role)
476482
except Exception as e:
477483
logger.error(f"Error processing creator roles: {e}")
478484
return roles

src/webhooks/handlers/account.py

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,8 @@ async def _handle_account_linked(self, body: WebhookBody, bot: Bot) -> dict:
3333
"""
3434
Handles the account linked event.
3535
"""
36-
discord_id = self.validate_discord_id(
37-
self.get_property_or_trait(body, "discord_id")
38-
)
39-
account_id = self.validate_account_id(
40-
self.get_property_or_trait(body, "account_id")
41-
)
36+
discord_id = self.validate_discord_id(self.get_property_or_trait(body, "discord_id"))
37+
account_id = self.validate_account_id(self.get_property_or_trait(body, "account_id"))
4238

4339
member = await self.get_guild_member(discord_id, bot)
4440
await process_account_identification(
@@ -55,9 +51,7 @@ async def _handle_account_linked(self, body: WebhookBody, bot: Bot) -> dict:
5551
f"Account linked: {account_id} -> ({member.mention} ({member.id})",
5652
)
5753
else:
58-
self.logger.warning(
59-
f"Verify logs channel {settings.channels.VERIFY_LOGS} not found"
60-
)
54+
self.logger.warning(f"Verify logs channel {settings.channels.VERIFY_LOGS} not found")
6155
except Exception as e:
6256
self.logger.error(f"Failed to send verification log: {e}")
6357
# Don't raise - this is not critical
@@ -73,17 +67,14 @@ async def _handle_account_unlinked(self, body: WebhookBody, bot: Bot) -> dict:
7367
"""
7468
Handles the account unlinked event.
7569
"""
76-
discord_id = self.validate_discord_id(
77-
self.get_property_or_trait(body, "discord_id")
78-
)
79-
account_id = self.validate_account_id(
80-
self.get_property_or_trait(body, "account_id")
81-
)
70+
discord_id = self.validate_discord_id(self.get_property_or_trait(body, "discord_id"))
71+
account_id = self.validate_account_id(self.get_property_or_trait(body, "account_id"))
8272

8373
member = await self.get_guild_member(discord_id, bot)
8474

8575
await member.remove_roles(
86-
bot.guilds[0].get_role(settings.roles.VERIFIED), atomic=True # type: ignore
76+
bot.guilds[0].get_role(settings.roles.VERIFIED),
77+
atomic=True, # type: ignore
8778
) # type: ignore
8879

8980
return self.success()
@@ -104,15 +95,9 @@ async def _handle_account_banned(self, body: WebhookBody, bot: Bot) -> dict:
10495
"""
10596
Handles the account banned event.
10697
"""
107-
discord_id = self.validate_discord_id(
108-
self.get_property_or_trait(body, "discord_id")
109-
)
110-
account_id = self.validate_account_id(
111-
self.get_property_or_trait(body, "account_id")
112-
)
113-
expires_at = self.validate_property(
114-
self.get_property_or_trait(body, "expires_at"), "expires_at"
115-
)
98+
discord_id = self.validate_discord_id(self.get_property_or_trait(body, "discord_id"))
99+
account_id = self.validate_account_id(self.get_property_or_trait(body, "account_id"))
100+
expires_at = self.validate_property(self.get_property_or_trait(body, "expires_at"), "expires_at")
116101
reason = body.properties.get("reason")
117102
notes = body.properties.get("notes")
118103
created_by = body.properties.get("created_by")
@@ -122,9 +107,7 @@ async def _handle_account_banned(self, body: WebhookBody, bot: Bot) -> dict:
122107

123108
member = await self.get_guild_member(discord_id, bot)
124109
if not member:
125-
self.logger.warning(
126-
f"Cannot ban user {discord_id}- not found in guild", extra=extra
127-
)
110+
self.logger.warning(f"Cannot ban user {discord_id}- not found in guild", extra=extra)
128111
return self.fail()
129112

130113
# Use the generic ban helper to handle all the complex logic
@@ -142,9 +125,7 @@ async def _handle_account_banned(self, body: WebhookBody, bot: Bot) -> dict:
142125
extra_log_data=extra,
143126
)
144127

145-
self.logger.debug(
146-
f"Platform ban handling result: {result['action']}", extra=extra
147-
)
128+
self.logger.debug(f"Platform ban handling result: {result['action']}", extra=extra)
148129

149130
return self.success()
150131

@@ -164,7 +145,8 @@ async def _handle_account_deleted(self, body: WebhookBody, bot: Bot) -> dict:
164145
return self.fail()
165146

166147
await member.remove_roles(
167-
bot.guilds[0].get_role(settings.roles.VERIFIED), atomic=True # type: ignore
148+
bot.guilds[0].get_role(settings.roles.VERIFIED),
149+
atomic=True, # type: ignore
168150
) # type: ignore
169151

170152
return self.success()

tests/src/core/test_config.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import unittest
2+
3+
from src.core import settings
4+
5+
6+
class TestConfig(unittest.TestCase):
7+
def test_sherlock_creator_role_in_all_creators(self):
8+
"""Test that SHERLOCK_CREATOR role is included in ALL_CREATORS group."""
9+
all_creators = settings.role_groups.get("ALL_CREATORS", [])
10+
self.assertIn(settings.roles.SHERLOCK_CREATOR, all_creators)
11+
self.assertIn(settings.roles.CHALLENGE_CREATOR, all_creators)
12+
self.assertIn(settings.roles.BOX_CREATOR, all_creators)
13+
14+
def test_get_post_or_rank_sherlock_creator(self):
15+
"""Test that get_post_or_rank returns correct role for Sherlock Creator."""
16+
result = settings.get_post_or_rank("Sherlock Creator")
17+
self.assertEqual(result, settings.roles.SHERLOCK_CREATOR)
18+
19+
def test_get_post_or_rank_other_creators(self):
20+
"""Test that get_post_or_rank works for all creator types."""
21+
test_cases = [
22+
("Challenge Creator", settings.roles.CHALLENGE_CREATOR),
23+
("Box Creator", settings.roles.BOX_CREATOR),
24+
("Sherlock Creator", settings.roles.SHERLOCK_CREATOR),
25+
]
26+
27+
for role_name, expected_role in test_cases:
28+
with self.subTest(role_name=role_name):
29+
result = settings.get_post_or_rank(role_name)
30+
self.assertEqual(result, expected_role)
31+
32+
def test_get_post_or_rank_invalid_role(self):
33+
"""Test that get_post_or_rank returns None for invalid role."""
34+
result = settings.get_post_or_rank("Invalid Role")
35+
self.assertIsNone(result)
36+
37+
def test_sherlock_creator_role_configured(self):
38+
"""Test that SHERLOCK_CREATOR role is properly configured."""
39+
self.assertIsNotNone(settings.roles.SHERLOCK_CREATOR)
40+
self.assertIsInstance(settings.roles.SHERLOCK_CREATOR, int)

0 commit comments

Comments
 (0)