forked from mttu-developers/konabot
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cf35e5923c | |||
| 4107a4875c | |||
| c8dae680a3 | |||
| adebd51605 | |||
| f0fdc930d4 |
3
.env.dev
3
.env.dev
@ -1,3 +1,2 @@
|
||||
DRIVER=~fastapi+~httpx+~websockets
|
||||
COMMAND_START=["!", "!", "", "/"]
|
||||
ALCONNA_USE_ORIGIN=true
|
||||
COMMAND_START=["!", "!", "", "/"]
|
||||
@ -1,3 +1,2 @@
|
||||
DRIVER=~fastapi+~httpx+~websockets
|
||||
COMMAND_START=["!", "!", "", "/"]
|
||||
ALCONNA_USE_ORIGIN=true
|
||||
COMMAND_START=["!", "!", "", "/"]
|
||||
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())
|
||||
@ -1,12 +1,19 @@
|
||||
from nonebot_plugin_alconna import Alconna, Args, Field, UniMessage, on_alconna
|
||||
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
|
||||
from konabot.plugins.weather.fetcher import fetch_radar
|
||||
|
||||
evt = on_alconna(Alconna(
|
||||
"摇骰子"
|
||||
), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=True)
|
||||
|
||||
@evt.handle()
|
||||
async def _():
|
||||
await evt.send(await UniMessage().text(await roll_dice()).export())
|
||||
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())
|
||||
|
||||
@ -7,14 +7,14 @@ number_arts = {
|
||||
|
||||
''',
|
||||
2: ''' ____
|
||||
|___ \
|
||||
|___ \\
|
||||
__) |
|
||||
/ __/
|
||||
|_____|
|
||||
''',
|
||||
3: ''' _____
|
||||
|___ /
|
||||
|_ \
|
||||
|_ \\
|
||||
___) |
|
||||
|____/
|
||||
''',
|
||||
@ -26,15 +26,15 @@ number_arts = {
|
||||
''',
|
||||
5: ''' ____
|
||||
| ___|
|
||||
|___ \
|
||||
|___ \\
|
||||
___) |
|
||||
|____/
|
||||
''',
|
||||
6: ''' __
|
||||
/ /_
|
||||
| '_ \
|
||||
| '_ \\
|
||||
| (_) |
|
||||
\___/
|
||||
\\___/
|
||||
'''
|
||||
}
|
||||
|
||||
@ -42,5 +42,13 @@ def get_random_number(min: int = 1, max: int = 6) -> int:
|
||||
import random
|
||||
return random.randint(min, max)
|
||||
|
||||
async def roll_dice() -> str:
|
||||
return number_arts[get_random_number()]
|
||||
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