Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cf35e5923c | |||
| 4107a4875c | |||
| c8dae680a3 | |||
| adebd51605 | |||
| f0fdc930d4 | |||
| a97bf7d55c | |||
| 4a26177ab9 | |||
| a727c108fe | |||
| d6d68dcc96 | |||
| b0e8779bff | |||
| c3a0b02e10 |
@ -40,8 +40,6 @@ type: docker
|
||||
trigger:
|
||||
event:
|
||||
- tag
|
||||
branch:
|
||||
- master
|
||||
|
||||
steps:
|
||||
- name: 构建并推送 Release Docker 镜像
|
||||
|
||||
24
.vscode/launch.json
vendored
Normal file
24
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "运行 Bot 并调试(自动重载)",
|
||||
"type": "debugpy",
|
||||
"request": "launch",
|
||||
"module": "watchfiles",
|
||||
"args": [
|
||||
"bot.main"
|
||||
],
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": true,
|
||||
"env": {
|
||||
"PYTHONPATH": "${workspaceFolder}"
|
||||
},
|
||||
"cwd": "${workspaceFolder}",
|
||||
"presentation": {
|
||||
"hidden": false,
|
||||
"group": "bot"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
9
.vscode/tasks.json
vendored
9
.vscode/tasks.json
vendored
@ -11,19 +11,20 @@
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": [],
|
||||
"detail": "导出生产环境依赖到 requirements.txt,不包含开发依赖和哈希值。"
|
||||
"detail": "导出生产环境依赖到 requirements.txt"
|
||||
},
|
||||
{
|
||||
"label": "Poetry: Export requirements.txt (Full)",
|
||||
"label": "Bot: Run with Auto-reload",
|
||||
"type": "shell",
|
||||
"command": "poetry export -f requirements.txt --output requirements.txt",
|
||||
"command": "poetry run watchfiles bot.main",
|
||||
"group": "build",
|
||||
"isBackground": true,
|
||||
"presentation": {
|
||||
"reveal": "always",
|
||||
"panel": "new"
|
||||
},
|
||||
"problemMatcher": [],
|
||||
"detail": "导出所有依赖(包括生产和开发依赖)到 requirements.txt,包含哈希值以确保完全一致。"
|
||||
"detail": "运行 bot 并启用自动重载功能"
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -65,7 +65,13 @@ code .
|
||||
|
||||
### 运行
|
||||
|
||||
如果改动了代码,应该先用 `Ctrl+C` 或者根据控制台提示退出,然后再重新启动。
|
||||
你可以在 VSCode 的「运行与调试」窗口,启动 `运行 Bot 并调试(自动重载)` 任务来启动 Bot,也可以使用命令行手动启动 Bot:
|
||||
|
||||
```bash
|
||||
poetry run watchfiles bot.main
|
||||
```
|
||||
|
||||
如果你不希望自动重载,只是想运行 Bot,可以直接运行:
|
||||
|
||||
```bash
|
||||
poetry run python bot.py
|
||||
|
||||
5
bot.py
5
bot.py
@ -14,7 +14,7 @@ env_enable_qq = os.environ.get("ENABLE_QQ", "none")
|
||||
env_enable_discord = os.environ.get("ENABLE_DISCORD", "none")
|
||||
env_enable_minecraft = os.environ.get("ENABLE_MINECRAFT", "none")
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main():
|
||||
nonebot.init()
|
||||
|
||||
driver = nonebot.get_driver()
|
||||
@ -35,3 +35,6 @@ if __name__ == "__main__":
|
||||
nonebot.load_plugins("konabot/plugins")
|
||||
|
||||
nonebot.run()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
46
konabot/plugins/openssl_rand/__init__.py
Normal file
46
konabot/plugins/openssl_rand/__init__.py
Normal file
@ -0,0 +1,46 @@
|
||||
import base64
|
||||
import secrets
|
||||
from typing import Literal
|
||||
|
||||
from nonebot.adapters import Event as BaseEvent
|
||||
from nonebot.adapters.discord.event import MessageEvent as DiscordMessageEvent
|
||||
from nonebot_plugin_alconna import (Alconna, Args, Field, Subcommand,
|
||||
UniMessage, on_alconna)
|
||||
|
||||
evt = on_alconna(Alconna(
|
||||
"openssl",
|
||||
Subcommand(
|
||||
"rand",
|
||||
Args["mode", Literal["-hex", "-base64"], Field(
|
||||
missing_tips=lambda: "请输入生成模式,-hex 或 -base64,例如 openssl rand -hex 16",
|
||||
unmatch_tips=lambda mode: f"{mode} 不是一个有效的格式,请使用 -hex 或 -base64"
|
||||
)],
|
||||
Args["num", int, Field(
|
||||
missing_tips=lambda: "请输入需要生成的字节数,例如 openssl rand -hex 16",
|
||||
)],
|
||||
)
|
||||
), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=False)
|
||||
|
||||
@evt.assign("rand")
|
||||
async def _(event: BaseEvent, mode: str, num: int):
|
||||
if num <= 0:
|
||||
await evt.send(await UniMessage().text(
|
||||
"生成的字节数必须是一个正整数"
|
||||
).export())
|
||||
return
|
||||
if num > 256:
|
||||
await evt.send(await UniMessage().text(
|
||||
"太大了!!!!!"
|
||||
).export())
|
||||
return
|
||||
|
||||
random_bytes = secrets.token_bytes(num)
|
||||
if mode == "-hex":
|
||||
result = random_bytes.hex()
|
||||
else:
|
||||
result = base64.b64encode(random_bytes).decode()
|
||||
|
||||
if isinstance(event, DiscordMessageEvent):
|
||||
result = f"```{result}```"
|
||||
|
||||
await evt.send(await UniMessage().text(result).export())
|
||||
19
konabot/plugins/roll_dice/__init__.py
Normal file
19
konabot/plugins/roll_dice/__init__.py
Normal file
@ -0,0 +1,19 @@
|
||||
from nonebot.adapters import Event as BaseEvent
|
||||
from nonebot.adapters.console.event import MessageEvent as ConsoleMessageEvent
|
||||
from nonebot.adapters.discord.event import MessageEvent as DiscordMessageEvent
|
||||
from nonebot_plugin_alconna import Alconna, UniMessage, on_alconna
|
||||
|
||||
from konabot.plugins.roll_dice.roll_dice import roll_dice
|
||||
|
||||
evt = on_alconna(Alconna(
|
||||
"摇骰子"
|
||||
), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=True)
|
||||
|
||||
@evt.handle()
|
||||
async def _(event: BaseEvent):
|
||||
if isinstance(event, DiscordMessageEvent):
|
||||
await evt.send(await UniMessage().text("```\n" + roll_dice() + "\n```").export())
|
||||
elif isinstance(event, ConsoleMessageEvent):
|
||||
await evt.send(await UniMessage().text(roll_dice()).export())
|
||||
else:
|
||||
await evt.send(await UniMessage().text(roll_dice(wide=True)).export())
|
||||
54
konabot/plugins/roll_dice/roll_dice.py
Normal file
54
konabot/plugins/roll_dice/roll_dice.py
Normal file
@ -0,0 +1,54 @@
|
||||
number_arts = {
|
||||
1: ''' _
|
||||
/ |
|
||||
| |
|
||||
| |
|
||||
|_|
|
||||
|
||||
''',
|
||||
2: ''' ____
|
||||
|___ \\
|
||||
__) |
|
||||
/ __/
|
||||
|_____|
|
||||
''',
|
||||
3: ''' _____
|
||||
|___ /
|
||||
|_ \\
|
||||
___) |
|
||||
|____/
|
||||
''',
|
||||
4: ''' _ _
|
||||
| || |
|
||||
| || |_
|
||||
|__ _|
|
||||
|_|
|
||||
''',
|
||||
5: ''' ____
|
||||
| ___|
|
||||
|___ \\
|
||||
___) |
|
||||
|____/
|
||||
''',
|
||||
6: ''' __
|
||||
/ /_
|
||||
| '_ \\
|
||||
| (_) |
|
||||
\\___/
|
||||
'''
|
||||
}
|
||||
|
||||
def get_random_number(min: int = 1, max: int = 6) -> int:
|
||||
import random
|
||||
return random.randint(min, max)
|
||||
|
||||
def roll_dice(wide: bool = False) -> str:
|
||||
raw = number_arts[get_random_number()]
|
||||
if wide:
|
||||
raw = (raw
|
||||
.replace("/", "/")
|
||||
.replace("\\", "\")
|
||||
.replace("_", "_")
|
||||
.replace("|", "|")
|
||||
.replace(" ", " "))
|
||||
return raw
|
||||
Reference in New Issue
Block a user