Merge pull request #242 from Cantido/feature/d20
Add !roll module for dice rolling
This commit is contained in:
commit
68b4fa4772
1
Pipfile
1
Pipfile
|
@ -24,6 +24,7 @@ pillow = "*"
|
||||||
giphypop = "*"
|
giphypop = "*"
|
||||||
tzlocal = "*"
|
tzlocal = "*"
|
||||||
nest_asyncio = "*"
|
nest_asyncio = "*"
|
||||||
|
d20 = "*"
|
||||||
|
|
||||||
[dev-packages]
|
[dev-packages]
|
||||||
pylint = "*"
|
pylint = "*"
|
||||||
|
|
12
README.md
12
README.md
|
@ -725,6 +725,18 @@ Searches Wikipedia for a given query and returns the first result summary and li
|
||||||
|
|
||||||
* !wikipedia [query] - Search Wikipedia for query
|
* !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
|
## Bot setup
|
||||||
|
|
||||||
* Create a Matrix user
|
* Create a Matrix user
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue