ClassiCube/misc/notify.py
2020-02-18 18:10:35 +11:00

64 lines
1.9 KiB
Python

import requests, re, datetime, json, time, os
# Any resemblence to any discord bots written by 123DMWM is purely coincidental. I swear.
# The URL of the discord channel webhook to notify
# You can generate a webhook by right clicking channel -> Edit Channel -> Webhooks
WEBHOOK_URL = ''
# The ID of the user you want to ping on a build failure
# You can get this by right clicking user -> Copy ID
# You may have to go to settings -> Appearance -> Check Developer Mode to see this option
TARGET_USER = ''
def notify_webhook(body):
try:
webhook_data = {
"username": "CC BuildBot",
"avatar_url": "https://static.classicube.net/img/cc-cube-small.png",
"content" : body
}
r = requests.post(WEBHOOK_URL, json=webhook_data)
print("BuildNotify response: " + r.text)
except Exception as e:
print("BuildNotify failed: %s" % (e))
def build_exists(file):
return os.path.exists('client/src/' + file)
builds = {
'Win32' : build_exists('cc-w32-d3d.exe'),
'Win64' : build_exists('cc-w64-d3d.exe'),
'Mac32' : build_exists('cc-osx32'),
'Mac64' : build_exists('cc-osx64'),
'Nix32' : build_exists('cc-nix32'),
'Nix64' : build_exists('cc-nix64'),
'Rpi' : build_exists('cc-rpi'),
'Web' : build_exists('cc.js'),
'Win-ogl32' : build_exists('cc-w32-ogl.exe'),
'Win-ogl64' : build_exists('cc-w64-ogl.exe'),
}
failed = []
def check_build(key):
key_32 = key + '32'
key_64 = key + '64'
if key in builds:
if not builds[key]:
failed.append(key)
else:
if not builds[key_32] and not builds[key_64]:
failed.append(key + '32/64')
elif not builds[key_32]:
failed.append(key_32)
elif not builds[key_64]:
failed.append(key_64)
check_build('Win')
check_build('Mac')
check_build('Nix')
check_build('Rpi')
check_build('Web')
if len(failed):
notify_webhook('<@%s>, failed to compile for: %s' % (TARGET_USER, ', '.join(failed)))