Dice: rename plugin.

This commit is contained in:
oddluck 2020-02-15 01:03:44 +00:00
parent 1740a06b3d
commit 11f96e4d3c
17 changed files with 131 additions and 131 deletions

View File

@ -4,11 +4,11 @@ Install dependencies: python3 -m pip install -r requirements.txt
## Description
Dicebot plugin contains the commands which simulate rolling of dice.
Dice plugin contains the commands which simulate rolling of dice.
Though core supybot plugin Games contain 'dice' command, it is very simple and
is not sufficient for advanced uses, such as online playing of tabletop
role-playing games using IRC.
The most basic feature of any dicebot is, of course, rolling of one or several
The most basic feature of any dice plugin is, of course, rolling of one or several
identical dice and showing the results. That is what core 'dice' command can
do. It takes an expression such as 3d6 and returns a series of numbers -
results of rolling each (of 3) die (6-sided): '2, 4, and 4'. This may be
@ -61,9 +61,9 @@ shuffled before drawing next card.
## Thanks
Ur-DnD roleplaying community (#dnd @ RusNet) for games, talking and fun, and
personally Zuzuzu for describing basic dicebot requirements, which led to
personally Zuzuzu for describing basic Dice requirements, which led to
writing the first version of this plugin in August 2007.
## Tests
Run tests: supybot-test Dicebot && pytest
Run tests: supybot-test Dice && pytest

View File

@ -28,7 +28,7 @@
###
"""
Dice bot
Dice
"""
import supybot
@ -55,7 +55,7 @@ from . import deck
from imp import reload
# In case we're being reloaded.
reload(deck)
reload(plugin)
reload(plugin)
# Add more reloads here if you add third-party modules and want them to be
# reloaded when this plugin is reloaded. Don't forget to import them as well!

View File

@ -35,14 +35,14 @@ def configure(advanced):
# a bool that specifies whether the user identified himself as an advanced
# user or not. You should effect your configuration by manipulating the
# registry as appropriate.
conf.registerPlugin('Dicebot', True)
conf.registerPlugin('Dice', True)
Dicebot = conf.registerPlugin('Dicebot')
conf.registerChannelValue(Dicebot, 'autoRoll',
Dice = conf.registerPlugin('Dice')
conf.registerChannelValue(Dice, 'autoRoll',
registry.Boolean(False, """Determines whether the bot will automatically
roll the dice it sees in the channel."""))
conf.registerGlobalValue(Dicebot, 'autoRollInPrivate',
conf.registerGlobalValue(Dice, 'autoRollInPrivate',
registry.Boolean(False, """Determines whether the bot will automatically
roll the dice it sees in private messages."""))

View File

@ -1,10 +1,10 @@
Description
~~~~~~~~~~~
Dicebot plugin contains the commands which simulate rolling of dice.
Dice plugin contains the commands which simulate rolling of dice.
Though core supybot plugin Games contain 'dice' command, it is very simple and
is not sufficient for advanced uses, such as online playing of tabletop
role-playing games using IRC.
The most basic feature of any dicebot is, of course, rolling of one or several
The most basic feature of any dice plugin is, of course, rolling of one or several
identical dice and showing the results. That is what core 'dice' command can
do. It takes an expression such as 3d6 and returns a series of numbers -
results of rolling each (of 3) die (6-sided): '2, 4, and 4'. This may be
@ -57,6 +57,6 @@ shuffled before drawing next card.
Thanks
~~~~~~
Ur-DnD roleplaying community (#dnd @ RusNet) for games, talking and fun, and
personally Zuzuzu for describing basic dicebot requirements, which led to
personally Zuzuzu for describing basic dice requirements, which led to
writing the first version of this plugin in August 2007.

View File

@ -39,7 +39,7 @@ from supybot.utils.str import format, ordinal
import supybot.ircmsgs as ircmsgs
import supybot.callbacks as callbacks
class Dicebot(callbacks.Plugin):
class Dice(callbacks.Plugin):
"""This plugin supports rolling the dice using !roll 4d20+3 as well as
automatically rolling such combinations it sees in the channel (if
autoRoll option is enabled for that channel) or query (if
@ -65,7 +65,7 @@ class Dicebot(callbacks.Plugin):
MAX_ROLLS = 30
def __init__(self, irc):
super(Dicebot, self).__init__(irc)
super(Dice, self).__init__(irc)
self.deck = Deck()
def _roll(self, dice, sides, mod=0):
@ -505,7 +505,7 @@ class Dicebot(callbacks.Plugin):
text = msg.args[1]
self._process(irc, text)
Class = Dicebot
Class = Dice
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

115
Dice/test.py Normal file
View File

@ -0,0 +1,115 @@
###
# Copyright (c) 2007-2010, Andrey Rahmatullin
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
from supybot.test import PluginTestCase
class DiceTestCase(PluginTestCase):
plugins = ('Dice',)
def testPlugin(self):
self.assertHelp('Dice roll')
self.assertNotError('Dice roll 1d2')
self.assertNoResponse('Dice roll dummy')
def testRollStd(self):
self.assertRegexp('Dice roll 1d20', r'\[1d20\] \d+')
self.assertRegexp('Dice roll d20', r'\[1d20\] \d+')
self.assertRegexp('Dice roll 1d20+5', r'\[1d20\+5\] \d+')
self.assertRegexp('Dice roll d20+5', r'\[1d20\+5\] \d+')
self.assertRegexp('Dice roll 1d20-30', r'\[1d20-30\] -\d+')
self.assertRegexp('Dice roll d20-30', r'\[1d20-30\] -\d+')
self.assertRegexp('Dice roll 2d20-1', r'\[2d20-1\] \d+')
self.assertRegexp('Dice roll d20-1d6+3', r'\[1d20-1d6\+3\] -?\d+')
self.assertRegexp('Dice roll 1d20+d20+3', r'\[2d20\+3\] \d+')
self.assertRegexp('Dice roll 1d20+4+d6-3', r'\[1d20\+1d6\+1\] \d+')
self.assertNoResponse('Dice roll 1d1')
def testRollMult(self):
self.assertRegexp('Dice roll 2#1d20', r'\[1d20\] \d+, \d+')
self.assertRegexp('Dice roll 2#d20', r'\[1d20\] \d+, \d+')
self.assertRegexp('Dice roll 2#1d20+5', r'\[1d20\+5\] \d+, \d+')
self.assertRegexp('Dice roll 2#d20+5', r'\[1d20\+5\] \d+, \d+')
self.assertRegexp('Dice roll 2#1d20-30', r'\[1d20-30\] -\d+, -\d+')
self.assertRegexp('Dice roll 2#d20-30', r'\[1d20-30\] -\d+, -\d+')
self.assertRegexp('Dice roll 2#2d20-1', r'\[2d20-1\] \d+, \d+')
self.assertNoResponse('Dice roll 2#1d1')
def testRollSR(self):
self.assertRegexp('Dice roll 2#sd', r'\(pool 2\) (\d hits?|critical glitch!)')
self.assertRegexp('Dice roll 4#sd', r'\(pool 4\) (\d hits?(, glitch)?|critical glitch!)')
self.assertNoResponse('Dice roll 0#sd')
def testRollSRX(self):
self.assertRegexp('Dice roll 2#sdx', r'\(pool 2, exploding\) (\d hits?|critical glitch!)')
self.assertRegexp('Dice roll 4#sdx', r'\(pool 4, exploding\) (\d hits?(, glitch)?|critical glitch!)')
self.assertNoResponse('Dice roll 0#sdx')
def testRoll7S(self):
self.assertRegexp('Dice roll 3k2', r'\[3k2\] \(\d+\) \d+, \d+')
self.assertRegexp('Dice roll 2k3', r'\[2k2\] \(\d+\) \d+, \d+')
self.assertRegexp('Dice roll 3kk2', r'\[3k2\] \(\d+\) \d+, \d+ \| \d+')
self.assertRegexp('Dice roll +3k2', r'\[3k2\] \(\d+\) \d+, \d+ \| \d+')
self.assertRegexp('Dice roll -3k2', r'\[3k2, not exploding\] \(\d+\) \d+, \d+')
self.assertRegexp('Dice roll +3kk2', r'\[3k2\] \(\d+\) \d+, \d+ \| \d+')
self.assertRegexp('Dice roll -3kk2', r'\[3k2, not exploding\] \(\d+\) \d+, \d+ \| \d+')
self.assertRegexp('Dice roll 3k2+1', r'\[3k2\+1\] \(\d+\) \d+, \d+')
self.assertRegexp('Dice roll 3k2-1', r'\[3k2-1\] \(\d+\) \d+, \d+')
self.assertRegexp('Dice roll -3k2-1', r'\[3k2-1, not exploding\] \(\d+\) \d+, \d+')
self.assertRegexp('Dice roll 10k10', r'\[10k10\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('Dice roll 12k10', r'\[10k10\+20\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('Dice roll 12k9', r'\[10k10\+10\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('Dice roll 12k8', r'\[10k10\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('Dice roll 12k9+5', r'\[10k10\+15\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('Dice roll 12kk9', r'\[10k10\+10\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('Dice roll 12kk7', r'\[10k9\] \(\d+\) (\d+, ){8}\d+ \| \d+')
self.assertRegexp('Dice roll 3#3k2', r'\[3k2\] \(\d+\) \d+, \d+(; \(\d+\) \d+, \d+){2}')
def testDeck(self):
validator = r'(2|3|4|5|6|7|8|9|10|J|Q|K|A)(♣|♦|♥|♠)|(Black|Red) Joker'
self.assertRegexp('Dice draw', validator)
self.assertResponse('Dice shuffle', 'shuffled')
for i in range(0, 54):
self.assertRegexp('Dice draw', validator)
def testWoD(self):
self.assertRegexp('Dice roll 3w', r'\(3\) (\d success(es)?|FAIL)')
self.assertRegexp('Dice roll 3w-', r'\(3, not exploding\) (\d success(es)?|FAIL)')
self.assertRegexp('Dice roll 3w8', r'\(3, 8-again\) (\d success(es)?|FAIL)')
self.assertNoResponse('Dice roll 0w')
def testDH(self):
self.assertRegexp('Dice roll vs(10)', r'-?\d+ \(\d+ vs 10\)')
self.assertRegexp('Dice roll vs(10+20)', r'-?\d+ \(\d+ vs 30\)')
self.assertRegexp('Dice roll vs(10+20-5)', r'-?\d+ \(\d+ vs 25\)')
self.assertRegexp('Dice roll 3vs(10+20)', r'-?\d+, -?\d+, -?\d+ \(\d+, \d+, \d+ vs 30\)')
def testWG(self):
self.assertRegexp('Dice roll 10#wg', r'\[pool 10\] \d+ icon\(s\): [❶❷❸❹❺❻] ([1-5➅] )*(\| Glory|\| Complication)?')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:

View File

@ -1,115 +0,0 @@
###
# Copyright (c) 2007-2010, Andrey Rahmatullin
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
from supybot.test import PluginTestCase
class DicebotTestCase(PluginTestCase):
plugins = ('Dicebot',)
def testPlugin(self):
self.assertHelp('dicebot roll')
self.assertNotError('dicebot roll 1d2')
self.assertNoResponse('dicebot roll dummy')
def testRollStd(self):
self.assertRegexp('dicebot roll 1d20', r'\[1d20\] \d+')
self.assertRegexp('dicebot roll d20', r'\[1d20\] \d+')
self.assertRegexp('dicebot roll 1d20+5', r'\[1d20\+5\] \d+')
self.assertRegexp('dicebot roll d20+5', r'\[1d20\+5\] \d+')
self.assertRegexp('dicebot roll 1d20-30', r'\[1d20-30\] -\d+')
self.assertRegexp('dicebot roll d20-30', r'\[1d20-30\] -\d+')
self.assertRegexp('dicebot roll 2d20-1', r'\[2d20-1\] \d+')
self.assertRegexp('dicebot roll d20-1d6+3', r'\[1d20-1d6\+3\] -?\d+')
self.assertRegexp('dicebot roll 1d20+d20+3', r'\[2d20\+3\] \d+')
self.assertRegexp('dicebot roll 1d20+4+d6-3', r'\[1d20\+1d6\+1\] \d+')
self.assertNoResponse('dicebot roll 1d1')
def testRollMult(self):
self.assertRegexp('dicebot roll 2#1d20', r'\[1d20\] \d+, \d+')
self.assertRegexp('dicebot roll 2#d20', r'\[1d20\] \d+, \d+')
self.assertRegexp('dicebot roll 2#1d20+5', r'\[1d20\+5\] \d+, \d+')
self.assertRegexp('dicebot roll 2#d20+5', r'\[1d20\+5\] \d+, \d+')
self.assertRegexp('dicebot roll 2#1d20-30', r'\[1d20-30\] -\d+, -\d+')
self.assertRegexp('dicebot roll 2#d20-30', r'\[1d20-30\] -\d+, -\d+')
self.assertRegexp('dicebot roll 2#2d20-1', r'\[2d20-1\] \d+, \d+')
self.assertNoResponse('dicebot roll 2#1d1')
def testRollSR(self):
self.assertRegexp('dicebot roll 2#sd', r'\(pool 2\) (\d hits?|critical glitch!)')
self.assertRegexp('dicebot roll 4#sd', r'\(pool 4\) (\d hits?(, glitch)?|critical glitch!)')
self.assertNoResponse('dicebot roll 0#sd')
def testRollSRX(self):
self.assertRegexp('dicebot roll 2#sdx', r'\(pool 2, exploding\) (\d hits?|critical glitch!)')
self.assertRegexp('dicebot roll 4#sdx', r'\(pool 4, exploding\) (\d hits?(, glitch)?|critical glitch!)')
self.assertNoResponse('dicebot roll 0#sdx')
def testRoll7S(self):
self.assertRegexp('dicebot roll 3k2', r'\[3k2\] \(\d+\) \d+, \d+')
self.assertRegexp('dicebot roll 2k3', r'\[2k2\] \(\d+\) \d+, \d+')
self.assertRegexp('dicebot roll 3kk2', r'\[3k2\] \(\d+\) \d+, \d+ \| \d+')
self.assertRegexp('dicebot roll +3k2', r'\[3k2\] \(\d+\) \d+, \d+ \| \d+')
self.assertRegexp('dicebot roll -3k2', r'\[3k2, not exploding\] \(\d+\) \d+, \d+')
self.assertRegexp('dicebot roll +3kk2', r'\[3k2\] \(\d+\) \d+, \d+ \| \d+')
self.assertRegexp('dicebot roll -3kk2', r'\[3k2, not exploding\] \(\d+\) \d+, \d+ \| \d+')
self.assertRegexp('dicebot roll 3k2+1', r'\[3k2\+1\] \(\d+\) \d+, \d+')
self.assertRegexp('dicebot roll 3k2-1', r'\[3k2-1\] \(\d+\) \d+, \d+')
self.assertRegexp('dicebot roll -3k2-1', r'\[3k2-1, not exploding\] \(\d+\) \d+, \d+')
self.assertRegexp('dicebot roll 10k10', r'\[10k10\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('dicebot roll 12k10', r'\[10k10\+20\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('dicebot roll 12k9', r'\[10k10\+10\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('dicebot roll 12k8', r'\[10k10\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('dicebot roll 12k9+5', r'\[10k10\+15\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('dicebot roll 12kk9', r'\[10k10\+10\] \(\d+\) (\d+, ){9}\d+')
self.assertRegexp('dicebot roll 12kk7', r'\[10k9\] \(\d+\) (\d+, ){8}\d+ \| \d+')
self.assertRegexp('dicebot roll 3#3k2', r'\[3k2\] \(\d+\) \d+, \d+(; \(\d+\) \d+, \d+){2}')
def testDeck(self):
validator = r'(2|3|4|5|6|7|8|9|10|J|Q|K|A)(♣|♦|♥|♠)|(Black|Red) Joker'
self.assertRegexp('dicebot draw', validator)
self.assertResponse('dicebot shuffle', 'shuffled')
for i in range(0, 54):
self.assertRegexp('dicebot draw', validator)
def testWoD(self):
self.assertRegexp('dicebot roll 3w', r'\(3\) (\d success(es)?|FAIL)')
self.assertRegexp('dicebot roll 3w-', r'\(3, not exploding\) (\d success(es)?|FAIL)')
self.assertRegexp('dicebot roll 3w8', r'\(3, 8-again\) (\d success(es)?|FAIL)')
self.assertNoResponse('dicebot roll 0w')
def testDH(self):
self.assertRegexp('dicebot roll vs(10)', r'-?\d+ \(\d+ vs 10\)')
self.assertRegexp('dicebot roll vs(10+20)', r'-?\d+ \(\d+ vs 30\)')
self.assertRegexp('dicebot roll vs(10+20-5)', r'-?\d+ \(\d+ vs 25\)')
self.assertRegexp('dicebot roll 3vs(10+20)', r'-?\d+, -?\d+, -?\d+ \(\d+, \d+, \d+ vs 30\)')
def testWG(self):
self.assertRegexp('dicebot roll 10#wg', r'\[pool 10\] \d+ icon\(s\): [❶❷❸❹❺❻] ([1-5➅] )*(\| Glory|\| Complication)?')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: