-
-
Save lerokko/2cbc985050d4e1717e9d19d151db8618 to your computer and use it in GitHub Desktop.
Scripts that shouts in discord when paper releases a new build (via webhook)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#. env file | |
MINECRAFT_VERSION="1.19.2" | |
WEBHOOK_URL="put your webhook's url in these quotation marks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Run this for everytime you want to check if paper released a new build. If it did this will post a discord messsage via webhook. The build number is cached in a file so MAKE SURE TO HAVE WRITE ACCESS TO WHERE YOU RUN IT. IT WIL CREATE A FILE. Provide a .env file with The webhooks url and the minecraft version you want to check. | |
#I just run this in a cron job every 5 mins :) | |
#https://opensource.org/licenses/GPL-3.0 (I guess) | |
#Disclaimer: I am not a coder. Feel free to impove this, or rip it to shreds, it works for me :) HF | |
import os | |
import requests | |
import json | |
from dotenv import load_dotenv | |
load_dotenv() | |
VERSION = os.getenv('MINECRAFT_VERSION') | |
webhook_url = os.getenv('WEBHOOK_URL') | |
current_build = 0 | |
#create file if not exist | |
try: | |
file = open("latest_build", 'r') | |
except IOError: | |
file = open("latest_build", 'w') | |
#get cached build number | |
with open('latest_build', 'r') as file: | |
current_build = int(file.read()) | |
print("Last known build", current_build) | |
paper_url = "https://api.papermc.io/v2/projects/paper/versions/" + VERSION | |
try: | |
response = requests.get(paper_url) | |
json_data = json.loads(response.text) | |
latest_build = json_data['builds'][-1] | |
except: | |
print("Invalid URL or some error occured while making the GET request to the specified URL") | |
if latest_build > current_build: | |
print("New paper build found:", latest_build) | |
dl_link = "https://api.papermc.io/v2/projects/paper/versions/%s/builds/%s/downloads/paper-%s-%s.jar"%(json_data['version'],latest_build,json_data['version'],latest_build) | |
print(dl_link) | |
current_build = latest_build | |
with open('latest_build', 'w') as file: | |
file.write(str(current_build)) | |
#for all params, see https://discordapp.com/developers/docs/resources/webhook#execute-webhook | |
data = { | |
"content" : "", | |
} | |
#leave this out if you dont want an embed | |
#for all params, see https://discordapp.com/developers/docs/resources/channel#embed-object | |
data["embeds"] = [ | |
{ | |
"description" : dl_link, | |
"title" : "Honey wake up new paper build just dropped" | |
} | |
] | |
result = requests.post(webhook_url, json = data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment