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

23 lines
692 B
Python
Raw Normal View History

2023-01-17 03:38:37 +00:00
import secrets
2023-02-05 14:33:33 +00:00
from core.builtins import Bot
2023-03-01 14:04:16 +00:00
from core.utils.i18n import get_target_locale
2023-03-04 08:51:56 +00:00
from core.component import module
2023-01-17 03:38:37 +00:00
2023-03-04 09:04:35 +00:00
r = module('random', alias={'rand': 'random', 'rng': 'random'}, developers=['Dianliang233'], desc='{random.desc}', )
2023-01-17 03:38:37 +00:00
2023-03-01 14:04:16 +00:00
@r.handle('number <min> <max> {{random.number.help}}', )
2023-02-05 14:33:33 +00:00
async def _(msg: Bot.MessageSession):
2023-01-17 03:38:37 +00:00
_min = msg.parsed_msg['<min>']
_max = msg.parsed_msg['<max>']
random = secrets.randbelow(int(_max) - int(_min) + 1) + int(_min)
2023-01-28 05:53:11 +00:00
await msg.finish('' + str(random))
2023-01-17 03:38:37 +00:00
2023-03-01 14:32:58 +00:00
@r.handle('choice ... {{random.choice.help}}', )
2023-02-05 14:33:33 +00:00
async def _(msg: Bot.MessageSession):
2023-01-17 03:38:37 +00:00
choices = msg.parsed_msg['...']
await msg.finish(secrets.choice(choices))