Update app.py
Browse files
app.py
CHANGED
@@ -34,26 +34,23 @@ 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.content, slack_mention)
|
38 |
break
|
39 |
|
40 |
-
async def post_to_slack(content, 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']}")
|
48 |
|
49 |
-
|
50 |
def run_bot():
|
51 |
bot.run(DISCORD_TOKEN)
|
52 |
-
|
53 |
threading.Thread(target=run_bot).start()
|
54 |
-
|
55 |
def greet(name):
|
56 |
return "Hello " + name + "!"
|
57 |
-
|
58 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
59 |
demo.launch()
|
|
|
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} Discord message by {author} in {channel}:{content}\n{url}"
|
45 |
)
|
46 |
except SlackApiError as e:
|
47 |
print(f"Error posting to Slack: {e.response['error']}")
|
48 |
|
49 |
+
# runs discord bot in thread = helps avoid blocking calls
|
50 |
def run_bot():
|
51 |
bot.run(DISCORD_TOKEN)
|
|
|
52 |
threading.Thread(target=run_bot).start()
|
|
|
53 |
def greet(name):
|
54 |
return "Hello " + name + "!"
|
|
|
55 |
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
56 |
demo.launch()
|