mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-24 03:54:20 +00:00
Improved levelup code
This commit is contained in:
parent
8fea42680e
commit
f42dc376bf
2 changed files with 24 additions and 15 deletions
33
main.py
33
main.py
|
@ -2,6 +2,7 @@ import asyncio
|
||||||
import discord
|
import discord
|
||||||
import json
|
import json
|
||||||
import overwatch
|
import overwatch
|
||||||
|
import strings as s
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
d_client = discord.Client()
|
d_client = discord.Client()
|
||||||
|
@ -12,25 +13,29 @@ db = json.load(file)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
# Get the discord bot token from "discordtoken.txt"
|
# Get the discord bot token from "discordtoken.txt"
|
||||||
f = open("discordtoken.txt", "r")
|
file = open("discordtoken.txt", "r")
|
||||||
token = f.read()
|
token = file.read()
|
||||||
f.close()
|
file.close()
|
||||||
|
|
||||||
# List overwatch players
|
|
||||||
ow_players = list()
|
|
||||||
for player in db:
|
|
||||||
if db[player]["overwatch"] is not None:
|
|
||||||
ow_players.append(db[player]["overwatch"])
|
|
||||||
|
|
||||||
# Every 300 seconds, update player status and check for levelups
|
# Every 300 seconds, update player status and check for levelups
|
||||||
async def overwatch_level_up(timeout):
|
async def overwatch_level_up(timeout):
|
||||||
while True:
|
while True:
|
||||||
# Update data for every player in list
|
# Update data for every player in list
|
||||||
for ow_player in ow_players:
|
for player in db:
|
||||||
r = await overwatch.get_player_data(**ow_player)
|
if db[player]["overwatch"] is not None:
|
||||||
if r["data"]["level"] > ow_player["level"]:
|
r = await overwatch.get_player_data(**db[player]["overwatch"])
|
||||||
await d_client.send_message(d_client.get_channel("213655027842154508"), "Level up!")
|
if r["data"]["level"] > db[player]["overwatch"]["level"]:
|
||||||
ow_player["level"] = r["data"]["level"]
|
# Convert user ID into a mention
|
||||||
|
user = "<@" + player + ">"
|
||||||
|
# Prepare the message to send
|
||||||
|
msg = s.overwatch_level_up.format(player=user, level=r["data"]["level"])
|
||||||
|
# Send the message to the discord channel
|
||||||
|
loop.create_task(d_client.send_message(d_client.get_channel("213655027842154508"), msg))
|
||||||
|
db[player]["overwatch"]["level"] = r["data"]["level"]
|
||||||
|
# Update database
|
||||||
|
f = open("db.json", "w")
|
||||||
|
json.dump(db, f)
|
||||||
|
f.close()
|
||||||
# Wait for the timeout
|
# Wait for the timeout
|
||||||
await asyncio.sleep(timeout)
|
await asyncio.sleep(timeout)
|
||||||
|
|
||||||
|
|
4
strings.py
Normal file
4
strings.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
# Overwatch: Level up!
|
||||||
|
# {player} = player
|
||||||
|
# {level} = new level
|
||||||
|
overwatch_level_up = "{player} è salito al livello **{level}** su Overwatch!"
|
Loading…
Reference in a new issue