Skip to content

Commit 7853386

Browse files
committed
Raise hard error if user tries to use mention without backend installed
Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
1 parent 2702314 commit 7853386

4 files changed

Lines changed: 9 additions & 3 deletions

File tree

csp_bot/backends/discord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ class DiscordAdapterConfig(BaseModel):
2020
class DiscordMessage(Struct):
2121
_ignore: str = ""
2222

23-
mention_user_discord = lambda x: x # noqa: E731
23+
mention_user_discord = None

csp_bot/backends/slack.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ class SlackAdapterConfig(BaseModel):
2121
class SlackMessage(Struct):
2222
_ignore: str = ""
2323

24-
mention_user_slack = lambda x: x # noqa: E731
24+
mention_user_slack = None

csp_bot/backends/symphony.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ class SymphonyAdapterConfig(BaseModel):
2424
class SymphonyMessage(Struct):
2525
_ignore: str = ""
2626

27-
mention_user_symphony = lambda x: x # noqa: E731
27+
mention_user_symphony = None

csp_bot/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,18 @@ def recursive_format_for_message_ml(d):
5656

5757
def mention_user(email_or_userid: str = "", backend: Backend = "symphony") -> str:
5858
if backend == "symphony":
59+
if mention_user_symphony is None:
60+
raise ImportError("Symphony adapter is not available.")
5961
return mention_user_symphony(email_or_userid)
6062
elif backend == "slack":
6163
if not email_or_userid.startswith("@"):
6264
email_or_userid = f"@{email_or_userid}"
65+
if mention_user_slack is None:
66+
raise ImportError("Slack adapter is not available.")
6367
return mention_user_slack(email_or_userid)
6468
elif backend == "discord":
69+
if mention_user_discord is None:
70+
raise ImportError("Discord adapter is not available.")
6571
return mention_user_discord(email_or_userid)
6672
else:
6773
raise NotImplementedError(f"Unsupported backend: {backend}")

0 commit comments

Comments
 (0)