mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Cambia la signature di linker.create
This commit is contained in:
parent
b7f099d499
commit
f777f008c5
5 changed files with 46 additions and 17 deletions
|
@ -41,7 +41,7 @@ class LinkerCommand(rc.Command, metaclass=abc.ABCMeta):
|
||||||
await data.reply("\n".join(message))
|
await data.reply("\n".join(message))
|
||||||
else:
|
else:
|
||||||
message = ["🔗 Account collegato!\n"]
|
message = ["🔗 Account collegato!\n"]
|
||||||
created = await self.create(session=data.session, user=author, args=args)
|
created = await self.create(session=data.session, user=author, args=args, data=data)
|
||||||
message.append(self.describe(created))
|
message.append(self.describe(created))
|
||||||
await data.session_commit()
|
await data.session_commit()
|
||||||
await data.reply("\n".join(message))
|
await data.reply("\n".join(message))
|
||||||
|
@ -61,8 +61,14 @@ class LinkerCommand(rc.Command, metaclass=abc.ABCMeta):
|
||||||
...
|
...
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
async def create(self, session, user: rbt.User, args) -> Updatable:
|
async def create(self,
|
||||||
"""Create a new updatable object for a user."""
|
session,
|
||||||
|
user: rbt.User,
|
||||||
|
args: rc.CommandArgs,
|
||||||
|
data: Optional[rc.CommandData] = None) -> Updatable:
|
||||||
|
"""Create a new updatable object for a user.
|
||||||
|
|
||||||
|
This function is responsible for adding the object to the session."""
|
||||||
...
|
...
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
|
|
|
@ -5,8 +5,8 @@ import logging
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from royalnet.backpack import tables as rbt
|
from royalnet.backpack import tables as rbt
|
||||||
from royalnet.commands import *
|
import royalnet.commands as rc
|
||||||
from royalnet.utils import *
|
import royalnet.utils as ru
|
||||||
from sqlalchemy import or_, and_
|
from sqlalchemy import or_, and_
|
||||||
|
|
||||||
from .abstract.linker import LinkerCommand
|
from .abstract.linker import LinkerCommand
|
||||||
|
@ -32,10 +32,14 @@ class BrawlhallaCommand(LinkerCommand):
|
||||||
return user.steam
|
return user.steam
|
||||||
|
|
||||||
async def get_updatables(self, session) -> List[Brawlhalla]:
|
async def get_updatables(self, session) -> List[Brawlhalla]:
|
||||||
return await asyncify(session.query(self.alchemy.get(Steam)).all)
|
return await ru.asyncify(session.query(self.alchemy.get(Steam)).all)
|
||||||
|
|
||||||
async def create(self, session, user: rbt.User, args) -> Updatable:
|
async def create(self,
|
||||||
raise InvalidInputError("Brawlhalla accounts are automatically linked from Steam.")
|
session,
|
||||||
|
user: rbt.User,
|
||||||
|
args: rc.CommandArgs,
|
||||||
|
data: Optional[rc.CommandData] = None) -> Brawlhalla:
|
||||||
|
raise rc.InvalidInputError("Brawlhalla accounts are automatically linked from Steam.")
|
||||||
|
|
||||||
async def update(self, session, obj, change: Callable[[str, Any], Awaitable[None]]):
|
async def update(self, session, obj, change: Callable[[str, Any], Awaitable[None]]):
|
||||||
BrawlhallaT = self.alchemy.get(Brawlhalla)
|
BrawlhallaT = self.alchemy.get(Brawlhalla)
|
||||||
|
@ -47,7 +51,7 @@ class BrawlhallaCommand(LinkerCommand):
|
||||||
log.debug(f"Checking if player has an account...")
|
log.debug(f"Checking if player has an account...")
|
||||||
async with hcs.get(f"https://api.brawlhalla.com/search?steamid={obj.steamid.as_64}&api_key={self.token()}") as response:
|
async with hcs.get(f"https://api.brawlhalla.com/search?steamid={obj.steamid.as_64}&api_key={self.token()}") as response:
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
raise ExternalError(f"Brawlhalla API /search returned {response.status}!")
|
raise rc.ExternalError(f"Brawlhalla API /search returned {response.status}!")
|
||||||
j = await response.json()
|
j = await response.json()
|
||||||
if j == {} or j == []:
|
if j == {} or j == []:
|
||||||
log.debug("No account found.")
|
log.debug("No account found.")
|
||||||
|
@ -62,7 +66,7 @@ class BrawlhallaCommand(LinkerCommand):
|
||||||
|
|
||||||
async with hcs.get(f"https://api.brawlhalla.com/player/{bh.brawlhalla_id}/ranked?api_key={self.token()}") as response:
|
async with hcs.get(f"https://api.brawlhalla.com/player/{bh.brawlhalla_id}/ranked?api_key={self.token()}") as response:
|
||||||
if response.status != 200:
|
if response.status != 200:
|
||||||
raise ExternalError(f"Brawlhalla API /ranked returned {response.status}!")
|
raise rc.ExternalError(f"Brawlhalla API /ranked returned {response.status}!")
|
||||||
j = await response.json()
|
j = await response.json()
|
||||||
if j == {} or j == []:
|
if j == {} or j == []:
|
||||||
log.debug("No ranked info found.")
|
log.debug("No ranked info found.")
|
||||||
|
@ -75,7 +79,7 @@ class BrawlhallaCommand(LinkerCommand):
|
||||||
await self._change(session=session, obj=bh, attribute="rank_1v1", new=rank)
|
await self._change(session=session, obj=bh, attribute="rank_1v1", new=rank)
|
||||||
|
|
||||||
for jduo in j.get("2v2", []):
|
for jduo in j.get("2v2", []):
|
||||||
bhduo: Optional[BrawlhallaDuo] = await asyncify(
|
bhduo: Optional[BrawlhallaDuo] = await ru.asyncify(
|
||||||
session.query(DuoT)
|
session.query(DuoT)
|
||||||
.filter(
|
.filter(
|
||||||
or_(
|
or_(
|
||||||
|
@ -93,11 +97,11 @@ class BrawlhallaCommand(LinkerCommand):
|
||||||
)
|
)
|
||||||
if bhduo is None:
|
if bhduo is None:
|
||||||
if bh.brawlhalla_id == jduo["brawlhalla_id_one"]:
|
if bh.brawlhalla_id == jduo["brawlhalla_id_one"]:
|
||||||
otherbh: Optional[Brawlhalla] = await asyncify(
|
otherbh: Optional[Brawlhalla] = await ru.asyncify(
|
||||||
session.query(BrawlhallaT).get, jduo["brawlhalla_id_two"]
|
session.query(BrawlhallaT).get, jduo["brawlhalla_id_two"]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
otherbh: Optional[Brawlhalla] = await asyncify(
|
otherbh: Optional[Brawlhalla] = await ru.asyncify(
|
||||||
session.query(BrawlhallaT).get, jduo["brawlhalla_id_one"]
|
session.query(BrawlhallaT).get, jduo["brawlhalla_id_one"]
|
||||||
)
|
)
|
||||||
if otherbh is None:
|
if otherbh is None:
|
||||||
|
|
|
@ -37,7 +37,7 @@ class DotaCommand(LinkerCommand):
|
||||||
async def get_updatables(self, session) -> List[Dota]:
|
async def get_updatables(self, session) -> List[Dota]:
|
||||||
return await ru.asyncify(session.query(self.alchemy.get(Steam)).all)
|
return await ru.asyncify(session.query(self.alchemy.get(Steam)).all)
|
||||||
|
|
||||||
async def create(self, session, user: rbt.User, args):
|
async def create(self, session, user: rbt.User, args: rc.CommandArgs, data: Optional[rc.CommandData] = None):
|
||||||
raise rc.InvalidInputError("Dota accounts are automatically linked from Steam.")
|
raise rc.InvalidInputError("Dota accounts are automatically linked from Steam.")
|
||||||
|
|
||||||
async def update(self, session, obj: Steam, change: Callable[[str, Any], Awaitable[None]]):
|
async def update(self, session, obj: Steam, change: Callable[[str, Any], Awaitable[None]]):
|
||||||
|
|
|
@ -60,7 +60,7 @@ class LeagueoflegendsCommand(LinkerCommand):
|
||||||
async def get_updatables(self, session) -> List[LeagueOfLegends]:
|
async def get_updatables(self, session) -> List[LeagueOfLegends]:
|
||||||
return await ru.asyncify(session.query(self.alchemy.get(LeagueOfLegends)).all)
|
return await ru.asyncify(session.query(self.alchemy.get(LeagueOfLegends)).all)
|
||||||
|
|
||||||
async def create(self, session, user: rbt.User, args) -> LeagueOfLegends:
|
async def create(self, session, user: rbt.User, args: rc.CommandArgs, data: Optional[rc.CommandData] = None) -> LeagueOfLegends:
|
||||||
name = args.joined()
|
name = args.joined()
|
||||||
|
|
||||||
# Connect a new League of Legends account to Royalnet
|
# Connect a new League of Legends account to Royalnet
|
||||||
|
@ -108,6 +108,14 @@ class LeagueoflegendsCommand(LinkerCommand):
|
||||||
rank_tftq=tftq,
|
rank_tftq=tftq,
|
||||||
mastery_score=mastery
|
mastery_score=mastery
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await FiorygiTransaction.spawn_fiorygi(
|
||||||
|
data=data,
|
||||||
|
user=user,
|
||||||
|
qty=1,
|
||||||
|
reason="aver collegato a Royalnet il proprio account di League of Legends"
|
||||||
|
)
|
||||||
|
|
||||||
session.add(leagueoflegends)
|
session.add(leagueoflegends)
|
||||||
return leagueoflegends
|
return leagueoflegends
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,11 @@ class SteampoweredCommand(LinkerCommand):
|
||||||
async def get_updatables(self, session) -> List[Steam]:
|
async def get_updatables(self, session) -> List[Steam]:
|
||||||
return await ru.asyncify(session.query(self.alchemy.get(Steam)).all)
|
return await ru.asyncify(session.query(self.alchemy.get(Steam)).all)
|
||||||
|
|
||||||
async def create(self, session, user: rbt.User, args) -> Steam:
|
async def create(self,
|
||||||
|
session,
|
||||||
|
user: rbt.User,
|
||||||
|
args: rc.CommandArgs,
|
||||||
|
data: Optional[rc.CommandData] = None) -> Steam:
|
||||||
url = args.joined()
|
url = args.joined()
|
||||||
steamid64 = await self._call(steam.steamid.steam64_from_url, url)
|
steamid64 = await self._call(steam.steamid.steam64_from_url, url)
|
||||||
if steamid64 is None:
|
if steamid64 is None:
|
||||||
|
@ -51,8 +55,15 @@ class SteampoweredCommand(LinkerCommand):
|
||||||
primary_clan_id=r["primaryclanid"],
|
primary_clan_id=r["primaryclanid"],
|
||||||
account_creation_date=datetime.datetime.fromtimestamp(r["timecreated"])
|
account_creation_date=datetime.datetime.fromtimestamp(r["timecreated"])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await FiorygiTransaction.spawn_fiorygi(
|
||||||
|
data=data,
|
||||||
|
user=user,
|
||||||
|
qty=1,
|
||||||
|
reason="aver collegato a Royalnet il proprio account di League of Legends"
|
||||||
|
)
|
||||||
|
|
||||||
session.add(steam_account)
|
session.add(steam_account)
|
||||||
await ru.asyncify(session.commit)
|
|
||||||
return steam_account
|
return steam_account
|
||||||
|
|
||||||
async def update(self, session, obj: Steam, change: Callable[[str, Any], Awaitable[None]]):
|
async def update(self, session, obj: Steam, change: Callable[[str, Any], Awaitable[None]]):
|
||||||
|
|
Loading…
Reference in a new issue