-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.py
60 lines (51 loc) · 2.05 KB
/
bot.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
56
57
58
59
60
import requests
from bs4 import BeautifulSoup
import time
import re
import urllib.parse
from discordwebhook import Discord
# Discord webhook URL
discord = Discord(url="REPLACE WITH YOUR WEBHOOK")
# The last commit id we've seen
last_commit_id = 0
while True:
# Request the page
try:
response = requests.get('https://commits.facepunch.com/r/rust_reboot')
soup = BeautifulSoup(response.text, 'html.parser')
# Find the first commit
commit = soup.find('div', {'class' :'commit columns'})
# Extract the commit id
commit_id = int(soup.find('div', {'class' :'commit columns'})['like-id'])
# If this is a new commit
if commit_id > last_commit_id:
# Update the last commit id
last_commit_id = commit_id
# Extract the commit details
author = commit.find('div', class_='author').text
repo = commit.find('span', class_='repo').text
branch = commit.find('span', class_='branch').text
changeset = commit.find('span', class_='changeset').text
commit_message = commit.find('div', class_='commits-message').text
avatar = commit.find('div', class_='avatar').fetchNextSiblings
avtr = re.search("(?P<url>https?://[^\s]+)", str(avatar)).group("url")[:-3]
# Create the message
# Send the message to the Discord webhook
discord.post(
embeds=[
{
"author": {
"name": str(author),
"url": "https://commits.facepunch.com/r/rust_reboot"
},
"title": str(repo)+str(branch)+str(changeset),
"description": str(commit_message),
"thumbnail": {"url": str(avtr)}
}
],
)
# Send the message to the Discord webhook
except:
print("error blehhhhh\n")
# Wait for 50 seconds
time.sleep(50)