-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
49 lines (32 loc) · 1.26 KB
/
app.py
File metadata and controls
49 lines (32 loc) · 1.26 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
import requests
from flask import Flask
from flask import jsonify, request
import config
import converter
from utils import get_ip
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
sentry_sdk.init(
dsn=config.SENTRY_DNS,
integrations=[FlaskIntegration()]
)
app = Flask(__name__)
@app.route("/")
def get_your_ip():
real_ip = request.environ.get('HTTP_X_REAL_IP', request.remote_addr)
data = {'ip': get_ip(request.remote_addr), 'real_ip': real_ip}
return jsonify(data)
@app.route('/api/webhooks/convert')
def convert():
discord_webhook_url = request.args.get('webhook_url', '')
forwarder_webhook_url = discord_webhook_url.replace(config.DISCORD_BASE_URL, config.FORWARDER_BASE_URL)
return forwarder_webhook_url
@app.route('/api/webhooks/<channel_id>/<token>/<type>', methods=['GET', 'POST'])
def forward(channel_id, token, type):
# dest_url = '{}/api/webhooks/{}/{}'.format(DISCORD_BASE_URL, channel_id, token)
dest_url = '{}/api/webhooks/{}/{}/slack'.format(config.DISCORD_BASE_URL, channel_id, token)
origin_data = request.get_json()
if type == 'sentry':
discord_data = converter.convert_sentry(origin_data)
res = requests.post(dest_url, json=discord_data)
return jsonify(res.content)