-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (51 loc) · 2.34 KB
/
main.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
61
62
from mee6_py_api.api import API
import asyncio
import time
import sys
import requests
import configparser
config = configparser.RawConfigParser()
config.read('config.txt')
settings = dict(config.items('CONFIG'))\
guild_id = settings['guild_id']
user_id = settings['user_id']
url = settings['url']
# Check if user has at least change some of the config settings.
if guild_id == "12345678901234567":
print("CHANGE SETTINGS IN CONFIG.TXT")
sys.exit()
class TestClass: # I have a class here because that's what the example code had for the API and I'm too lazy to change it.
def __init__(self):
self.mee6API = API(guild_id)
async def test_get_leaderboard_page(self): #Gets all the data from the first page of the leaderboard.
leaderboard_page = await self.mee6API.levels.get_leaderboard_page(0)
return leaderboard_page
def test_has_passed_userXP(self):
f = open("rank.txt", "r") # Check what rank you currently are. Saved in rank.txt
my_rank = int(f.read())
f.close()
leaderboard = asyncio.run(testClass.test_get_leaderboard_page())
for i in range(0,100): # Check the first 100 people to see if they match with var user_id
time.sleep(1)
print(leaderboard["players"][i]["id"])
if leaderboard["players"][i]["id"] == str(user_id): # Check if user_id matches. API stores info in nested dicts & lists
if my_rank < i:
# Webhook stuff
data = {
"content" : f"<@{user_id}>, you have been passed! You are now in rank {i + 1}."
}
result = requests.post(url, json=data)
# Check for errors
if 200 <= result.status_code < 300:
print(f"Webhook sent {result.status_code}")
else:
print(f"Not sent with {result.status_code}, response:\n{result.json()}")
# Save the new rank in rank.txt
w = open("rank.txt", "w")
w.write(str(i))
w.close()
break
testClass = TestClass()
while True: # Keep program running
testClass.test_has_passed_userXP()
time.sleep(60) # You can only earn xp every minute with Mee6, no use in checking more often