36 lines
746 B
Python
36 lines
746 B
Python
import random
|
|
from typing import Optional
|
|
|
|
|
|
stuff = {}
|
|
|
|
|
|
def register_var(name: str | None = None):
|
|
def wrapper(coro):
|
|
varname = name or coro.__name__
|
|
stuff[varname] = coro
|
|
return coro
|
|
|
|
return wrapper
|
|
|
|
|
|
@register_var("random")
|
|
async def random_func(ctx, a: int, b: Optional[int] = None):
|
|
a = int(a)
|
|
b = int(b) if b is not None else None
|
|
if b is not None:
|
|
low, high = a, b
|
|
else:
|
|
low, high = 0, a
|
|
return random.randint(low, high)
|
|
|
|
|
|
@register_var("user")
|
|
async def user_func(ctx, userstr: int | str):
|
|
"""
|
|
Attempt to turn the given userstr into a user.
|
|
Currently just looks up the user directly.
|
|
Some fuzzy matching may be appropriate in the future.
|
|
"""
|
|
...
|