Update app.py
Browse files
app.py
CHANGED
@@ -1,55 +1,46 @@
|
|
1 |
-
import
|
|
|
2 |
from slack_sdk import WebClient
|
3 |
from slack_sdk.errors import SlackApiError
|
4 |
-
from flask import Flask, request, Response
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
SLACK_SIGNING_SECRET = os.getenv('SIGNING_SECRET')
|
10 |
-
TARGET_CHANNEL_ID = os.getenv('CHANNEL_ID')
|
11 |
|
12 |
TRIGGERS = {
|
13 |
-
"urgent": "<@
|
14 |
-
"help": "<@
|
15 |
}
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
def slack_events():
|
21 |
-
if not verify_slack_request(request):
|
22 |
-
return Response(status=403)
|
23 |
-
|
24 |
-
data = request.json
|
25 |
-
if "event" in data:
|
26 |
-
event = data["event"]
|
27 |
-
if event.get("type") == "message" and not "subtype" in event:
|
28 |
-
handle_message_event(event)
|
29 |
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
|
|
40 |
for trigger, slack_mention in TRIGGERS.items():
|
41 |
-
if trigger in
|
42 |
-
post_to_slack(
|
43 |
break
|
44 |
|
45 |
-
def post_to_slack(
|
46 |
try:
|
47 |
response = slack_client.chat_postMessage(
|
48 |
-
channel=
|
49 |
-
text=f"{slack_mention} New message in
|
50 |
)
|
51 |
except SlackApiError as e:
|
52 |
print(f"Error posting to Slack: {e.response['error']}")
|
53 |
|
54 |
-
|
55 |
-
app.run(port=3000)
|
|
|
1 |
+
import discord
|
2 |
+
from discord.ext import commands
|
3 |
from slack_sdk import WebClient
|
4 |
from slack_sdk.errors import SlackApiError
|
|
|
5 |
|
6 |
+
DISCORD_T =
|
7 |
+
SLACK_T =
|
8 |
+
SLACK_CHANNEL_ID =
|
|
|
|
|
9 |
|
10 |
TRIGGERS = {
|
11 |
+
"urgent": "<@U12345678>",
|
12 |
+
"help": "<@U87654321>",
|
13 |
}
|
14 |
|
15 |
+
intents = discord.Intents.all()
|
16 |
+
intents.messages = True
|
17 |
+
bot = commands.Bot(command_prefix='!', intents=intents)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
# Set up the Slack client
|
20 |
+
slack_client = WebClient(token=SLACK_T)
|
21 |
|
22 |
+
@bot.event
|
23 |
+
async def on_ready():
|
24 |
+
print(f'Logged in as {bot.user}')
|
25 |
|
26 |
+
@bot.event
|
27 |
+
async def on_message(message):
|
28 |
+
if message.author == bot.user:
|
29 |
+
return
|
30 |
|
31 |
+
content = message.content.lower()
|
32 |
for trigger, slack_mention in TRIGGERS.items():
|
33 |
+
if trigger in content:
|
34 |
+
await post_to_slack(message.content, slack_mention)
|
35 |
break
|
36 |
|
37 |
+
async def post_to_slack(content, slack_mention):
|
38 |
try:
|
39 |
response = slack_client.chat_postMessage(
|
40 |
+
channel=SLACK_CHANNEL_ID,
|
41 |
+
text=f"{slack_mention} New message in Discord: {content}"
|
42 |
)
|
43 |
except SlackApiError as e:
|
44 |
print(f"Error posting to Slack: {e.response['error']}")
|
45 |
|
46 |
+
bot.run(DISCORD_T)
|
|