-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
69 lines (55 loc) · 2.07 KB
/
app.py
File metadata and controls
69 lines (55 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
from flask import Flask, request, jsonify, abort
import discord
from discord.ext import tasks
import asyncio
from collections import deque
import threading
app = Flask(__name__)
# Define the necessary intents
intents = discord.Intents.default()
intents.messages = True
intents.guilds = True
# Initialize the Discord client with the required intents
client = discord.Client(intents=intents)
BOT_TOKEN = os.environ.get('BOT_TOKEN')
CHANNEL_ID = 1142072323311144962
# Create a queue to hold messages that we want to send to Discord
message_queue = deque()
@tasks.loop(seconds=5)
async def background_task():
while message_queue:
data = message_queue.popleft()
print(f"Sending to Discord: {data}") # Debug print
channel = client.get_channel(CHANNEL_ID)
content = f"Transaction Alert: {data}"
try:
await channel.send(content)
except Exception as e:
print(f"Error sending message: {e}")
@app.route('/', methods=['POST'])
def webhook_listener():
webhook_token = request.headers.get('Arkham-Webhook-Token')
valid_tokens = {'Kep9w4rCgMx09o', 'Token2', 'Token3'} # Add your valid tokens to this set
if webhook_token not in valid_tokens:
abort(403) # Forbidden, incorrect token
data = request.json
print(data)
# Append data to our queue
message_queue.append(data)
print(f"Current Queue: {message_queue}") # Debug print
return jsonify({"message": "Received and forwarded"}), 200
@client.event
async def on_ready():
print(f'Logged in as {client.user.name}({client.user.id})')
target_channel = client.get_channel(CHANNEL_ID)
await target_channel.send(
"Script now running watching for Arkham Alerts")
background_task.start()
def run_discord():
asyncio.run(client.start(BOT_TOKEN))
if __name__ == '__main__':
# Start the Discord bot in a separate thread
threading.Thread(target=run_discord, daemon=True).start()
# Run the Flask app in the main thread
app.run(host='0.0.0.0')