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

28 lines
784 B
Python
Raw Normal View History

2023-01-17 03:38:37 +00:00
import secrets
2023-03-10 13:59:18 +00:00
import uuid
2023-01-17 03:38:37 +00:00
2023-02-05 14:33:33 +00:00
from core.builtins import Bot
2023-03-04 08:51:56 +00:00
from core.component import module
2023-01-17 03:38:37 +00:00
2023-04-05 02:22:37 +00:00
r = module('random', alias={'rand': 'random', 'rng': 'random'}, developers=['Dianliang233'], desc='{random.help.desc}', )
2023-01-17 03:38:37 +00:00
2023-03-15 11:29:25 +00:00
@r.handle('number <min> <max> {{random.help.number}}', )
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-15 11:29:25 +00:00
@r.handle('choice ... {{random.help.choice}}', )
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))
2023-03-10 13:59:18 +00:00
2023-03-15 11:29:25 +00:00
@r.handle('uuid {{random.help.uuid}}', )
2023-03-10 13:59:18 +00:00
async def _(msg: Bot.MessageSession):
2023-03-10 14:03:03 +00:00
await msg.finish(str(uuid.uuid4()))