mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Fix misc bugs
This commit is contained in:
parent
421ad2daad
commit
61fd3f4c25
20 changed files with 144 additions and 174 deletions
|
@ -13,15 +13,15 @@ class GivefiorygiCommand(rc.Command):
|
||||||
syntax: str = "{destinatario} {quantità} {motivo}"
|
syntax: str = "{destinatario} {quantità} {motivo}"
|
||||||
|
|
||||||
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
||||||
author = await data.get_author(error_if_none=True)
|
async with data.session_acm() as session:
|
||||||
|
author = await data.find_author(session=session, required=True)
|
||||||
|
|
||||||
user_arg = args[0]
|
user_arg = args[0]
|
||||||
qty_arg = args[1]
|
qty_arg = args[1]
|
||||||
|
|
||||||
if user_arg is None:
|
if user_arg is None:
|
||||||
raise rc.InvalidInputError("Non hai specificato un destinatario!")
|
raise rc.InvalidInputError("Non hai specificato un destinatario!")
|
||||||
async with data.session_acm() as session:
|
user = await rbt.User.find(alchemy=self.alchemy, session=session, identifier=user_arg)
|
||||||
user = await rbt.User.find(self.alchemy, session, user_arg)
|
|
||||||
if user is None:
|
if user is None:
|
||||||
raise rc.InvalidInputError("L'utente specificato non esiste!")
|
raise rc.InvalidInputError("L'utente specificato non esiste!")
|
||||||
if user.uid == author.uid:
|
if user.uid == author.uid:
|
||||||
|
@ -39,5 +39,9 @@ class GivefiorygiCommand(rc.Command):
|
||||||
if author.fiorygi.fiorygi < qty:
|
if author.fiorygi.fiorygi < qty:
|
||||||
raise rc.InvalidInputError("Non hai abbastanza fiorygi per effettuare la transazione!")
|
raise rc.InvalidInputError("Non hai abbastanza fiorygi per effettuare la transazione!")
|
||||||
|
|
||||||
await FiorygiTransaction.spawn_fiorygi(data, author, -qty, f"aver ceduto fiorygi a {user}")
|
await FiorygiTransaction.spawn_fiorygi(author, -qty, f"aver ceduto fiorygi a {user}",
|
||||||
await FiorygiTransaction.spawn_fiorygi(data, user, qty, f"aver ricevuto fiorygi da {author}")
|
data=data,
|
||||||
|
session=session)
|
||||||
|
await FiorygiTransaction.spawn_fiorygi(user, qty, f"aver ricevuto fiorygi da {author}",
|
||||||
|
data=data,
|
||||||
|
session=session)
|
||||||
|
|
|
@ -30,6 +30,6 @@ class GivetreasureCommand(MagicktreasureCommand):
|
||||||
redeemed_by=None
|
redeemed_by=None
|
||||||
)
|
)
|
||||||
|
|
||||||
await FiorygiTransaction.spawn_fiorygi(data, author, -value, "aver creato un tesoro")
|
await FiorygiTransaction.spawn_fiorygi(author, -value, "aver creato un tesoro", data=data, session=session)
|
||||||
|
|
||||||
return treasure
|
return treasure
|
||||||
|
|
|
@ -115,6 +115,7 @@ class LeagueoflegendsCommand(LinkerCommand):
|
||||||
|
|
||||||
await FiorygiTransaction.spawn_fiorygi(
|
await FiorygiTransaction.spawn_fiorygi(
|
||||||
data=data,
|
data=data,
|
||||||
|
session=session,
|
||||||
user=user,
|
user=user,
|
||||||
qty=1,
|
qty=1,
|
||||||
reason="aver collegato a Royalnet il proprio account di League of Legends"
|
reason="aver collegato a Royalnet il proprio account di League of Legends"
|
||||||
|
|
|
@ -13,7 +13,8 @@ class MagickfiorygiCommand(rc.Command):
|
||||||
syntax: str = "{destinatario} {quantità} {motivo}"
|
syntax: str = "{destinatario} {quantità} {motivo}"
|
||||||
|
|
||||||
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
||||||
author = await data.get_author(error_if_none=True)
|
async with data.session_acm() as session:
|
||||||
|
author = await data.find_author(session=session, required=True)
|
||||||
if "banker" not in author.roles:
|
if "banker" not in author.roles:
|
||||||
raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.")
|
raise rc.UserError("Non hai permessi sufficienti per eseguire questo comando.")
|
||||||
|
|
||||||
|
@ -23,7 +24,6 @@ class MagickfiorygiCommand(rc.Command):
|
||||||
|
|
||||||
if user_arg is None:
|
if user_arg is None:
|
||||||
raise rc.InvalidInputError("Non hai specificato un destinatario!")
|
raise rc.InvalidInputError("Non hai specificato un destinatario!")
|
||||||
async with data.session_acm() as session:
|
|
||||||
user = await rbt.User.find(self.alchemy, session, user_arg)
|
user = await rbt.User.find(self.alchemy, session, user_arg)
|
||||||
if user is None:
|
if user is None:
|
||||||
raise rc.InvalidInputError("L'utente specificato non esiste!")
|
raise rc.InvalidInputError("L'utente specificato non esiste!")
|
||||||
|
@ -38,4 +38,4 @@ class MagickfiorygiCommand(rc.Command):
|
||||||
if reason_arg == "":
|
if reason_arg == "":
|
||||||
raise rc.InvalidInputError("Non hai specificato un motivo!")
|
raise rc.InvalidInputError("Non hai specificato un motivo!")
|
||||||
|
|
||||||
await FiorygiTransaction.spawn_fiorygi(data, user, qty, reason_arg)
|
await FiorygiTransaction.spawn_fiorygi(user, qty, reason_arg, data=data, session=session)
|
||||||
|
|
|
@ -34,7 +34,9 @@ class MagicktreasureCommand(rc.Command):
|
||||||
|
|
||||||
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
||||||
await data.delete_invoking()
|
await data.delete_invoking()
|
||||||
author = await data.get_author(error_if_none=True)
|
|
||||||
|
async with data.session_acm() as session:
|
||||||
|
author = await data.find_author(session=session, required=True)
|
||||||
|
|
||||||
code = args[0].lower()
|
code = args[0].lower()
|
||||||
try:
|
try:
|
||||||
|
@ -44,7 +46,6 @@ class MagicktreasureCommand(rc.Command):
|
||||||
if value < 0:
|
if value < 0:
|
||||||
raise rc.InvalidInputError("Il valore deve essere maggiore o uguale a 0.")
|
raise rc.InvalidInputError("Il valore deve essere maggiore o uguale a 0.")
|
||||||
|
|
||||||
async with data.session_acm() as session:
|
|
||||||
await self._permission_check(author, code, value, data, session)
|
await self._permission_check(author, code, value, data, session)
|
||||||
treasure = await self._create_treasure(author, code, value, data, session)
|
treasure = await self._create_treasure(author, code, value, data, session)
|
||||||
session.add(treasure)
|
session.add(treasure)
|
||||||
|
|
|
@ -117,7 +117,7 @@ class OsuCommand(LinkerCommand):
|
||||||
if attribute == "standard_pp":
|
if attribute == "standard_pp":
|
||||||
await self.notify(f"⬜️ [b]{obj.user}[/b] non è più classificato su [i]osu![/i].")
|
await self.notify(f"⬜️ [b]{obj.user}[/b] non è più classificato su [i]osu![/i].")
|
||||||
elif attribute == "taiko_pp":
|
elif attribute == "taiko_pp":
|
||||||
await self.notify(f" ⬜️[b]{obj.user}[/b] non è più classificato su [i]osu!taiko[/i].")
|
await self.notify(f"⬜️ [b]{obj.user}[/b] non è più classificato su [i]osu!taiko[/i].")
|
||||||
elif attribute == "catch_pp":
|
elif attribute == "catch_pp":
|
||||||
await self.notify(f"⬜️ [b]{obj.user}[/b] non è più classificato su [i]osu!catch[/i].")
|
await self.notify(f"⬜️ [b]{obj.user}[/b] non è più classificato su [i]osu!catch[/i].")
|
||||||
elif attribute == "mania_pp":
|
elif attribute == "mania_pp":
|
||||||
|
|
|
@ -23,7 +23,7 @@ class PingCommand(rc.Command):
|
||||||
for target in self._targets:
|
for target in self._targets:
|
||||||
tasks[target] = self.loop.create_task(self.serf.call_herald_event(target, "pong"))
|
tasks[target] = self.loop.create_task(self.serf.call_herald_event(target, "pong"))
|
||||||
|
|
||||||
await asyncio.sleep(10)
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
lines = ["📶 [b]Pong![/b]", ""]
|
lines = ["📶 [b]Pong![/b]", ""]
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class ReminderCommand(rc.Command):
|
||||||
.all()
|
.all()
|
||||||
)
|
)
|
||||||
for reminder in reminders:
|
for reminder in reminders:
|
||||||
self.loop.create_task(self._remind(reminder))
|
self.serf.tasks.add(self._remind(reminder))
|
||||||
|
|
||||||
async def _remind(self, reminder):
|
async def _remind(self, reminder):
|
||||||
await ru.sleep_until(reminder.datetime)
|
await ru.sleep_until(reminder.datetime)
|
||||||
|
@ -77,13 +77,13 @@ class ReminderCommand(rc.Command):
|
||||||
interface_data = pickle.dumps(data.message.channel.id)
|
interface_data = pickle.dumps(data.message.channel.id)
|
||||||
else:
|
else:
|
||||||
raise rc.UnsupportedError("This command does not support the current interface.")
|
raise rc.UnsupportedError("This command does not support the current interface.")
|
||||||
creator = await data.get_author()
|
|
||||||
async with data.session_acm() as session:
|
async with data.session_acm() as session:
|
||||||
|
creator = await data.find_author(session=session)
|
||||||
reminder = self.alchemy.get(Reminder)(creator=creator,
|
reminder = self.alchemy.get(Reminder)(creator=creator,
|
||||||
interface_name=self.serf.interface_name,
|
interface_name=self.serf.interface_name,
|
||||||
interface_data=interface_data,
|
interface_data=interface_data,
|
||||||
datetime=date,
|
datetime=date,
|
||||||
message=reminder_text)
|
message=reminder_text)
|
||||||
self.loop.create_task(self._remind(reminder))
|
self.serf.tasks.add(self._remind(reminder))
|
||||||
session.add(reminder)
|
session.add(reminder)
|
||||||
await ru.asyncify(session.commit)
|
await ru.asyncify(session.commit)
|
||||||
|
|
|
@ -60,11 +60,11 @@ class SteammatchCommand(rc.Command):
|
||||||
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
||||||
users = []
|
users = []
|
||||||
|
|
||||||
author = await data.get_author(error_if_none=True)
|
async with data.session_acm() as session:
|
||||||
|
author = await data.find_author(session=session, required=True)
|
||||||
users.append(author)
|
users.append(author)
|
||||||
|
|
||||||
for arg in args:
|
for arg in args:
|
||||||
async with data.session_acm() as session:
|
|
||||||
user = await rbt.User.find(self.alchemy, session, arg)
|
user = await rbt.User.find(self.alchemy, session, arg)
|
||||||
users.append(user)
|
users.append(user)
|
||||||
|
|
||||||
|
|
|
@ -57,10 +57,12 @@ class SteampoweredCommand(LinkerCommand):
|
||||||
)
|
)
|
||||||
|
|
||||||
await FiorygiTransaction.spawn_fiorygi(
|
await FiorygiTransaction.spawn_fiorygi(
|
||||||
data=data,
|
|
||||||
user=user,
|
user=user,
|
||||||
qty=1,
|
qty=1,
|
||||||
reason="aver collegato a Royalnet il proprio account di League of Legends"
|
reason="aver collegato a Royalnet il proprio account di Steam",
|
||||||
|
|
||||||
|
data=data,
|
||||||
|
session=session,
|
||||||
)
|
)
|
||||||
|
|
||||||
session.add(steam_account)
|
session.add(steam_account)
|
||||||
|
|
|
@ -13,11 +13,11 @@ class TreasureCommand(rc.Command):
|
||||||
syntax: str = "{code}"
|
syntax: str = "{code}"
|
||||||
|
|
||||||
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
async def run(self, args: rc.CommandArgs, data: rc.CommandData) -> None:
|
||||||
author = await data.get_author(error_if_none=True)
|
TreasureT = self.alchemy.get(Treasure)
|
||||||
code = args[0].lower()
|
|
||||||
|
|
||||||
async with data.session_acm() as session:
|
async with data.session_acm() as session:
|
||||||
TreasureT = self.alchemy.get(Treasure)
|
author = await data.find_author(session=session, required=True)
|
||||||
|
code = args[0].lower()
|
||||||
|
|
||||||
treasure = await ru.asyncify(session.query(TreasureT).get, code)
|
treasure = await ru.asyncify(session.query(TreasureT).get, code)
|
||||||
if treasure is None:
|
if treasure is None:
|
||||||
|
|
|
@ -94,7 +94,7 @@ class TriviaCommand(rc.Command):
|
||||||
|
|
||||||
# Create the correct and wrong functions
|
# Create the correct and wrong functions
|
||||||
async def correct(data: rc.CommandData):
|
async def correct(data: rc.CommandData):
|
||||||
answerer_ = await data.get_author(error_if_none=True)
|
answerer_ = await data.find_author(session=session, required=True)
|
||||||
try:
|
try:
|
||||||
self._answerers[question_id][answerer_.uid] = True
|
self._answerers[question_id][answerer_.uid] = True
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -102,7 +102,7 @@ class TriviaCommand(rc.Command):
|
||||||
await data.reply("🆗 Hai risposto alla domanda. Ora aspetta un attimo per i risultati!")
|
await data.reply("🆗 Hai risposto alla domanda. Ora aspetta un attimo per i risultati!")
|
||||||
|
|
||||||
async def wrong(data: rc.CommandData):
|
async def wrong(data: rc.CommandData):
|
||||||
answerer_ = await data.get_author(error_if_none=True)
|
answerer_ = await data.find_author(session=session, required=True)
|
||||||
try:
|
try:
|
||||||
self._answerers[question_id][answerer_.uid] = False
|
self._answerers[question_id][answerer_.uid] = False
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
|
|
@ -88,5 +88,6 @@ class DiscordCvEvent(rc.HeraldEvent):
|
||||||
"id": guild.id,
|
"id": guild.id,
|
||||||
"name": guild.name,
|
"name": guild.name,
|
||||||
"members": results,
|
"members": results,
|
||||||
|
"channels": channels,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ from .api_bio import ApiBioSetStar
|
||||||
from .api_diario import ApiDiarioGetStar
|
from .api_diario import ApiDiarioGetStar
|
||||||
from .api_diario_list import ApiDiarioPagesStar
|
from .api_diario_list import ApiDiarioPagesStar
|
||||||
from .api_discord_cv import ApiDiscordCvStar
|
from .api_discord_cv import ApiDiscordCvStar
|
||||||
from .api_discord_play import ApiDiscordPlayStar
|
|
||||||
from .api_fiorygi import ApiFiorygiStar
|
from .api_fiorygi import ApiFiorygiStar
|
||||||
from .api_diario_random import ApiDiarioRandomStar
|
from .api_diario_random import ApiDiarioRandomStar
|
||||||
from .api_poll import ApiPollStar
|
from .api_poll import ApiPollStar
|
||||||
|
@ -21,7 +20,6 @@ available_page_stars = [
|
||||||
ApiDiarioGetStar,
|
ApiDiarioGetStar,
|
||||||
ApiDiarioPagesStar,
|
ApiDiarioPagesStar,
|
||||||
ApiDiscordCvStar,
|
ApiDiscordCvStar,
|
||||||
ApiDiscordPlayStar,
|
|
||||||
ApiFiorygiStar,
|
ApiFiorygiStar,
|
||||||
ApiDiarioRandomStar,
|
ApiDiarioRandomStar,
|
||||||
ApiPollStar,
|
ApiPollStar,
|
||||||
|
|
|
@ -7,7 +7,7 @@ import aiohttp
|
||||||
import aiohttp.client_exceptions
|
import aiohttp.client_exceptions
|
||||||
import datetime
|
import datetime
|
||||||
from ..types import oauth_refresh
|
from ..types import oauth_refresh
|
||||||
from ..tables import Osu, FiorygiTransaction
|
from ..tables import Osu
|
||||||
|
|
||||||
|
|
||||||
class ApiAuthLoginOsuStar(rca.ApiStar):
|
class ApiAuthLoginOsuStar(rca.ApiStar):
|
||||||
|
|
|
@ -12,5 +12,5 @@ class ApiDiscordCvStar(rca.ApiStar):
|
||||||
"""Get the members status of a single Discord guild.
|
"""Get the members status of a single Discord guild.
|
||||||
|
|
||||||
Equivalent to calling /cv in a chat."""
|
Equivalent to calling /cv in a chat."""
|
||||||
response = await self.interface.call_herald_event("discord", "discord_cv")
|
response = await self.constellation.call_herald_event("discord", "discord_cv")
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
from typing import *
|
|
||||||
import royalnet.constellation.api as rca
|
|
||||||
import logging
|
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class ApiDiscordPlayStar(rca.ApiStar):
|
|
||||||
path = "/api/discord/play/v2"
|
|
||||||
|
|
||||||
parameters = {
|
|
||||||
"post": {
|
|
||||||
"url": "The url of the audio file to add.",
|
|
||||||
"user": "The name to display in the File Added message.",
|
|
||||||
"guild_id": "The id of the guild owning the RoyalQueue to add the audio file to.",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tags = ["discord"]
|
|
||||||
|
|
||||||
@rca.magic
|
|
||||||
async def post(self, data: rca.ApiData) -> dict:
|
|
||||||
"""Add a audio file to the RoyalQueue of a Discord Guild."""
|
|
||||||
url = data["url"]
|
|
||||||
user = data.get("user")
|
|
||||||
guild_id_str = data.get("guild_id")
|
|
||||||
if guild_id_str:
|
|
||||||
try:
|
|
||||||
guild_id: Optional[int] = int(guild_id_str)
|
|
||||||
except (ValueError, TypeError):
|
|
||||||
raise rca.InvalidParameterError("'guild_id' is not a valid int.")
|
|
||||||
else:
|
|
||||||
guild_id = None
|
|
||||||
log.info(f"Received request to play {url} on guild_id {guild_id} via web")
|
|
||||||
response = await self.interface.call_herald_event("discord", "discord_play",
|
|
||||||
urls=[url],
|
|
||||||
guild_id=guild_id,
|
|
||||||
user=user)
|
|
||||||
return response
|
|
|
@ -3,7 +3,7 @@ import royalnet.utils as ru
|
||||||
import royalnet.constellation.api as rca
|
import royalnet.constellation.api as rca
|
||||||
|
|
||||||
|
|
||||||
url_validation = re.compile(r'^(?:http|ftp)s?://'
|
url_validation = re.compile(r'^(?:http|ftp)s://'
|
||||||
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
|
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
|
||||||
r'localhost|'
|
r'localhost|'
|
||||||
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
|
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
|
||||||
|
@ -16,7 +16,7 @@ class ApiUserAvatarStar(rca.ApiStar):
|
||||||
|
|
||||||
parameters = {
|
parameters = {
|
||||||
"put": {
|
"put": {
|
||||||
"avatar_url": "The url that the user wants to set as avatar."
|
"avatar_url": "The url that the user wants to set as avatar. MUST BE HTTPS/FTPS!"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,23 +47,27 @@ class FiorygiTransaction:
|
||||||
return f"<{self.__class__.__name__}: {self.change:+} to {self.user.username} for {self.reason}>"
|
return f"<{self.__class__.__name__}: {self.change:+} to {self.user.username} for {self.reason}>"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def spawn_fiorygi(cls, data: "CommandData", user, qty: int, reason: str):
|
async def spawn_fiorygi(cls, user, qty: int, reason: str, *, data: "CommandData", session):
|
||||||
|
FiorygiT = data.alchemy.get(cls)
|
||||||
|
FiorygiTransactionT = data.alchemy.get(FiorygiTransaction)
|
||||||
|
|
||||||
if user.fiorygi is None:
|
if user.fiorygi is None:
|
||||||
async with data.session_acm() as session:
|
session.add(
|
||||||
session.add(data.alchemy.get(Fiorygi)(
|
FiorygiT(
|
||||||
user_id=user.uid,
|
user_id=user.uid,
|
||||||
fiorygi=0
|
fiorygi=0
|
||||||
))
|
)
|
||||||
|
)
|
||||||
await ru.asyncify(session.commit)
|
await ru.asyncify(session.commit)
|
||||||
|
|
||||||
async with data.session_acm() as session:
|
session.add(
|
||||||
transaction = data.alchemy.get(FiorygiTransaction)(
|
FiorygiTransactionT(
|
||||||
user_id=user.uid,
|
user_id=user.uid,
|
||||||
change=qty,
|
change=qty,
|
||||||
reason=reason,
|
reason=reason,
|
||||||
timestamp=datetime.datetime.now()
|
timestamp=datetime.datetime.now()
|
||||||
)
|
)
|
||||||
session.add(transaction)
|
)
|
||||||
|
|
||||||
user.fiorygi.fiorygi += qty
|
user.fiorygi.fiorygi += qty
|
||||||
await ru.asyncify(session.commit)
|
await ru.asyncify(session.commit)
|
||||||
|
|
|
@ -7,8 +7,7 @@ async def oauth_refresh(*, url, client_id, client_secret, redirect_uri, refresh_
|
||||||
"client_id": client_id,
|
"client_id": client_id,
|
||||||
"client_secret": client_secret,
|
"client_secret": client_secret,
|
||||||
"code": refresh_code,
|
"code": refresh_code,
|
||||||
"grant_type": "authorization_code",
|
"grant_type": "refresh_token"
|
||||||
"redirect_uri": redirect_uri
|
|
||||||
}) as response:
|
}) as response:
|
||||||
j = await response.json()
|
j = await response.json()
|
||||||
return j
|
return j
|
||||||
|
|
Loading…
Reference in a new issue