mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Some new spooky stuff
This commit is contained in:
parent
1f3f78ac65
commit
7d59664c48
6 changed files with 1589 additions and 58 deletions
124
db.py
124
db.py
|
@ -12,6 +12,7 @@ import re
|
|||
import enum
|
||||
from discord import User as DiscordUser
|
||||
from telegram import User as TelegramUser
|
||||
import loldata
|
||||
|
||||
# Init the config reader
|
||||
import configparser
|
||||
|
@ -353,6 +354,7 @@ class LeagueOfLegends(Base):
|
|||
royal = relationship("Royal", backref="lol", lazy="joined")
|
||||
|
||||
summoner_id = Column(BigInteger, primary_key=True)
|
||||
account_id = Column(BigInteger)
|
||||
summoner_name = Column(String)
|
||||
|
||||
level = Column(Integer)
|
||||
|
@ -370,31 +372,6 @@ class LeagueOfLegends(Base):
|
|||
return f"<LeagueOfLegends {self.summoner_id}>"
|
||||
return f"<LeagueOfLegends {(''.join([x if x.isalnum else '' for x in self.summoner_name]))}>"
|
||||
|
||||
@staticmethod
|
||||
def create(session: Session, royal_id, summoner_name=None, summoner_id=None):
|
||||
if summoner_name:
|
||||
lol = session.query(LeagueOfLegends).filter(LeagueOfLegends.summoner_name == summoner_name).first()
|
||||
elif summoner_id:
|
||||
lol = session.query(LeagueOfLegends).get(summoner_id)
|
||||
else:
|
||||
raise SyntaxError("Neither summoner_name or summoner_id were specified.")
|
||||
if lol is not None:
|
||||
raise AlreadyExistingError(repr(lol))
|
||||
# Get the summoner_id
|
||||
if summoner_name:
|
||||
r = requests.get(f"https://euw1.api.riotgames.com/lol/summoner/v3/summoners/by-name/{summoner_name}?api_key={config['League of Legends']['riot_api_key']}")
|
||||
else:
|
||||
r = requests.get(f"https://euw1.api.riotgames.com/lol/summoner/v3/summoners/{summoner_id}?api_key={config['League of Legends']['riot_api_key']}")
|
||||
if r.status_code != 200:
|
||||
return RequestError(f"League of Legends API returned {r.status_code}")
|
||||
data = r.json()
|
||||
lol = LeagueOfLegends(royal_id=royal_id,
|
||||
summoner_id=data["id"],
|
||||
summoner_name=data["name"],
|
||||
level=data["summonerLevel"])
|
||||
lol.update()
|
||||
return lol
|
||||
|
||||
def update(self) -> bool:
|
||||
r = requests.get(f"https://euw1.api.riotgames.com/lol/summoner/v3/summoners/{self.summoner_id}?api_key={config['League of Legends']['riot_api_key']}")
|
||||
if r.status_code != 200:
|
||||
|
@ -420,6 +397,7 @@ class LeagueOfLegends(Base):
|
|||
twtr_rank = league
|
||||
self.summoner_id = data["id"]
|
||||
self.summoner_name = data["name"]
|
||||
self.account_id = data["accountId"]
|
||||
self.level = data["summonerLevel"]
|
||||
if solo_rank is not None:
|
||||
self.solo_division = LeagueOfLegendsRanks[solo_rank["tier"]]
|
||||
|
@ -441,6 +419,14 @@ class LeagueOfLegends(Base):
|
|||
self.twtr_rank = None
|
||||
self.highest_mastery_champ = mastery[0]["championId"]
|
||||
|
||||
def highest_mastery_champ_name(self):
|
||||
champ = loldata.get_champ_by_key(self.highest_mastery_champ)
|
||||
return champ["name"]
|
||||
|
||||
def highest_mastery_champ_image(self):
|
||||
champ = loldata.get_champ_by_key(self.highest_mastery_champ)
|
||||
return loldata.get_champ_icon(champ["name"])
|
||||
|
||||
|
||||
class Osu(Base):
|
||||
__tablename__ = "osu"
|
||||
|
@ -894,16 +880,92 @@ class LoginToken(Base):
|
|||
return f"<LoginToken for {self.royal.username}>"
|
||||
|
||||
|
||||
class EETrigger(Base):
|
||||
__tablename__ = "eetriggers"
|
||||
class Halloween(Base):
|
||||
"""This is some nice spaghetti, don't you think?"""
|
||||
__tablename__ = "halloween"
|
||||
|
||||
royal_id = Column(Integer, ForeignKey("royals.id"), primary_key=True)
|
||||
royal = relationship("Royal", backref="triggers", lazy="joined")
|
||||
royal = relationship("Royal", backref="halloween", lazy="joined")
|
||||
|
||||
stage = Column(String, nullable=False)
|
||||
first_trigger = Column(DateTime)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<EETrigger of {self.royal.username}: {self.stage}>"
|
||||
puzzle_piece_a = Column(DateTime)
|
||||
puzzle_piece_b = Column(DateTime)
|
||||
puzzle_piece_c = Column(DateTime)
|
||||
puzzle_piece_d = Column(DateTime)
|
||||
puzzle_piece_e = Column(DateTime)
|
||||
puzzle_piece_f = Column(DateTime)
|
||||
puzzle_piece_g = Column(DateTime)
|
||||
puzzle_piece_h = Column(DateTime)
|
||||
puzzle_piece_i = Column(DateTime)
|
||||
puzzle_piece_j = Column(DateTime)
|
||||
|
||||
boss_battle = Column(DateTime)
|
||||
|
||||
def pieces_completed(self) -> int:
|
||||
count = 0
|
||||
if puzzle_piece_a is not None:
|
||||
count += 1
|
||||
if puzzle_piece_b is not None:
|
||||
count += 1
|
||||
if puzzle_piece_c is not None:
|
||||
count += 1
|
||||
if puzzle_piece_d is not None:
|
||||
count += 1
|
||||
if puzzle_piece_e is not None:
|
||||
count += 1
|
||||
if puzzle_piece_f is not None:
|
||||
count += 1
|
||||
if puzzle_piece_g is not None:
|
||||
count += 1
|
||||
if puzzle_piece_h is not None:
|
||||
count += 1
|
||||
if puzzle_piece_i is not None:
|
||||
count += 1
|
||||
if puzzle_piece_j is not None:
|
||||
count += 1
|
||||
return count
|
||||
|
||||
@staticmethod
|
||||
def puzzle_is_complete() -> bool:
|
||||
session = db.Session()
|
||||
halloweens = session.query(Halloween).all()
|
||||
session.close()
|
||||
completed_a = False
|
||||
completed_b = False
|
||||
completed_c = False
|
||||
completed_d = False
|
||||
completed_e = False
|
||||
completed_f = False
|
||||
completed_g = False
|
||||
completed_h = False
|
||||
completed_i = False
|
||||
completed_j = False
|
||||
for halloween in halloweens:
|
||||
if halloween.puzzle_piece_a is not None:
|
||||
completed_a = True
|
||||
if halloween.puzzle_piece_b is not None:
|
||||
completed_b = True
|
||||
if halloween.puzzle_piece_c is not None:
|
||||
completed_c = True
|
||||
if halloween.puzzle_piece_d is not None:
|
||||
completed_d = True
|
||||
if halloween.puzzle_piece_d is not None:
|
||||
completed_d = True
|
||||
if halloween.puzzle_piece_e is not None:
|
||||
completed_e = True
|
||||
if halloween.puzzle_piece_f is not None:
|
||||
completed_f = True
|
||||
if halloween.puzzle_piece_g is not None:
|
||||
completed_g = True
|
||||
if halloween.puzzle_piece_h is not None:
|
||||
completed_h = True
|
||||
if halloween.puzzle_piece_i is not None:
|
||||
completed_i = True
|
||||
if halloween.puzzle_piece_j is not None:
|
||||
completed_j = True
|
||||
return (completed_a and completed_b and completed_c and completed_d and completed_e
|
||||
and completed_f and completed_g and completed_h and completed_i and completed_j)
|
||||
|
||||
|
||||
# If run as script, create all the tables in the db
|
||||
|
|
1447
loldata.py
Normal file
1447
loldata.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,12 +1,11 @@
|
|||
@background-color: #0d193b;
|
||||
@text-color: #a0ccff;
|
||||
@background-color: #0d0303;
|
||||
@text-color: #ff8080;
|
||||
@quote-color: #a0ffcc;
|
||||
@spoiler-color: #ffa0cc;
|
||||
@highlight-color: #ffff95;
|
||||
@accent-color: white;
|
||||
@accent-color: #ffcccc;
|
||||
@link-color: #00aaff;
|
||||
@visited-color: #aa66ff;
|
||||
@old-ryg-color: #ff7f00;
|
||||
|
||||
body {
|
||||
font-family: sans-serif;
|
||||
|
@ -127,6 +126,7 @@ nav {
|
|||
width: 32px;
|
||||
height: 32px;
|
||||
vertical-align: middle;
|
||||
border-radius: 32px;
|
||||
}
|
||||
|
||||
.left
|
||||
|
@ -482,7 +482,7 @@ table {
|
|||
border: 3px solid #463714;
|
||||
background-color: #010a13;
|
||||
grid-row-gap: 5px;
|
||||
grid-template-columns: 40% 20% 20% 20%;
|
||||
grid-template-columns: 20% 20% 20% 20% 20%;
|
||||
|
||||
.player {
|
||||
grid-row: 1;
|
||||
|
@ -502,18 +502,26 @@ table {
|
|||
font-size: x-large;
|
||||
}
|
||||
|
||||
.soloq {
|
||||
.mastery {
|
||||
grid-column: 2;
|
||||
}
|
||||
|
||||
.flexq {
|
||||
.game-score.mastery {
|
||||
border-radius: 40px;
|
||||
}
|
||||
|
||||
.soloq {
|
||||
grid-column: 3;
|
||||
}
|
||||
|
||||
.twtrq {
|
||||
.flexq {
|
||||
grid-column: 4;
|
||||
}
|
||||
|
||||
.twtrq {
|
||||
grid-column: 5;
|
||||
}
|
||||
|
||||
.game-title {
|
||||
text-align: center;
|
||||
}
|
||||
|
@ -641,7 +649,7 @@ table {
|
|||
}
|
||||
|
||||
.ryg {
|
||||
background-color: rgba(red(@accent-color), green(@accent-color), blue(@accent-color), 0.1);
|
||||
background-color: rgba(red(@text-color), green(@text-color), blue(@text-color), 0.1);
|
||||
padding: 18px;
|
||||
grid-template-columns: 80% 20%;
|
||||
|
||||
|
@ -769,7 +777,7 @@ table {
|
|||
}
|
||||
}
|
||||
|
||||
.entry {
|
||||
ntry {
|
||||
display: grid;
|
||||
|
||||
.left {
|
||||
|
@ -870,22 +878,26 @@ table {
|
|||
}
|
||||
}
|
||||
|
||||
.ee {
|
||||
color: @old-ryg-color;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline #ff7f00;
|
||||
@keyframes shake {
|
||||
0%, 100% {
|
||||
transform: translate(2px, 2px);
|
||||
}
|
||||
|
||||
&:active {
|
||||
text-decoration: underline white;
|
||||
20%, 80% {
|
||||
transform: translate(-2px, -2px);
|
||||
}
|
||||
}
|
||||
|
||||
.eeclear {
|
||||
opacity: 0.8;
|
||||
cursor: help;
|
||||
40% {
|
||||
transform: translate(2px, -2px);
|
||||
}
|
||||
|
||||
60% {
|
||||
transform: translate(-2px, 2px);
|
||||
}
|
||||
|
||||
10%, 30%, 50%, 70%, 90% {
|
||||
transform: translate(0px, 0px);
|
||||
}
|
||||
}
|
||||
|
||||
#debug-mode {
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
mode: "same-origin",
|
||||
credentials: "same-origin"
|
||||
});
|
||||
document.getElementById("main-title").innerHTML = '<span class="eeclear" title="Soon, my pupil.">R</span>oyal Games';
|
||||
document.getElementById("main-title").innerHTML = '<span class="eetip" title="When there is something strange, in the neighbourhood, who you gonna call?">R</span>oyal Games';
|
||||
audio.play();
|
||||
}
|
||||
</script>
|
||||
|
@ -22,7 +22,7 @@
|
|||
|
||||
{% block body %}
|
||||
<h1 id="main-title">
|
||||
<span {% if triggerable_r %}class="ee" onclick="ee()" {% else %}class="eeclear" title="Soon, my pupil."{% endif %}>R</span>oyal Games
|
||||
Royal Games
|
||||
</h1>
|
||||
<div class="main-page">
|
||||
<div class="left">
|
||||
|
|
|
@ -16,6 +16,12 @@
|
|||
<div class="game-score level">
|
||||
<span>{{ record.level }}</span>
|
||||
</div>
|
||||
<div class="game-title mastery">
|
||||
MAIN
|
||||
</div>
|
||||
<div class="game-score mastery">
|
||||
<img src="{{ record.highest_mastery_champ_image() }}" title="{{ record.highest_mastery_champ_name() }}" class="rank">
|
||||
</div>
|
||||
<div class="game-title soloq">
|
||||
SOLO/DUO
|
||||
</div>
|
||||
|
|
10
webserver.py
10
webserver.py
|
@ -66,10 +66,9 @@ def page_main():
|
|||
random_diario = db_session.query(db.Diario).order_by(db.func.random()).first()
|
||||
next_events = db_session.query(db.Event).filter(db.Event.time > datetime.datetime.now()).order_by(
|
||||
db.Event.time).all()
|
||||
triggerable_r = not bool(db_session.query(db.EETrigger).filter_by(royal_id=fl_session["user_id"]).one_or_none())
|
||||
db_session.close()
|
||||
return render_template("main.html", royals=royals, wiki_pages=wiki_pages, entry=random_diario,
|
||||
next_events=next_events, rygconf=config, escape=escape, triggerable_r=triggerable_r)
|
||||
next_events=next_events, rygconf=config, escape=escape)
|
||||
|
||||
|
||||
@app.route("/profile/<name>")
|
||||
|
@ -208,7 +207,12 @@ def page_game(name: str):
|
|||
elif name == "lol":
|
||||
game_name = "League of Legends"
|
||||
query = db_session.query(db.LeagueOfLegends).order_by(db.LeagueOfLegends.solo_division.desc().nullslast(),
|
||||
db.LeagueOfLegends.solo_rank).all()
|
||||
db.LeagueOfLegends.solo_rank,
|
||||
db.LeagueOfLegends.flex_division.desc().nullslast(),
|
||||
db.LeagueOfLegends.flex_rank,
|
||||
db.LeagueOfLegends.twtr_division.desc().nullslast(),
|
||||
db.LeagueOfLegends.twtr_rank,
|
||||
db.LeagueOfLegends.level).all()
|
||||
elif name == "osu":
|
||||
game_name = "osu!"
|
||||
query = db_session.query(db.Osu).order_by(db.Osu.mania_pp.desc().nullslast()).all()
|
||||
|
|
Loading…
Reference in a new issue