Archived
1
0
Fork 0
This repository has been archived on 2024-04-26. You can view files and clone it, but cannot push or open issues or pull requests.
akari-bot/modules/random/__init__.py
2023-01-19 11:29:50 +08:00

20 lines
779 B
Python

from core.builtins.message import MessageSession
from core.component import on_command
import secrets
r = on_command('random', alias={'rand': 'random', 'rng': 'random', 'dice': 'random number 1 6', 'random dice': 'random number 1 6'}, developers=[
'Dianliang233'], desc='随机数生成器(密码学安全)',)
@r.handle('number <min> <max> {生成区间内的随机整数}',)
async def _(msg: MessageSession):
_min = msg.parsed_msg['<min>']
_max = msg.parsed_msg['<max>']
random = secrets.randbelow(int(_max) - int(_min) + 1) + int(_min)
await msg.finish(''+str(random))
@r.handle('choice ... {从选项中选择一个}',)
async def _(msg: MessageSession):
choices = msg.parsed_msg['...']
await msg.finish(secrets.choice(choices))