-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from Cantido/feature/d20
Add !roll module for dice rolling
- Loading branch information
Showing
3 changed files
with
60 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ pillow = "*" | |
giphypop = "*" | ||
tzlocal = "*" | ||
nest_asyncio = "*" | ||
d20 = "*" | ||
|
||
[dev-packages] | ||
pylint = "*" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |