mirror of
https://github.com/RGBCube/VReplBot
synced 2025-07-24 23:17:44 +00:00
Add repl.py
This commit is contained in:
parent
ec2bafb249
commit
9eb87f0c8d
8 changed files with 50 additions and 3 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,8 +1,8 @@
|
||||||
*
|
*
|
||||||
|
|
||||||
!.gitignore
|
!.gitignore
|
||||||
!bot/
|
!v_repl_bot/
|
||||||
!bot/cogs/
|
!v_repl_bot/cogs/
|
||||||
!poetry.lock
|
!poetry.lock
|
||||||
!*.py
|
!*.py
|
||||||
!*.example.json
|
!*.example.json
|
||||||
|
|
|
@ -11,4 +11,4 @@ jishaku = "*"
|
||||||
uvloop = "*"
|
uvloop = "*"
|
||||||
|
|
||||||
[tool.poetry.scripts]
|
[tool.poetry.scripts]
|
||||||
bot = "bot.__main__:main"
|
bot = "v_repl_bot.__main__:main"
|
||||||
|
|
|
@ -22,6 +22,7 @@ from discord.ext.commands import (
|
||||||
class ReplBot(CommandsBot):
|
class ReplBot(CommandsBot):
|
||||||
ready_timestamp: float
|
ready_timestamp: float
|
||||||
log_webhook: Webhook
|
log_webhook: Webhook
|
||||||
|
session: AIOHTTPSession
|
||||||
|
|
||||||
def __init__(self, *, token: str, webhook_url: str) -> None:
|
def __init__(self, *, token: str, webhook_url: str) -> None:
|
||||||
self.token = token
|
self.token = token
|
46
v_repl_bot/cogs/repl.py
Normal file
46
v_repl_bot/cogs/repl.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from discord.ext import commands
|
||||||
|
from discord.ext.commands import Cog, command
|
||||||
|
from jishaku.codeblocks import Codeblock, codeblock_converter
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from discord.ext.commands import Context
|
||||||
|
|
||||||
|
from .. import ReplBot
|
||||||
|
|
||||||
|
|
||||||
|
class REPL(
|
||||||
|
Cog,
|
||||||
|
name = "REPL",
|
||||||
|
description = "REPL (Read, Eval, Print, Loop) commands.",
|
||||||
|
):
|
||||||
|
def __init__(self, bot: ReplBot) -> None:
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@command(
|
||||||
|
aliases = ("run", "repl"),
|
||||||
|
brief = "Runs V code.",
|
||||||
|
help = "Runs V code."
|
||||||
|
)
|
||||||
|
async def eval(
|
||||||
|
self,
|
||||||
|
ctx: Context,
|
||||||
|
code: Codeblock | None = commands.param(converter = codeblock_converter, default = None)
|
||||||
|
) -> None:
|
||||||
|
if code is None:
|
||||||
|
await ctx.reply("No code provided.")
|
||||||
|
|
||||||
|
with self.bot.session.post(
|
||||||
|
"https://vlang.io/play",
|
||||||
|
data = { "code": code.content },
|
||||||
|
) as response:
|
||||||
|
await ctx.reply(
|
||||||
|
"```\n" + response.text.replace("`", "\u200B`\u200B") + "\n```"
|
||||||
|
) # Zero-width space.
|
||||||
|
|
||||||
|
|
||||||
|
async def setup(bot: ReplBot) -> None:
|
||||||
|
await bot.add_cog(REPL(bot))
|
Loading…
Add table
Add a link
Reference in a new issue