1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-27 13:34:28 +00:00

Make more progress

This commit is contained in:
Steffo 2020-09-22 19:42:57 +02:00
parent 1928aaa2f5
commit 3f0b412024
9 changed files with 184 additions and 59 deletions

0
royalpack/__init__.py Normal file
View file

View file

@ -1,8 +1,9 @@
from typing import * from typing import *
import logging import logging
import aiohttp import steam.webapi
import royalnet.commands as rc import royalnet.commands as rc
import royalnet.utils as ru import royalnet.utils as ru
import requests
from royalnet.backpack import tables as rbt from royalnet.backpack import tables as rbt
from .abstract.linker import LinkerCommand from .abstract.linker import LinkerCommand
@ -12,6 +13,8 @@ from ..types import DotaRank
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class TrionfirealiCommand(LinkerCommand): class TrionfirealiCommand(LinkerCommand):
name: str = "trionfireali" name: str = "trionfireali"

View file

View file

@ -0,0 +1,76 @@
from typing import *
import abc
import aiohttp
if TYPE_CHECKING:
from .trionfistatus import TrionfiStatus
__all__ = [
"Check",
"CheckPlayedSteamGame",
"CheckAchievementSteamGame",
]
class Check(metaclass=abc.ABCMeta):
@abc.abstractmethod
async def check(self, status: "TrionfiStatus") -> bool:
raise NotImplementedError()
class CheckPlayedSteamGame(Check):
def __init__(self, appid: int, *args, **kwargs):
super().__init__(*args, **kwargs)
self.appid: int = appid
async def check(self, status: "TrionfiStatus") -> bool:
async with aiohttp.ClientSession() as ah_session:
# noinspection PyProtectedMember
async with ah_session.get("https://api.steampowered.com/IPlayerService/GetOwnedGames/v1/",
params={
"steamid": status._steamid,
"include_appinfo": True,
"include_played_free_games": True,
"include_free_sub": True,
"appids_filter": self.appid,
}) as response:
try:
j = await response.json()
except Exception:
return False
games = j["response"]["games"]
for game in games:
if game["appid"] != self.appid:
continue
if game["playtime_forever"] >= 1:
return True
return False
class CheckAchievementSteamGame(Check):
def __init__(self, appid: int, achievement_name: str, *args, **kwargs):
super().__init__(*args, **kwargs)
self.appid: int = appid
self.achivement_name: str = achievement_name
async def check(self, status: "TrionfiStatus") -> bool:
async with aiohttp.ClientSession() as ah_session:
# noinspection PyProtectedMember
async with ah_session.get("http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v1/",
params={
"steamid": status._steamid,
"appid": self.appid,
}) as response:
try:
j = await response.json()
except Exception:
return False
achievements = j["playerstats"]["achievements"]
for ach in achievements:
if ach["apiname"] != self.achivement_name:
continue
return ach["achieved"] == 1
return False

View file

@ -1,168 +1,170 @@
from typing import * from .trionfoinfo import TrionfoInfo
from .check import *
trionfilist = (
class Halloween2020Tarot: TrionfoInfo(
def __init__(self,
variable: str,
title: str,
roman: str,
name: str,
objective: str,
puzzle: str,
check: Optional[Callable[..., Awaitable[...]]]):
self.variable: str = variable
self.title: str = title
self.roman: str = roman
self.name: str = name
self.objective: str = objective
self.puzzle: str = puzzle
self.check: Optional[Callable[..., Awaitable[...]]] = check
halloween2020tarots = (
Halloween2020Tarot(
variable="zero", variable="zero",
title="o", title="o",
roman="0", roman="0",
name="Il Folle", name="Il Folle",
puzzle="IL DESTINO TI ATTENDE",
objective="Partecipa ai Trionfi Reali.", objective="Partecipa ai Trionfi Reali.",
puzzle="Scopri nuovi indizi ottenendo dei Trionfi!",
check=None, check=None,
), ),
Halloween2020Tarot( TrionfoInfo(
variable="i", variable="i",
title="i", title="i",
roman="I", roman="I",
name="Il Mago", name="Il Mago",
objective="Trova una magia che possa fare almeno 250 danni.", puzzle="L'ULTIMO GIORNO",
puzzle="L'ultimo giorno del decimo mese...", objective="Trova una /spell che possa fare almeno 250 danni.",
check=None, check=None,
), ),
Halloween2020Tarot( TrionfoInfo(
variable="ii", variable="ii",
title="ii", title="ii",
roman="II", roman="II",
name="La Papessa", name="La Sacerdotessa",
puzzle="DEL DECIMO MESE",
objective="Gioca almeno un'ora a [url=https://store.steampowered.com/app/881100]Noita[/url].",
check=CheckPlayedSteamGame(881100),
), ),
Halloween2020Tarot( TrionfoInfo(
variable="iii", variable="iii",
title="iii", title="iii",
roman="III", roman="III",
name="L'Imperatrice", name="L'Imperatrice",
puzzle="NON IMPEGNARTI",
objective="Gioca a [url=https://store.steampowered.com/app/245170]Skullgirls[/url].",
check=CheckPlayedSteamGame(245170),
), ),
Halloween2020Tarot( TrionfoInfo(
variable="iv", variable="iv",
title="iv", title="iv",
roman="IV", roman="IV",
name="L'Imperatore", name="L'Imperatore",
puzzle="ESEGUI GLI ORDINI",
objective="Vinci una partita su [url=https://store.steampowered.com/app/611500]Quake Champions[/url].",
check=CheckAchievementSteamGame(611500, "qc_victory")
), ),
Halloween2020Tarot( TrionfoInfo(
variable="v", variable="v",
title="v", title="v",
roman="V", roman="V",
name="Il Papa", name="Il Papa",
puzzle="ALLA SEDICESIMA ORA",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="vi", variable="vi",
title="vi", title="vi",
roman="VI", roman="VI",
name="Gli Amanti", name="Gli Amanti",
objective="Completa [url=https://store.steampowered.com/app/698780]Doki Doki " puzzle="ANCORA DIECI MINUTI",
"Literature Club[/url].", objective="Finisci l'Atto 3 di [url=https://store.steampowered.com/app/698780]Doki Doki Literature Club["
"/url].",
check=CheckPlayedSteamGame(698780),
), ),
Halloween2020Tarot( TrionfoInfo(
variable="vii", variable="vii",
title="vii", title="vii",
roman="VII", roman="VII",
name="Il Carro", name="Il Carro",
puzzle="SOPRA UN CARRO",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="viii", variable="viii",
title="viii", title="viii",
roman="VIII", roman="VIII",
name="La Giustizia", name="La Giustizia",
objective="Porta la giustizia dalla tua parte su [url=https://store.steampowered.com/app/1289310]Helltaker["
"/url].",
check=CheckAchievementSteamGame(1289310, "achiev_05"),
), ),
Halloween2020Tarot( TrionfoInfo(
variable="ix", variable="ix",
title="ix", title="ix",
roman="IX", roman="IX",
name="L'Eremita", name="L'Eremita",
puzzle="SEGRETAMENTE",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="x", variable="x",
title="x", title="x",
roman="X", roman="X",
name="La Fortuna", name="La Fortuna",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xi", variable="xi",
title="xi", title="xi",
roman="XI", roman="XI",
name="La Forza", name="La Forza",
objective="Gioca 3 partite Ranked 1v1 su "
"[url=https://steamcommunity.com/id/steffo1999/stats/appid/291550/achievements]Brawlhalla[/url]."
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xii", variable="xii",
title="xii", title="xii",
roman="XII", roman="XII",
name="L'Appeso", name="L'Appeso",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xiii", variable="xiii",
title="xiii", title="xiii",
roman="XIII", roman="XIII",
name="La Morte", name="La Morte",
objective="Raggiungi la Tenuta dell'Antenato su [url=https://store.steampowered.com/app/262060]Darkest Dungeon["
"/url].",
check=CheckAchievementSteamGame(262060, "welcome_home"),
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xiv", variable="xiv",
title="xiv", title="xiv",
roman="XIV", roman="XIV",
name="La Temperanza", name="La Temperanza",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xv", variable="xv",
title="xv", title="xv",
roman="XV", roman="XV",
name="Il Diavolo", name="Il Diavolo",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xvi", variable="xvi",
title="xvi", title="xvi",
roman="XVI", roman="XVI",
name="La Torre", name="La Torre",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xvii", variable="xvii",
title="xvii", title="xvii",
roman="XVII", roman="XVII",
name="Le Stelle", name="Le Stelle",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xviii", variable="xviii",
title="xviii", title="xviii",
roman="XVIII", roman="XVIII",
name="La Luna", name="La Luna",
objective="Gioca a [url=https://store.steampowered.com/app/388880]Oxenfree[/url].",
check=CheckPlayedSteamGame(388880),
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xix", variable="xix",
title="xix", title="xix",
roman="XIX", roman="XIX",
name="Il Sole", name="Il Sole",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xx", variable="xx",
title="xx", title="xx",
roman="XX", roman="XX",
name="Il Giudizio", name="Il Giudizio",
), ),
Halloween2020Tarot( TrionfoInfo(
variable="xxi", variable="xxi",
title="xxi", title="xxi",
roman="XII", roman="XII",
name="Il Mondo", name="Il Mondo",
objective="Risolvi il mistero dei Trionfi Reali.",
puzzle="""44°35'45.0"N 11°02'58.9"E""", puzzle="""44°35'45.0"N 11°02'58.9"E""",
objective="Risolvi il mistero dei Trionfi Reali.",
check=None, check=None,
), ),
) )

View file

@ -3,8 +3,8 @@ from sqlalchemy.orm import relationship, backref
from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.ext.declarative import declared_attr
class Halloween2020: class TrionfiStatus:
__tablename__ = "halloween2020" __tablename__ = "trionfistatus"
@declared_attr @declared_attr
def _steamid(self): def _steamid(self):
@ -12,7 +12,7 @@ class Halloween2020:
@declared_attr @declared_attr
def steam(self): def steam(self):
return relationship("Steam", backref=backref("halloween2020", uselist=False)) return relationship("Steam", backref=backref("trionfistatus", uselist=False))
@declared_attr @declared_attr
def zero(self): def zero(self):

View file

@ -0,0 +1,44 @@
import royalnet.utils as ru
from typing import *
if TYPE_CHECKING:
from .check import Check
class TrionfoInfo:
def __init__(self,
variable: str,
title: str,
roman: str,
name: str,
objective: str,
puzzle: str,
check: Optional["Check"]):
self.variable: str = variable
self.title: str = title
self.roman: str = roman
self.name: str = name
self.objective: str = objective
self.puzzle: str = puzzle
self.check: Optional["Check"] = check
def json_anonymous(self) -> ru.JSON:
return {
"variable": self.variable,
"title": self.title,
"roman": self.roman,
"name": self.name,
"objective": self.objective,
}
def json_user(self, obj) -> ru.JSON:
status = obj.__getattribute__(self.variable)
return {
"variable": self.variable,
"title": self.title,
"roman": self.roman,
"name": self.name,
"objective": self.objective,
"puzzle": self.puzzle if status is not None else None,
"completed_on": status
}

View file

@ -19,7 +19,7 @@ from .mmresponse import MMResponse
from .cvstats import Cvstats from .cvstats import Cvstats
from .treasure import Treasure from .treasure import Treasure
from .osu import Osu from .osu import Osu
from .halloween2020 import Halloween2020 from ..halloween2020.trionfistatus import Halloween2020
# Enter the tables of your Pack here! # Enter the tables of your Pack here!
available_tables = [ available_tables = [

View file

@ -77,7 +77,7 @@ class Steam:
"dota": self.dota.json() if self.dota is not None else None, "dota": self.dota.json() if self.dota is not None else None,
"brawlhalla": self.brawlhalla.json() if self.brawlhalla is not None else None, "brawlhalla": self.brawlhalla.json() if self.brawlhalla is not None else None,
"halloween2020": self.halloween2020.json() if self.halloween2020 is not None else None, "trionfistatus": self.trionfistatus.json() if self.trionfistatus is not None else None,
} }
def __repr__(self): def __repr__(self):