1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Fix league and steam commands

This commit is contained in:
Steffo 2020-07-18 02:50:00 +02:00
parent 22d534f3e8
commit 28e98cef31
Signed by: steffo
GPG key ID: 896A80F55F7C97F0
8 changed files with 136 additions and 243 deletions

58
poetry.lock generated
View file

@ -178,7 +178,7 @@ description = "A Python wrapper for the Discord API"
name = "discord.py"
optional = false
python-versions = ">=3.5.3"
version = "1.3.3"
version = "1.3.4"
[package.dependencies]
aiohttp = ">=3.6.0,<3.7.0"
@ -402,7 +402,7 @@ description = "Alternative regular expression module, to replace re."
name = "regex"
optional = false
python-versions = "*"
version = "2020.6.8"
version = "2020.7.14"
[[package]]
category = "main"
@ -428,7 +428,7 @@ description = "RiotWatcher is a thin wrapper on top of the Riot Games API for Le
name = "riotwatcher"
optional = false
python-versions = "*"
version = "2.7.1"
version = "3.0.0"
[package.dependencies]
requests = "*"
@ -712,7 +712,7 @@ python-versions = "*"
version = "2020.6.16.1"
[metadata]
content-hash = "b0649ccbfdffd5947cbb0d4930182bd3b5edbf39181880db20e7b73ee85c9b02"
content-hash = "ff4adf9a29095096d1daf6aa1decde76d0bd045d614b589d954199d1e512316e"
python-versions = "^3.8"
[metadata.files]
@ -846,8 +846,8 @@ deprecation = [
{file = "deprecation-2.1.0.tar.gz", hash = "sha256:72b3bde64e5d778694b0cf68178aed03d15e15477116add3fb773e581f9518ff"},
]
"discord.py" = [
{file = "discord.py-1.3.3-py3-none-any.whl", hash = "sha256:406871b06d86c3dc49fba63238519f28628dac946fef8a0e22988ff58ec05580"},
{file = "discord.py-1.3.3.tar.gz", hash = "sha256:ad00e34c72d2faa8db2157b651d05f3c415d7d05078e7e41dc9e8dc240051beb"},
{file = "discord.py-1.3.4-py3-none-any.whl", hash = "sha256:8ef58d6fc1e66903bc00ae79c4c09a38aa71043e88a83da4d2e8b9b1c9f9b9e2"},
{file = "discord.py-1.3.4.tar.gz", hash = "sha256:1b546a32c0cd83d949392a71e5b06e30e19d1067246e3826d32ae9b8b3d06c1e"},
]
eyed3 = [
{file = "eyeD3-0.9.5-py2.py3-none-any.whl", hash = "sha256:94d475c0b55d9227a7f885f0be0f8433da9de6e5037e5164a524b042e78a2b62"},
@ -1014,35 +1014,35 @@ pytz = [
{file = "pytz-2020.1.tar.gz", hash = "sha256:c35965d010ce31b23eeb663ed3cc8c906275d6be1a34393a1d73a41febf4a048"},
]
regex = [
{file = "regex-2020.6.8-cp27-cp27m-win32.whl", hash = "sha256:fbff901c54c22425a5b809b914a3bfaf4b9570eee0e5ce8186ac71eb2025191c"},
{file = "regex-2020.6.8-cp27-cp27m-win_amd64.whl", hash = "sha256:112e34adf95e45158c597feea65d06a8124898bdeac975c9087fe71b572bd938"},
{file = "regex-2020.6.8-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:92d8a043a4241a710c1cf7593f5577fbb832cf6c3a00ff3fc1ff2052aff5dd89"},
{file = "regex-2020.6.8-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:bae83f2a56ab30d5353b47f9b2a33e4aac4de9401fb582b55c42b132a8ac3868"},
{file = "regex-2020.6.8-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:b2ba0f78b3ef375114856cbdaa30559914d081c416b431f2437f83ce4f8b7f2f"},
{file = "regex-2020.6.8-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:95fa7726d073c87141f7bbfb04c284901f8328e2d430eeb71b8ffdd5742a5ded"},
{file = "regex-2020.6.8-cp36-cp36m-win32.whl", hash = "sha256:e3cdc9423808f7e1bb9c2e0bdb1c9dc37b0607b30d646ff6faf0d4e41ee8fee3"},
{file = "regex-2020.6.8-cp36-cp36m-win_amd64.whl", hash = "sha256:c78e66a922de1c95a208e4ec02e2e5cf0bb83a36ceececc10a72841e53fbf2bd"},
{file = "regex-2020.6.8-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:08997a37b221a3e27d68ffb601e45abfb0093d39ee770e4257bd2f5115e8cb0a"},
{file = "regex-2020.6.8-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:2f6f211633ee8d3f7706953e9d3edc7ce63a1d6aad0be5dcee1ece127eea13ae"},
{file = "regex-2020.6.8-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:55b4c25cbb3b29f8d5e63aeed27b49fa0f8476b0d4e1b3171d85db891938cc3a"},
{file = "regex-2020.6.8-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:89cda1a5d3e33ec9e231ece7307afc101b5217523d55ef4dc7fb2abd6de71ba3"},
{file = "regex-2020.6.8-cp37-cp37m-win32.whl", hash = "sha256:690f858d9a94d903cf5cada62ce069b5d93b313d7d05456dbcd99420856562d9"},
{file = "regex-2020.6.8-cp37-cp37m-win_amd64.whl", hash = "sha256:1700419d8a18c26ff396b3b06ace315b5f2a6e780dad387e4c48717a12a22c29"},
{file = "regex-2020.6.8-cp38-cp38-manylinux1_i686.whl", hash = "sha256:654cb773b2792e50151f0e22be0f2b6e1c3a04c5328ff1d9d59c0398d37ef610"},
{file = "regex-2020.6.8-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:52e1b4bef02f4040b2fd547357a170fc1146e60ab310cdbdd098db86e929b387"},
{file = "regex-2020.6.8-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:cf59bbf282b627130f5ba68b7fa3abdb96372b24b66bdf72a4920e8153fc7910"},
{file = "regex-2020.6.8-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:5aaa5928b039ae440d775acea11d01e42ff26e1561c0ffcd3d805750973c6baf"},
{file = "regex-2020.6.8-cp38-cp38-win32.whl", hash = "sha256:97712e0d0af05febd8ab63d2ef0ab2d0cd9deddf4476f7aa153f76feef4b2754"},
{file = "regex-2020.6.8-cp38-cp38-win_amd64.whl", hash = "sha256:6ad8663c17db4c5ef438141f99e291c4d4edfeaacc0ce28b5bba2b0bf273d9b5"},
{file = "regex-2020.6.8.tar.gz", hash = "sha256:e9b64e609d37438f7d6e68c2546d2cb8062f3adb27e6336bc129b51be20773ac"},
{file = "regex-2020.7.14-cp27-cp27m-win32.whl", hash = "sha256:e46d13f38cfcbb79bfdb2964b0fe12561fe633caf964a77a5f8d4e45fe5d2ef7"},
{file = "regex-2020.7.14-cp27-cp27m-win_amd64.whl", hash = "sha256:6961548bba529cac7c07af2fd4d527c5b91bb8fe18995fed6044ac22b3d14644"},
{file = "regex-2020.7.14-cp36-cp36m-manylinux1_i686.whl", hash = "sha256:c50a724d136ec10d920661f1442e4a8b010a4fe5aebd65e0c2241ea41dbe93dc"},
{file = "regex-2020.7.14-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:8a51f2c6d1f884e98846a0a9021ff6861bdb98457879f412fdc2b42d14494067"},
{file = "regex-2020.7.14-cp36-cp36m-manylinux2010_i686.whl", hash = "sha256:9c568495e35599625f7b999774e29e8d6b01a6fb684d77dee1f56d41b11b40cd"},
{file = "regex-2020.7.14-cp36-cp36m-manylinux2010_x86_64.whl", hash = "sha256:51178c738d559a2d1071ce0b0f56e57eb315bcf8f7d4cf127674b533e3101f88"},
{file = "regex-2020.7.14-cp36-cp36m-win32.whl", hash = "sha256:9eddaafb3c48e0900690c1727fba226c4804b8e6127ea409689c3bb492d06de4"},
{file = "regex-2020.7.14-cp36-cp36m-win_amd64.whl", hash = "sha256:14a53646369157baa0499513f96091eb70382eb50b2c82393d17d7ec81b7b85f"},
{file = "regex-2020.7.14-cp37-cp37m-manylinux1_i686.whl", hash = "sha256:1269fef3167bb52631ad4fa7dd27bf635d5a0790b8e6222065d42e91bede4162"},
{file = "regex-2020.7.14-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:d0a5095d52b90ff38592bbdc2644f17c6d495762edf47d876049cfd2968fbccf"},
{file = "regex-2020.7.14-cp37-cp37m-manylinux2010_i686.whl", hash = "sha256:4c037fd14c5f4e308b8370b447b469ca10e69427966527edcab07f52d88388f7"},
{file = "regex-2020.7.14-cp37-cp37m-manylinux2010_x86_64.whl", hash = "sha256:bc3d98f621898b4a9bc7fecc00513eec8f40b5b83913d74ccb445f037d58cd89"},
{file = "regex-2020.7.14-cp37-cp37m-win32.whl", hash = "sha256:46bac5ca10fb748d6c55843a931855e2727a7a22584f302dd9bb1506e69f83f6"},
{file = "regex-2020.7.14-cp37-cp37m-win_amd64.whl", hash = "sha256:0dc64ee3f33cd7899f79a8d788abfbec168410be356ed9bd30bbd3f0a23a7204"},
{file = "regex-2020.7.14-cp38-cp38-manylinux1_i686.whl", hash = "sha256:5ea81ea3dbd6767873c611687141ec7b06ed8bab43f68fad5b7be184a920dc99"},
{file = "regex-2020.7.14-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:bbb332d45b32df41200380fff14712cb6093b61bd142272a10b16778c418e98e"},
{file = "regex-2020.7.14-cp38-cp38-manylinux2010_i686.whl", hash = "sha256:c11d6033115dc4887c456565303f540c44197f4fc1a2bfb192224a301534888e"},
{file = "regex-2020.7.14-cp38-cp38-manylinux2010_x86_64.whl", hash = "sha256:75aaa27aa521a182824d89e5ab0a1d16ca207318a6b65042b046053cfc8ed07a"},
{file = "regex-2020.7.14-cp38-cp38-win32.whl", hash = "sha256:d6cff2276e502b86a25fd10c2a96973fdb45c7a977dca2138d661417f3728341"},
{file = "regex-2020.7.14-cp38-cp38-win_amd64.whl", hash = "sha256:7a2dd66d2d4df34fa82c9dc85657c5e019b87932019947faece7983f2089a840"},
{file = "regex-2020.7.14.tar.gz", hash = "sha256:3a3af27a8d23143c49a3420efe5b3f8cf1a48c6fc8bc6856b03f638abc1833bb"},
]
requests = [
{file = "requests-2.24.0-py2.py3-none-any.whl", hash = "sha256:fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898"},
{file = "requests-2.24.0.tar.gz", hash = "sha256:b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b"},
]
riotwatcher = [
{file = "riotwatcher-2.7.1-py2.py3-none-any.whl", hash = "sha256:3fb03b20f768cea7830d54c6d301a8341c67223625ac8536d26d1c140af3dcb0"},
{file = "riotwatcher-2.7.1.tar.gz", hash = "sha256:5349271c7e00637b7619491a6070e66603705db60558ea2a690e7016f6e6d9a4"},
{file = "riotwatcher-3.0.0-py2.py3-none-any.whl", hash = "sha256:f00346692cd05c82450d7cfbdbf94e0de9553179daf612d08d1ffb163a091945"},
{file = "riotwatcher-3.0.0.tar.gz", hash = "sha256:bf8b8eb7e13c794730c18cd7846513cf22295a068204433117ce4d83a25b0fd2"},
]
royalnet = [
{file = "royalnet-5.10.3-py3-none-any.whl", hash = "sha256:1042a7383e26dbc76d03289d73f3c1b4d167cf860e272397b88ea54db0af513d"},

View file

@ -2,7 +2,7 @@
[tool.poetry]
name = "royalpack"
version = "5.12.1"
version = "5.12.2"
description = "A Royalnet command pack for the Royal Games community"
authors = ["Stefano Pigozzi <ste.pigozzi@gmail.com>"]
license = "AGPL-3.0+"
@ -20,7 +20,7 @@
[tool.poetry.dependencies]
python = "^3.8"
riotwatcher = "^2.7.1"
riotwatcher = "^3.0.0"
royalspells = "^3.2"
steam = "*"

View file

@ -19,8 +19,6 @@ class LinkerCommand(rc.Command, metaclass=abc.ABCMeta):
self.updater_task = None
if self.enabled():
# Run updaters only on Telegram
if self.interface.name == "telegram":
self.updater_task = self.loop.create_task(self.run_updater())
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
@ -139,7 +137,7 @@ class LinkerCommand(rc.Command, metaclass=abc.ABCMeta):
def enabled(self) -> bool:
"""Whether the updater is enabled or not."""
return self.config[self.name]["updater"]["enabled"]
return self.config[self.name]["updater"]["enabled"] and self.interface.name == "telegram"
def period(self) -> int:
"""The time between two updater cycles."""
@ -147,7 +145,7 @@ class LinkerCommand(rc.Command, metaclass=abc.ABCMeta):
def delay(self) -> int:
"""The time between two object updates."""
return self.config[self.name]["updater"]["rate"]
return self.config[self.name]["updater"]["delay"]
def target(self) -> int:
"""The id of the Telegram chat where notifications should be sent."""

View file

@ -27,15 +27,15 @@ class LeagueoflegendsCommand(LinkerCommand):
queue_names = {
"rank_soloq": "Solo/Duo",
"rank_flexq": "Flex",
"rank_twtrq": "3v3",
"rank_tftq": "TFT"
}
def __init__(self, interface: rc.CommandInterface):
super().__init__(interface)
self._riotwatcher: Optional[riotwatcher.RiotWatcher] = None
if self.interface.name == "telegram" and self.enabled():
self._riotwatcher = riotwatcher.RiotWatcher(api_key=self.token())
self._lolwatcher: Optional[riotwatcher.RiotWatcher] = None
self._tftwatcher: Optional[riotwatcher.RiotWatcher] = None
if self.enabled():
self._lolwatcher = riotwatcher.LolWatcher(api_key=self.token())
self._tftwatcher = riotwatcher.TftWatcher(api_key=self.token())
def token(self):
return self.config["leagueoflegends"]["token"]
@ -52,10 +52,6 @@ class LeagueoflegendsCommand(LinkerCommand):
string += f"Solo: {obj.rank_soloq}\n"
if obj.rank_flexq:
string += f"Flex: {obj.rank_flexq}\n"
if obj.rank_twtrq:
string += f"3v3: {obj.rank_twtrq}\n"
if obj.rank_tftq:
string += f"TFT: {obj.rank_tftq}\n"
return string
async def get_updatables_of_user(self, session, user: rbt.User) -> List[LeagueOfLegends]:
@ -69,7 +65,7 @@ class LeagueoflegendsCommand(LinkerCommand):
# Connect a new League of Legends account to Royalnet
log.debug(f"Searching for: {name}")
summoner = self._riotwatcher.summoner.by_name(region=self.region(), summoner_name=name)
summoner = self._lolwatcher.summoner.by_name(region=self.region(), summoner_name=name)
# Ensure the account isn't already connected to something else
leagueoflegends = await ru.asyncify(
session.query(self.alchemy.get(LeagueOfLegends)).filter_by(summoner_id=summoner["id"]).one_or_none)
@ -77,7 +73,7 @@ class LeagueoflegendsCommand(LinkerCommand):
raise rc.CommandError(f"L'account {leagueoflegends} è già registrato su Royalnet.")
# Get rank information
log.debug(f"Getting leagues data: {name}")
leagues = self._riotwatcher.league.by_summoner(region=self.region(),
leagues = self._lolwatcher.league.by_summoner(region=self.region(),
encrypted_summoner_id=summoner["id"])
soloq = LeagueLeague()
flexq = LeagueLeague()
@ -94,7 +90,7 @@ class LeagueoflegendsCommand(LinkerCommand):
tftq = LeagueLeague.from_dict(league)
# Get mastery score
log.debug(f"Getting mastery data: {name}")
mastery = self._riotwatcher.champion_mastery.scores_by_summoner(region=self.region(),
mastery = self._lolwatcher.champion_mastery.scores_by_summoner(region=self.region(),
encrypted_summoner_id=summoner["id"])
# Create database row
leagueoflegends = self.alchemy.get(LeagueOfLegends)(
@ -117,7 +113,7 @@ class LeagueoflegendsCommand(LinkerCommand):
async def update(self, session, obj: LeagueOfLegends, change: Callable[[str, Any], Awaitable[None]]):
log.debug(f"Getting summoner data: {obj}")
summoner = await ru.asyncify(self._riotwatcher.summoner.by_id, region=self.region(),
summoner = await ru.asyncify(self._lolwatcher.summoner.by_id, region=self.region(),
encrypted_summoner_id=obj.summoner_id)
await change("profile_icon_id", summoner["profileIconId"])
await change("summoner_name", summoner["name"])
@ -126,27 +122,19 @@ class LeagueoflegendsCommand(LinkerCommand):
await change("summoner_id", summoner["id"])
await change("account_id", summoner["accountId"])
log.debug(f"Getting leagues data: {obj}")
leagues = await ru.asyncify(self._riotwatcher.league.by_summoner, region=self.region(),
leagues = await ru.asyncify(self._lolwatcher.league.by_summoner, region=self.region(),
encrypted_summoner_id=obj.summoner_id)
soloq = LeagueLeague()
flexq = LeagueLeague()
twtrq = LeagueLeague()
tftq = LeagueLeague()
for league in leagues:
if league["queueType"] == "RANKED_SOLO_5x5":
soloq = LeagueLeague.from_dict(league)
if league["queueType"] == "RANKED_FLEX_SR":
flexq = LeagueLeague.from_dict(league)
if league["queueType"] == "RANKED_FLEX_TT":
twtrq = LeagueLeague.from_dict(league)
if league["queueType"] == "RANKED_TFT":
tftq = LeagueLeague.from_dict(league)
await change("rank_soloq", soloq)
await change("rank_flexq", flexq)
await change("rank_twtrq", twtrq)
await change("rank_tftq", tftq)
log.debug(f"Getting mastery data: {obj}")
mastery = await ru.asyncify(self._riotwatcher.champion_mastery.scores_by_summoner,
mastery = await ru.asyncify(self._lolwatcher.champion_mastery.scores_by_summoner,
region=self.region(),
encrypted_summoner_id=obj.summoner_id)
await change("mastery_score", mastery)

View file

@ -55,9 +55,7 @@ class SteammatchCommand(rc.Command):
def __init__(self, interface: rc.CommandInterface):
super().__init__(interface)
if "Steam" not in self.config or "web_api_key" not in self.config["Steam"]:
raise rc.ConfigurationError("[c]Steam.web_api_key[/c] config option is missing!")
self._api = steam.webapi.WebAPI(self.config["Steam"]["web_api_key"])
self._api = steam.webapi.WebAPI(self.config["steampowered"]["token"])
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
users = []

View file

@ -4,75 +4,38 @@ import steam.webapi
import datetime
import royalnet.commands as rc
import royalnet.utils as ru
import logging
from royalnet.backpack import tables as rbt
from .abstract.linker import LinkerCommand
from ..tables import Steam, FiorygiTransaction
from ..types import Updatable
log = logging.getLogger(__name__)
class SteampoweredCommand(rc.Command):
class SteampoweredCommand(LinkerCommand):
name: str = "steampowered"
description: str = "Connetti il tuo account di Steam!"
description: str = "Connetti e visualizza informazioni sul tuo account di Steam!"
syntax: str = "{profile_url}"
syntax: str = "{url_profilo}"
def __init__(self, interface: rc.CommandInterface):
super().__init__(interface)
if "Steam" not in self.config or "web_api_key" not in self.config["Steam"]:
raise rc.ConfigurationError("[c]Steam.web_api_key[/c] config option is missing!")
self._api = steam.webapi.WebAPI(self.config["Steam"]["web_api_key"])
self._api = steam.webapi.WebAPI(self.token())
@staticmethod
def _display(account: Steam):
string = f" [url={account.profile_url}]{account.persona_name}[/url]\n" \
f"[b]Level {account.account_level}[/b]\n" \
f"\n" \
f"Owned games: [b]{account.owned_games_count}[/b]\n" \
f"Most played 2 weeks: [url=https://store.steampowered.com/app/{account.most_played_game_2weeks}]{account.most_played_game_2weeks}[/url]\n" \
f"Most played forever: [url=https://store.steampowered.com/app/{account.most_played_game_forever}]{account.most_played_game_forever}[/url]\n" \
f"\n" \
f"SteamID: [c]{account.steamid.as_32}[/c]\n" \
f"SteamID2: [c]{account.steamid.as_steam2}[/c]\n" \
f"SteamID3: [c]{account.steamid.as_steam3}[/c]\n" \
f"SteamID64: [c]{account.steamid.as_64}[/c]\n" \
f"\n" \
f"Created on: [b]{account.account_creation_date}[/b]\n"
return string
def token(self):
return self.config["steampowered"]["token"]
async def _call(self, method, *args, **kwargs):
try:
return await ru.asyncify(method, *args, **kwargs)
except Exception as e:
raise rc.ExternalError("\n".join(e.args).replace(self.config["Steam"]["web_api_key"], "HIDDEN"))
async def get_updatables_of_user(self, session, user: rbt.User) -> List[Steam]:
return user.steam
async def _update(self, account: Steam):
# noinspection PyProtectedMember
response = await self._call(self._api.ISteamUser.GetPlayerSummaries_v2, steamids=account._steamid)
r = response["response"]["players"][0]
account.persona_name = r["personaname"]
account.profile_url = r["profileurl"]
account.avatar = r["avatar"]
account.primary_clan_id = r["primaryclanid"]
account.account_creation_date = datetime.datetime.fromtimestamp(r["timecreated"])
async def get_updatables(self, session) -> List[Steam]:
return await ru.asyncify(session.query(self.alchemy.get(Steam)).all)
# noinspection PyProtectedMember
response = await self._call(self._api.IPlayerService.GetSteamLevel_v1, steamid=account._steamid)
account.account_level = response["response"]["player_level"]
# noinspection PyProtectedMember
response = await self._call(self._api.IPlayerService.GetOwnedGames_v1,
steamid=account._steamid,
include_appinfo=False,
include_played_free_games=True,
include_free_sub=False,
appids_filter=None)
account.owned_games_count = response["response"]["game_count"]
if response["response"]["game_count"] >= 0:
account.most_played_game_2weeks = sorted(response["response"]["games"], key=lambda g: -g.get("playtime_2weeks", 0))[0]["appid"]
account.most_played_game_forever = sorted(response["response"]["games"], key=lambda g: -g.get("playtime_forever", 0))[0]["appid"]
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
author = await data.get_author()
if len(args) > 0:
async def create(self, session, user: rbt.User, args) -> Steam:
url = args.joined()
steamid64 = await self._call(steam.steamid.steam64_from_url, url)
if steamid64 is None:
@ -80,7 +43,7 @@ class SteampoweredCommand(rc.Command):
response = await self._call(self._api.ISteamUser.GetPlayerSummaries_v2, steamids=steamid64)
r = response["response"]["players"][0]
steam_account = self.alchemy.get(Steam)(
user=author,
user=user,
_steamid=int(steamid64),
persona_name=r["personaname"],
profile_url=r["profileurl"],
@ -88,19 +51,64 @@ class SteampoweredCommand(rc.Command):
primary_clan_id=r["primaryclanid"],
account_creation_date=datetime.datetime.fromtimestamp(r["timecreated"])
)
data.session.add(steam_account)
await data.session_commit()
await data.reply(f"↔️ Account {steam_account} connesso a {author}!")
await FiorygiTransaction.spawn_fiorygi(data, author, 1,
"aver connesso il proprio account di Steam a Royalnet")
else:
# Update and display the Steam info for the current account
if len(author.steam) == 0:
raise rc.UserError("Nessun account di Steam trovato.")
message = ""
for account in author.steam:
await self._update(account)
message += self._display(account)
message += "\n"
await data.session_commit()
await data.reply(message)
session.add(steam_account)
await ru.asyncify(session.commit)
return steam_account
async def update(self, session, obj: Steam, change: Callable[[str, Any], Awaitable[None]]):
response = await self._call(self._api.ISteamUser.GetPlayerSummaries_v2, steamids=obj.steamid.as_64)
r = response["response"]["players"][0]
obj.persona_name = r["personaname"]
obj.profile_url = r["profileurl"]
obj.avatar = r["avatar"]
obj.primary_clan_id = r["primaryclanid"]
obj.account_creation_date = datetime.datetime.fromtimestamp(r["timecreated"])
response = await self._call(self._api.IPlayerService.GetSteamLevel_v1, steamid=obj.steamid.as_64)
obj.account_level = response["response"]["player_level"]
response = await self._call(self._api.IPlayerService.GetOwnedGames_v1,
steamid=obj.steamid.as_64,
include_appinfo=False,
include_played_free_games=True,
include_free_sub=False,
appids_filter=None)
obj.owned_games_count = response["response"]["game_count"]
if response["response"]["game_count"] >= 0:
obj.most_played_game_2weeks = sorted(response["response"]["games"], key=lambda g: -g.get("playtime_2weeks", 0))[0]["appid"]
obj.most_played_game_forever = sorted(response["response"]["games"], key=lambda g: -g.get("playtime_forever", 0))[0]["appid"]
async def on_increase(self, session, obj: Updatable, attribute: str, old: Any, new: Any) -> None:
pass
async def on_unchanged(self, session, obj: Updatable, attribute: str, old: Any, new: Any) -> None:
pass
async def on_decrease(self, session, obj: Updatable, attribute: str, old: Any, new: Any) -> None:
pass
async def on_first(self, session, obj: Updatable, attribute: str, old: None, new: Any) -> None:
pass
async def on_reset(self, session, obj: Updatable, attribute: str, old: Any, new: None) -> None:
pass
def describe(self, obj: Steam):
return f" [url={obj.profile_url}]{obj.persona_name}[/url]\n" \
f"[b]Level {obj.account_level}[/b]\n" \
f"\n" \
f"Owned games: [b]{obj.owned_games_count}[/b]\n" \
f"Most played 2 weeks: [url=https://store.steampowered.com/app/{obj.most_played_game_2weeks}]{obj.most_played_game_2weeks}[/url]\n" \
f"Most played forever: [url=https://store.steampowered.com/app/{obj.most_played_game_forever}]{obj.most_played_game_forever}[/url]\n" \
f"\n" \
f"SteamID32: [c]{obj.steamid.as_32}[/c]\n" \
f"SteamID64: [c]{obj.steamid.as_64}[/c]\n" \
f"SteamID2: [c]{obj.steamid.as_steam2}[/c]\n" \
f"SteamID3: [c]{obj.steamid.as_steam3}[/c]\n" \
f"\n" \
f"Created on: [b]{obj.account_creation_date}[/b]\n"
async def _call(self, method, *args, **kwargs):
log.debug(f"Calling {method}")
try:
return await ru.asyncify(method, *args, **kwargs)
except Exception as e:
raise rc.ExternalError("\n".join(e.args).replace(self.token(), "HIDDEN"))

View file

@ -147,104 +147,6 @@ class LeagueOfLegends(Updatable):
self.rank_flexq_fresh_blood,
self.rank_flexq_veteran)
@declared_attr
def rank_twtrq_tier(self):
return Column(Enum(LeagueTier))
@declared_attr
def rank_twtrq_rank(self):
return Column(Enum(LeagueRank))
@declared_attr
def rank_twtrq_points(self):
return Column(Integer)
@declared_attr
def rank_twtrq_wins(self):
return Column(Integer)
@declared_attr
def rank_twtrq_losses(self):
return Column(Integer)
@declared_attr
def rank_twtrq_inactive(self):
return Column(Boolean)
@declared_attr
def rank_twtrq_hot_streak(self):
return Column(Boolean)
@declared_attr
def rank_twtrq_fresh_blood(self):
return Column(Boolean)
@declared_attr
def rank_twtrq_veteran(self):
return Column(Boolean)
@declared_attr
def rank_twtrq(self):
return composite(LeagueLeague,
self.rank_twtrq_tier,
self.rank_twtrq_rank,
self.rank_twtrq_points,
self.rank_twtrq_wins,
self.rank_twtrq_losses,
self.rank_twtrq_inactive,
self.rank_twtrq_hot_streak,
self.rank_twtrq_fresh_blood,
self.rank_twtrq_veteran)
@declared_attr
def rank_tftq_tier(self):
return Column(Enum(LeagueTier))
@declared_attr
def rank_tftq_rank(self):
return Column(Enum(LeagueRank))
@declared_attr
def rank_tftq_points(self):
return Column(Integer)
@declared_attr
def rank_tftq_wins(self):
return Column(Integer)
@declared_attr
def rank_tftq_losses(self):
return Column(Integer)
@declared_attr
def rank_tftq_inactive(self):
return Column(Boolean)
@declared_attr
def rank_tftq_hot_streak(self):
return Column(Boolean)
@declared_attr
def rank_tftq_fresh_blood(self):
return Column(Boolean)
@declared_attr
def rank_tftq_veteran(self):
return Column(Boolean)
@declared_attr
def rank_tftq(self):
return composite(LeagueLeague,
self.rank_tftq_tier,
self.rank_tftq_rank,
self.rank_tftq_points,
self.rank_tftq_wins,
self.rank_tftq_losses,
self.rank_tftq_inactive,
self.rank_tftq_hot_streak,
self.rank_tftq_fresh_blood,
self.rank_tftq_veteran)
@declared_attr
def mastery_score(self):
return Column(Integer, nullable=False, default=0)
@ -259,9 +161,8 @@ class LeagueOfLegends(Updatable):
"summoner_id": self.summoner_id,
"account_id": self.account_id,
"soloq": self.rank_soloq.json() if self.rank_soloq is not None else None,
"twtrq": self.rank_twtrq.json() if self.rank_twtrq is not None else None,
"flexq": self.rank_flexq.json() if self.rank_flexq is not None else None,
"tftq": self.rank_tftq.json() if self.rank_tftq is not None else None,
"mastery_score": self.mastery_score,
}
def __repr__(self):

View file

@ -1 +1 @@
semantic = "5.12.1"
semantic = "5.12.2"