From 3850595b14e65b7f01344b01566014abb865ef56 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Mon, 8 Jan 2018 10:21:30 -0600 Subject: [PATCH] add dice module, give it a !choose --- dice/__init__.py | 9 +++++++++ dice/lib.py | 7 +++++++ hitomi/settings.py | 1 + 3 files changed, 17 insertions(+) create mode 100644 dice/__init__.py create mode 100644 dice/lib.py diff --git a/dice/__init__.py b/dice/__init__.py new file mode 100644 index 0000000..96f30f3 --- /dev/null +++ b/dice/__init__.py @@ -0,0 +1,9 @@ +"""Roll dice and do other randomization type operations.""" +from bot import hitomi +from dice import lib + + +@hitomi.command() +async def choose(*choices: str): + """Randomly select one item from multiple choices.""" + await hitomi.say(lib.choose(*choices)) diff --git a/dice/lib.py b/dice/lib.py new file mode 100644 index 0000000..7406d24 --- /dev/null +++ b/dice/lib.py @@ -0,0 +1,7 @@ +"""Functions for use in the dice module.""" +import random + + +def choose(*choices: str): + """Randomly choose an item from the provided multiple choices.""" + return random.choice(choices) diff --git a/hitomi/settings.py b/hitomi/settings.py index 7c803b1..ac1aaa7 100644 --- a/hitomi/settings.py +++ b/hitomi/settings.py @@ -38,6 +38,7 @@ INSTALLED_APPS = [ 'django.contrib.messages', 'django.contrib.staticfiles', 'bot', + 'dice', ] MIDDLEWARE = [