Add roll module

This commit is contained in:
Rosa Richter 2023-06-20 19:48:50 -06:00
parent bf3e4a7c7c
commit f62e2164da
No known key found for this signature in database
GPG Key ID: BEC39BF873A0103B
3 changed files with 60 additions and 17 deletions

View File

@ -24,6 +24,7 @@ pillow = "*"
giphypop = "*"
tzlocal = "*"
nest_asyncio = "*"
d20 = "*"
[dev-packages]
pylint = "*"

View File

@ -725,6 +725,18 @@ Searches Wikipedia for a given query and returns the first result summary and li
* !wikipedia [query] - Search Wikipedia for query
### Dice Roll
Rolls dice in XdY format.
* !roll 1d20 - roll a single d20
* !roll 1d20+4 - a skill check or attack roll
* !roll 1d20+1 adv - a skill check or attack roll with advantage
* !roll 1d20-1 dis - a skill check or attack roll with disadvantage
* !roll help - show help info
For more syntax help, see <https://d20.readthedocs.io/en/latest/start.html#dice-syntax>.
## Bot setup
* Create a Matrix user

30
modules/roll.py Normal file
View File

@ -0,0 +1,30 @@
from modules.common.module import BotModule
import d20
class MatrixModule(BotModule):
async def matrix_message(self, bot, room, event):
args = event.body.split()
args.pop(0)
if args[0] == 'help':
await bot.send_text(room, self.long_help())
else:
try:
result = d20.roll(' '.join(args), stringifier=d20.SimpleStringifier())
await bot.send_text(room, str(result), event=event)
except:
await bot.send_text(room, 'Invalid roll syntax', event=event)
def help(self):
return 'Rolls dice in XdY format'
def long_help(self, bot=None, event=None, **kwargs):
text = self.help() + (
'\n- "!roll 1d20": roll a single d20'
'\n- "!roll 1d20+4": A skill check or attack roll'
'\n- "!roll 1d20+1 adv": A skill check or attack roll with advantage'
'\n- "!roll 1d20-1 dis": A skill check or attack roll with disadvantage'
'\n- "!roll help": show this help'
'\n'
'\nFor more syntax help, see https://d20.readthedocs.io/en/latest/start.html#dice-syntax')
return text