-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Limnium/main
更新了正则的pattern,完善了输入、返回机制
- Loading branch information
Showing
7 changed files
with
104 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Publish Python 🐍 distributions 📦 to PyPI | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.9' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build | ||
- name: Build package | ||
run: python -m build | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
build/ | ||
dist/ | ||
nonebot_plugin_code.egg-info/ | ||
nonebot_plugin_code.egg-info/ | ||
.idea | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,34 +5,38 @@ | |
# @Email : [email protected] | ||
# @File : __init__.py.py | ||
# @Software: PyCharm | ||
from nonebot import on_command | ||
from nonebot.adapters.onebot.v11 import Bot, MessageEvent, Message | ||
|
||
# @Time : 2023/01/19 21:00 | ||
# @UpdateBy: Limnium | ||
# 更新了正则的pattern,完善了返回机制,“优化”代码风格。 | ||
from nonebot import on_command | ||
from nonebot.params import CommandArg | ||
from nonebot.adapters.onebot.v11 import MessageEvent, Message, Bot, GroupMessageEvent | ||
from .run import run | ||
|
||
runcode = on_command('code', priority=5) | ||
|
||
|
||
@runcode.handle() | ||
async def _(bot: Bot, event: MessageEvent): | ||
code = str(event.get_message()).strip() | ||
async def runcode_body(bot: Bot, event: MessageEvent, arg: Message = CommandArg()): | ||
code = str(arg).strip() | ||
res = await run(code) | ||
await runcode.send(message=Message(res), at_sender=True) | ||
messages = {"type": "node", "data": {"name": "return", "uin": bot.self_id, "content": Message(res)}} | ||
if isinstance(event, GroupMessageEvent): | ||
return await bot.call_api("send_group_forward_msg", group_id=event.group_id, messages=messages) | ||
else: | ||
return await bot.call_api("send_private_forward_msg", user_id=event.user_id, messages=messages) | ||
|
||
|
||
__usage__ = """ | ||
发送 | ||
code [语言] [-i] [inputText] | ||
code [语言] [stdin(空格将被替换为回车)] | ||
[代码] | ||
-i:可选 输入 后跟输入内容 | ||
运行代码示例(python)(无输入): | ||
code py | ||
print("sb") | ||
运行代码示例(python)(有输入): | ||
code py -i 你好 | ||
print(input()) | ||
运行代码示例(python): | ||
code py 你好 | ||
print(input()) | ||
目前仅支持c/cpp/c#/py/php/go/java/js | ||
运行于:https://glot.io/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,11 @@ | |
# @Email : [email protected] | ||
# @File : run.py | ||
# @Software: PyCharm | ||
import re | ||
|
||
# @Time : 2023/01/19 21:00 | ||
# @UpdateBy: Limnium | ||
# 更新了正则的pattern,完善了返回机制,“优化”代码风格。 | ||
import re | ||
import httpx | ||
|
||
codeType = { | ||
|
@@ -25,46 +28,26 @@ | |
async def run(strcode): | ||
strcode = strcode.replace('&', '&').replace('[', '[').replace(']', ']') | ||
try: | ||
a = re.findall(r'(py|php|java|cpp|js|c#|c|go|asm)\s?(-i)?\s?(\w*)?(\n|\r)((?:.|\n)+)', strcode)[0] | ||
print(a) | ||
a = re.match(r'(py|php|java|cpp|js|c#|c|go|asm)\b ?(.*)\n((?:.|\n)+)', strcode) | ||
lang, stdin, code = a.group(1), a.group(2).replace(' ', '\n'), a.group(3) | ||
except: | ||
return "输入有误汪\n目前仅支持c/cpp/c#/py/php/go/java/js" | ||
if "-i" in strcode: | ||
lang, code = a[0], a[4] | ||
dataJson = { | ||
"files": [ | ||
{ | ||
"name": f"main.{codeType[lang][1]}", | ||
"content": code | ||
} | ||
], | ||
"stdin": a[2], | ||
"command": "" | ||
} | ||
else: | ||
lang, code = a[0], a[4] | ||
dataJson = { | ||
"files": [ | ||
{ | ||
"name": f"main.{codeType[lang][1]}", | ||
"content": code | ||
} | ||
], | ||
"stdin": "", | ||
"command": "" | ||
} | ||
headers = { | ||
"Authorization": "Token 0123456-789a-bcde-f012-3456789abcde", | ||
"content-type": "application/" | ||
return "输入有误,目前仅支持c/cpp/c#/py/php/go/java/js" | ||
dataJson = { | ||
"files": [ | ||
{ | ||
"name": f"main.{codeType[lang][1]}", | ||
"content": code | ||
} | ||
], | ||
"stdin": stdin, | ||
"command": "" | ||
} | ||
headers = {"Authorization": "Token 0123456-789a-bcde-f012-3456789abcde", | ||
"content-type": "application/"} | ||
async with httpx.AsyncClient() as client: | ||
res = (await client.post(url=f'https://glot.io/run/{codeType[lang][0]}?version=latest', headers=headers, json=dataJson)) | ||
print(dataJson) | ||
res = await client.post(url=f'https://glot.io/run/{codeType[lang][0]}?version=latest', headers=headers, json=dataJson) | ||
if res.status_code == 200: | ||
if res.json()['stdout'] != "": | ||
if len(repr(res.json()['stdout'])) < 100: | ||
return res.json()['stdout'] | ||
else: | ||
return "返回字符过长呐~~~" | ||
else: | ||
return res.json()['stderr'].strip() | ||
res = res.json() | ||
return res['stdout']+('\n---\n'+res['stderr'] if res['stderr'] else '') | ||
else: | ||
return '响应异常' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
|
||
setuptools.setup( | ||
name="nonebot_plugin_code", | ||
version="0.0.4", | ||
version="0.0.5", | ||
author="yzyyz1387", | ||
author_email="[email protected]", | ||
keywords=("pip", "nonebot2", "nonebot", "nonebot_plugin"), | ||
|