summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py68
1 files changed, 25 insertions, 43 deletions
diff --git a/main.py b/main.py
index e250b4e..3e246ae 100644
--- a/main.py
+++ b/main.py
@@ -41,8 +41,7 @@ async def connect(queuedb, db):
await queue.setup()
global pool
- pool = await asyncpg.create_pool(
- min_size=1, **db)
+ pool = await asyncpg.create_pool(**db)
@bot.event
@@ -52,9 +51,6 @@ async def on_ready():
"client_id=%s&scope=bot)",
bot.user.name, bot.user.id)
await connect(source_db, dest_db)
- await bot.change_presence(
- game=discord.Game(
- name="alpha.vainsocial.com"))
@bot.event
@@ -84,9 +80,7 @@ async def vainsocial(region: str, name: str):
query = """
SELECT
player.name,
- player.shard_id,
match.game_mode,
- roster.match_api_id,
participant.hero, participant.winner,
participant.kills, participant.deaths, participant.assists, participant.farm,
participant.skill_tier, player.played, player.wins,
@@ -99,18 +93,13 @@ async def vainsocial(region: str, name: str):
ORDER BY match.created_at DESC
LIMIT 1
"""
- def emb(dct):
- data = dict(dct)
-
- tiers = ["Just Beginning", "Getting There", "Rock Solid", "Worthy Foe", "Got Swagger", "Credible Threat", "The Hotness", "Simply Amazing", "Pinnacle Of Awesome", "Vainglorious"]
+ def msg(dct):
+ tiers = ["Just Beginning", "Getting There", "Rock Solid", "Got Swagger", "Credible Threat", "The Hotness", "Simply Amazing", "Pinnacle Of Awesome", "Vainglorious"]
if data["skill_tier"] == -1:
- data["tier"] = "Unranked"
- data["tier_num"] = "unranked"
+ tier = "Unranked"
else:
subtiers = ["Bronze", "Silver", "Gold"]
- data["tier"] = tiers[data["skill_tier"]//3] + " " + subtiers[data["skill_tier"] % 3]
- data["tier_num"] = data["skill_tier"]
-
+ tier = tiers[data["skill_tier"]//3-1] + " " + subtiers[data["skill_tier"]%3]
modes = {
"blitz_pvp_ranked": "Blitz",
"casual_aral": "Battle Royale",
@@ -119,30 +108,26 @@ async def vainsocial(region: str, name: str):
"private_party_blitz_match": "private Blitz",
"private_party_aral_match": "private Battle Royale"
}
- data["mode"] = modes.get(data["game_mode"]) or data["game_mode"]
+ mode = modes.get(data["game_mode"]) or data["game_mode"]
heroes = {
"Sayoc": "Taka",
"Hero009": "Krul",
"Hero010": "Skaarf",
"Hero016": "Rona"
}
- data["hero"] = data["hero"].replace("*", "")
- data["hero"] = heroes.get(data["hero"]) or data["hero"]
- data["result"] = "won" if data["winner"] else "lost"
+ data["hero"].replace("*", "")
+ hero = heroes.get(data["hero"]) or data["hero"]
- emb = discord.Embed(
- title="%(name)s" % data,
- url="https://alpha.vainsocial.com/players/%(shard_id)s/%(name)s" % data
+ return ("""
+%s: %s, %s wins / %s games
+Last match: %s %s as %s %s/%s/%s
+""") % (
+ data["name"], tier,
+ data["wins"], data["played"],
+ ("won" if data["winner"] else "lost"),
+ mode, hero,
+ data["kills"], data["deaths"], data["assists"]
)
- emb.set_author(name="Vainsocial",
- url="https://alpha.vainsocial.com")
- emb.add_field(name="Stats",
- value="%(tier)s, %(wins)i wins / %(played)i games" % data)
- emb.add_field(name="Last match",
- value="%(result)s %(mode)s as %(hero)s %(kills)i/%(deaths)i/%(assists)i" % data)
- emb.set_footer(text="Vainsocial - Vainglory social stats service")
- emb.set_thumbnail(url="https://alpha.vainsocial.com/images/game/skill_tiers/%(tier_num)s.png" % data)
- return emb
async with pool.acquire() as con:
await bot.type()
@@ -156,9 +141,7 @@ async def vainsocial(region: str, name: str):
else:
in_cache = True # returning user
lmcd = data["last_match_created_date"]
- msgid = await bot.say(embed=emb(data))
-
- logging.info("'%s' cached: %s", name, in_cache)
+ msgid = await bot.say(msg(data))
payload = {
"region": region,
@@ -167,9 +150,9 @@ async def vainsocial(region: str, name: str):
"filter[playerNames]": name
}
}
- jobid = (await queue.request(jobtype="grab",
- payload=[payload],
- priority=[1]))[0]
+ jobid = await queue.request(jobtype="grab",
+ payload=payload,
+ priority=1)
while True:
# wait for grab job to finish
@@ -177,21 +160,20 @@ async def vainsocial(region: str, name: str):
if status == 'finished':
break
if status == 'failed':
- logging.warning("'%s': not found", name)
if not in_cache:
- await bot.edit_message(msgid,
+ await bot.edit_message(
"Could not find you.")
return
- asyncio.sleep(0.5)
+ asyncio.sleep(0.1)
while True:
# wait for processor to update the player
data = await con.fetchrow(query, name, lmcd)
if data is not None:
break
- asyncio.sleep(0.5)
+ asyncio.sleep(0.1)
- await bot.edit_message(msgid, embed=emb(data))
+ await bot.edit_message(msgid, msg(data))
logging.basicConfig(level=logging.INFO)