mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
idk stavo guardando anacapri the dream e non so bene cos'ho fatto
forse ho implementato la scopa https://www.youtube.com/watch?v=NFclBewnVmY
This commit is contained in:
parent
cbcac7a134
commit
e90221d1b6
11 changed files with 142 additions and 4 deletions
|
@ -27,6 +27,8 @@ from .ahnonlosoio import AhnonlosoioCommand
|
|||
from .eat import EatCommand
|
||||
from .pmots import PmotsCommand
|
||||
from .peertube import PeertubeCommand
|
||||
from .eval import EvalCommand
|
||||
from .exec import ExecCommand
|
||||
|
||||
# Enter the commands of your Pack here!
|
||||
available_commands = [
|
||||
|
@ -58,6 +60,8 @@ available_commands = [
|
|||
EatCommand,
|
||||
PmotsCommand,
|
||||
PeertubeCommand,
|
||||
EvalCommand,
|
||||
ExecCommand,
|
||||
]
|
||||
|
||||
# Don't change this, it should automatically generate __all__
|
||||
|
|
23
royalpack/commands/eval.py
Normal file
23
royalpack/commands/eval.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
import royalnet
|
||||
from royalnet.commands import *
|
||||
from royalnet.backpack.tables import *
|
||||
|
||||
|
||||
class EvalCommand(Command):
|
||||
# oh god if there is a security vulnerability
|
||||
name: str = "eval"
|
||||
|
||||
description: str = "Esegui una espressione Python... se sei Steffo."
|
||||
|
||||
syntax: str = "{espressione}"
|
||||
|
||||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||
user: User = await data.get_author(error_if_none=True)
|
||||
if user.role != "Admin":
|
||||
raise CommandError("Non sei autorizzato a eseguire codice arbitrario!\n"
|
||||
"(Sarebbe un po' pericoloso se te lo lasciassi eseguire, non trovi?)")
|
||||
try:
|
||||
result = eval(args.joined(require_at_least=1))
|
||||
except Exception as e:
|
||||
raise CommandError(f"Eval fallito: {e}")
|
||||
await data.reply(repr(result))
|
23
royalpack/commands/exec.py
Normal file
23
royalpack/commands/exec.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
import royalnet
|
||||
from royalnet.commands import *
|
||||
from royalnet.backpack.tables import *
|
||||
|
||||
|
||||
class ExecCommand(Command):
|
||||
# oh god if there is a security vulnerability
|
||||
name: str = "exec"
|
||||
|
||||
description: str = "Esegui uno script Python... se sei Steffo."
|
||||
|
||||
syntax: str = "{script}"
|
||||
|
||||
async def run(self, args: CommandArgs, data: CommandData) -> None:
|
||||
user: User = await data.get_author(error_if_none=True)
|
||||
if user.role != "Admin":
|
||||
raise CommandError("Non sei autorizzato a eseguire codice arbitrario!\n"
|
||||
"(Sarebbe un po' pericoloso se te lo lasciassi eseguire, non trovi?)")
|
||||
try:
|
||||
exec(args.joined(require_at_least=1))
|
||||
except Exception as e:
|
||||
raise CommandError(f"Esecuzione fallita: {e}")
|
||||
await data.reply(f"✅ Fatto!")
|
|
@ -36,6 +36,10 @@ class UserinfoCommand(Command):
|
|||
"",
|
||||
]
|
||||
|
||||
if user.fiorygi:
|
||||
r.append(f"{user.fiorygi}")
|
||||
r.append("")
|
||||
|
||||
# Bios are a bit too long
|
||||
# if user.bio:
|
||||
# r.append(f"{user.bio}")
|
||||
|
@ -58,6 +62,6 @@ class UserinfoCommand(Command):
|
|||
|
||||
if user.trivia_score:
|
||||
r.append(f"Trivia: [b]{user.trivia_score.correct_answers}[/b] risposte corrette / "
|
||||
f"{user.trivia_score.total_answers}) totali")
|
||||
f"{user.trivia_score.total_answers} totali")
|
||||
|
||||
await data.reply("\n".join(r))
|
||||
|
|
|
@ -4,6 +4,8 @@ from .api_user_get import ApiUserGetStar
|
|||
from .api_diario_list import ApiDiarioListStar
|
||||
from .api_diario_get import ApiDiarioGetStar
|
||||
from .api_discord_cv import ApiDiscordCvStar
|
||||
from .api_wiki_get import ApiWikiGetStar
|
||||
from .api_wiki_list import ApiUserListStar
|
||||
|
||||
# Enter the PageStars of your Pack here!
|
||||
available_page_stars = [
|
||||
|
@ -12,6 +14,8 @@ available_page_stars = [
|
|||
ApiDiarioListStar,
|
||||
ApiDiarioGetStar,
|
||||
ApiDiscordCvStar,
|
||||
ApiWikiGetStar,
|
||||
ApiUserListStar,
|
||||
]
|
||||
|
||||
# Enter the ExceptionStars of your Pack here!
|
||||
|
|
|
@ -7,7 +7,6 @@ from royalnet.backpack.tables import *
|
|||
|
||||
class ApiUserListStar(PageStar):
|
||||
path = "/api/user/list"
|
||||
tables = {User}
|
||||
|
||||
async def page(self, request: Request) -> JSONResponse:
|
||||
async with self.alchemy.session_acm() as session:
|
||||
|
|
22
royalpack/stars/api_wiki_get.py
Normal file
22
royalpack/stars/api_wiki_get.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
from starlette.requests import Request
|
||||
from starlette.responses import *
|
||||
from royalnet.constellation import *
|
||||
from royalnet.utils import *
|
||||
from ..tables import *
|
||||
import uuid
|
||||
|
||||
|
||||
class ApiWikiGetStar(PageStar):
|
||||
path = "/api/wiki/get/{wiki_page_uuid}"
|
||||
|
||||
async def page(self, request: Request) -> JSONResponse:
|
||||
wiki_page_uuid_str = request.path_params.get("wiki_page_uuid", "")
|
||||
try:
|
||||
wiki_page_uuid = uuid.UUID(wiki_page_uuid_str)
|
||||
except (ValueError, AttributeError, TypeError):
|
||||
return shoot(400, "Invalid wiki_page_uuid")
|
||||
async with self.alchemy.session_acm() as session:
|
||||
wikipage: WikiPage = await asyncify(session.query(self.alchemy.get(WikiPage)).get, wiki_page_uuid)
|
||||
if wikipage is None:
|
||||
return shoot(404, "No such page")
|
||||
return JSONResponse(wikipage.json_full())
|
15
royalpack/stars/api_wiki_list.py
Normal file
15
royalpack/stars/api_wiki_list.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
from starlette.requests import Request
|
||||
from starlette.responses import *
|
||||
from royalnet.constellation import *
|
||||
from royalnet.utils import *
|
||||
from royalnet.backpack.tables import *
|
||||
from ..tables import *
|
||||
|
||||
|
||||
class ApiUserListStar(PageStar):
|
||||
path = "/api/wiki/list"
|
||||
|
||||
async def page(self, request: Request) -> JSONResponse:
|
||||
async with self.alchemy.session_acm() as session:
|
||||
pages: typing.List[WikiPage] = await asyncify(session.query(self.alchemy.get(WikiPage)).all)
|
||||
return JSONResponse([page.json_list() for page in pages])
|
|
@ -9,6 +9,7 @@ from .triviascores import TriviaScore
|
|||
from .mmevents import MMEvent
|
||||
from .mmresponse import MMResponse
|
||||
from .leagueoflegends import LeagueOfLegends
|
||||
from .fiorygi import Fiorygi
|
||||
|
||||
# Enter the tables of your Pack here!
|
||||
available_tables = [
|
||||
|
@ -21,7 +22,8 @@ available_tables = [
|
|||
TriviaScore,
|
||||
MMEvent,
|
||||
MMResponse,
|
||||
LeagueOfLegends
|
||||
LeagueOfLegends,
|
||||
Fiorygi,
|
||||
]
|
||||
|
||||
# Don't change this, it should automatically generate __all__
|
||||
|
|
25
royalpack/tables/fiorygi.py
Normal file
25
royalpack/tables/fiorygi.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from sqlalchemy import *
|
||||
from sqlalchemy.orm import relationship, backref
|
||||
from sqlalchemy.ext.declarative import declared_attr
|
||||
|
||||
|
||||
class Fiorygi:
|
||||
__tablename__ = "fiorygi"
|
||||
|
||||
@declared_attr
|
||||
def user_id(self):
|
||||
return Column(Integer, ForeignKey("users.uid"), primary_key=True)
|
||||
|
||||
@declared_attr
|
||||
def user(self):
|
||||
return relationship("User", backref=backref("fiorygi", uselist=False))
|
||||
|
||||
@declared_attr
|
||||
def fiorygi(self):
|
||||
return Column(Integer, nullable=False, default=0)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Fiorygi di {self.royal}: {self.fiorygi}>"
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.fiorygi} fioryg" + ("i" if self.fiorygi != 1 else "")
|
|
@ -30,9 +30,26 @@ class WikiPage:
|
|||
return Column(String, nullable=False, default="markdown")
|
||||
|
||||
@declared_attr
|
||||
def css(self):
|
||||
def theme(self):
|
||||
return Column(String)
|
||||
|
||||
@property
|
||||
def page_short_id(self):
|
||||
return to_urluuid(self.page_id)
|
||||
|
||||
def json_list(self) -> dict:
|
||||
return {
|
||||
"page_id": str(self.page_id),
|
||||
"page_short_id": self.page_short_id,
|
||||
"title": self.title
|
||||
}
|
||||
|
||||
def json_full(self) -> dict:
|
||||
return {
|
||||
"page_id": str(self.page_id),
|
||||
"page_short_id": self.page_short_id,
|
||||
"title": self.title,
|
||||
"contents": self.contents,
|
||||
"format": self.format,
|
||||
"theme": self.theme,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue