mirror of
https://github.com/RGBCube/VReplBot
synced 2025-07-27 16:37:47 +00:00
Add &show
This commit is contained in:
parent
fde71c964f
commit
9a416f5000
1 changed files with 48 additions and 1 deletions
|
@ -48,10 +48,57 @@ class REPL(
|
|||
"The output was too long to be sent as a message. Here is a file instead:",
|
||||
file = File(BytesIO(text.encode()), filename = "output.txt")
|
||||
)
|
||||
return
|
||||
|
||||
await ctx.reply(
|
||||
"```" + text + "```"
|
||||
)
|
||||
|
||||
@command(
|
||||
aliases = ("download",),
|
||||
brief = "Shows the code in a V playground query.",
|
||||
help = "Shows the code in a V playground query."
|
||||
)
|
||||
async def show(self, ctx: Context, query: str | None = None) -> None:
|
||||
if query is None:
|
||||
if not (reply := ctx.message.reference):
|
||||
await ctx.reply("No query provided.")
|
||||
return
|
||||
|
||||
replied_message = await ctx.channel.fetch_message(reply.message_id)
|
||||
content = replied_message.content
|
||||
|
||||
if "play.vlang.io/?query=" in content:
|
||||
query = content.split("play.vlang.io/?query=", 1)[1].split(" ", 1)[0]
|
||||
else:
|
||||
query = content.split(" ", 1)[0]
|
||||
|
||||
query = query.lstrip("https://").lstrip("play.vlang.io/?query=")
|
||||
|
||||
if not query:
|
||||
await ctx.reply("No query provided.")
|
||||
return
|
||||
|
||||
async with await self.bot.session.post(
|
||||
f"https://play.vlang.io/query",
|
||||
data = { "hash": query }
|
||||
) as response:
|
||||
text = await response.text()
|
||||
|
||||
if text == "Not found.":
|
||||
await ctx.reply("Invalid link.")
|
||||
return
|
||||
|
||||
if len(text) + 8 > 2000:
|
||||
await ctx.reply(
|
||||
"```" + text + "```"
|
||||
"The code was too long to be sent as a message. Here is a file instead:",
|
||||
file = File(BytesIO(text.encode()), filename = "code.v")
|
||||
)
|
||||
return
|
||||
|
||||
await ctx.reply(
|
||||
"```v\n" + text + "```"
|
||||
)
|
||||
|
||||
|
||||
async def setup(bot: ReplBot) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue