lunarflu HF staff commited on
Commit
78dea1a
1 Parent(s): 42530b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -35
app.py CHANGED
@@ -1,55 +1,46 @@
1
- import os
 
2
  from slack_sdk import WebClient
3
  from slack_sdk.errors import SlackApiError
4
- from flask import Flask, request, Response
5
 
6
- app = Flask(__name__)
7
-
8
- SLACK_TOKEN = os.getenv('SLACK_TOKEN')
9
- SLACK_SIGNING_SECRET = os.getenv('SIGNING_SECRET')
10
- TARGET_CHANNEL_ID = os.getenv('CHANNEL_ID')
11
 
12
  TRIGGERS = {
13
- "urgent": "<@U061W3NRFFA>",
14
- "help": "<@U061W3NRFFA>",
15
  }
16
 
17
- slack_client = WebClient(token=SLACK_TOKEN)
18
-
19
- @app.route("/slack/events", methods=["POST"])
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
- return Response(status=200)
 
31
 
32
- def verify_slack_request(request):
33
- return True
 
34
 
35
- def handle_message_event(event):
36
- user = event.get("user")
37
- text = event.get("text").lower()
38
- channel = event.get("channel")
39
 
 
40
  for trigger, slack_mention in TRIGGERS.items():
41
- if trigger in text:
42
- post_to_slack(channel, slack_mention, text)
43
  break
44
 
45
- def post_to_slack(channel, slack_mention, text):
46
  try:
47
  response = slack_client.chat_postMessage(
48
- channel=TARGET_CHANNEL_ID,
49
- text=f"{slack_mention} New message in <#{channel}>: {text}"
50
  )
51
  except SlackApiError as e:
52
  print(f"Error posting to Slack: {e.response['error']}")
53
 
54
- if __name__ == "__main__":
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)