Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
making ping cleaner and more informative
Browse files
app.py
CHANGED
@@ -11,9 +11,7 @@ SLACK_BOT_TOKEN = os.getenv('BOT_USER_OAUTH_TOKEN_HF')
|
|
11 |
SLACK_CHANNEL_ID = os.getenv('SLACK_CHANNEL_ID_HF')
|
12 |
|
13 |
TRIGGERS = {
|
14 |
-
"discord bot": "<@U051DB2754M>",
|
15 |
-
"setfit": "tom aarsen",
|
16 |
-
"cv": "merve",
|
17 |
}
|
18 |
|
19 |
intents = discord.Intents.all()
|
@@ -34,14 +32,15 @@ async def on_message(message):
|
|
34 |
content = message.content.lower()
|
35 |
for trigger, slack_mention in TRIGGERS.items():
|
36 |
if trigger in content:
|
37 |
-
await post_to_slack(message.author, message.content, message.channel, message.jump_url, slack_mention)
|
38 |
break
|
39 |
|
40 |
-
async def post_to_slack(author, content, channel, url, slack_mention):
|
41 |
try:
|
|
|
42 |
response = slack_client.chat_postMessage(
|
43 |
channel=SLACK_CHANNEL_ID,
|
44 |
-
text=f"{slack_mention}
|
45 |
)
|
46 |
except SlackApiError as e:
|
47 |
print(f"Error posting to Slack: {e.response['error']}")
|
|
|
11 |
SLACK_CHANNEL_ID = os.getenv('SLACK_CHANNEL_ID_HF')
|
12 |
|
13 |
TRIGGERS = {
|
14 |
+
"discord bot": "<@U051DB2754M>", # Adam
|
|
|
|
|
15 |
}
|
16 |
|
17 |
intents = discord.Intents.all()
|
|
|
32 |
content = message.content.lower()
|
33 |
for trigger, slack_mention in TRIGGERS.items():
|
34 |
if trigger in content:
|
35 |
+
await post_to_slack(message.author, message.content, message.channel.name, message.jump_url, slack_mention, trigger)
|
36 |
break
|
37 |
|
38 |
+
async def post_to_slack(author, content, channel, url, slack_mention, trigger):
|
39 |
try:
|
40 |
+
message_link = f"[#{channel}]({url})"
|
41 |
response = slack_client.chat_postMessage(
|
42 |
channel=SLACK_CHANNEL_ID,
|
43 |
+
text=f"{slack_mention} (for the keyword -> '{trigger}')\n|{message_link} |{author}: {content}"
|
44 |
)
|
45 |
except SlackApiError as e:
|
46 |
print(f"Error posting to Slack: {e.response['error']}")
|