mirror of
https://github.com/RGBCube/VReplBot
synced 2025-07-27 00:17:46 +00:00
Add &show
This commit is contained in:
parent
fde71c964f
commit
9a416f5000
1 changed files with 48 additions and 1 deletions
|
@ -48,11 +48,58 @@ class REPL(
|
||||||
"The output was too long to be sent as a message. Here is a file instead:",
|
"The output was too long to be sent as a message. Here is a file instead:",
|
||||||
file = File(BytesIO(text.encode()), filename = "output.txt")
|
file = File(BytesIO(text.encode()), filename = "output.txt")
|
||||||
)
|
)
|
||||||
else:
|
return
|
||||||
|
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
"```" + text + "```"
|
"```" + 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(
|
||||||
|
"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:
|
async def setup(bot: ReplBot) -> None:
|
||||||
await bot.add_cog(REPL(bot))
|
await bot.add_cog(REPL(bot))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue