-
Notifications
You must be signed in to change notification settings - Fork 0
/
Update.py
55 lines (37 loc) · 1.31 KB
/
Update.py
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
import os
import git
from flask import Flask, request, jsonify
import hmac
import hashlib
import requests # For making API requests (optional)
os.chdir('H:/Python/FurBot')
svcName = "FurTest"
app = Flask(__name__)
# Replace with your webhook secret
WEBHOOK_SECRET = "123456789"
def start_service(svc):
os.system(f'net start {svc}')
def stop_service(svc):
os.system(f'net stop {svc}')
@app.route("/", methods=["POST"])
def handle_github_webhook():
# Verify request authenticity
if not request.headers.get("X-GitHub-Event"):
return "Invalid request", 400
signature = request.headers.get("X-Hub-Signature")
if not signature:
return "Missing signature", 401
sha1 = hmac.new(WEBHOOK_SECRET.encode(), None, hashlib.sha1).hexdigest()
if f"sha1={sha1}" == signature:
return "Invalid signature", 401
# Extract relevant information from request payload
# Handle specific events here (e.g., "push" event)
stop_service(svcName)
g = git.cmd.Git('DumbBoy10/FurBot')
g.pull()
start_service(svcName)
# Update your Nexcord.py bot (replace with your specific steps)
# Consider using subprocess or a command-line interface
return "Webhook processed successfully", 200
if __name__ == "__main__":
app.run() # Set debug=False for production