construct the lex/yacc dice roller in the package
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
"""Initialize the dice roller."""
|
||||
from dice.roller import DiceRoller
|
||||
|
||||
dice_roller = DiceRoller()
|
||||
|
||||
+3
-4
@@ -5,8 +5,8 @@ import random
|
||||
from django.conf import settings
|
||||
from irc.client import NickMask
|
||||
|
||||
from dice import dice_roller
|
||||
from dice.lib import reaction_roll
|
||||
from dice.roller import DiceRoller
|
||||
from ircbot.lib import Plugin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -19,8 +19,7 @@ class Dice(Plugin):
|
||||
|
||||
def __init__(self, bot, connection, event):
|
||||
"""Set up the plugin."""
|
||||
self.roller = DiceRoller(ircify=True)
|
||||
|
||||
dice_roller.ircify = True
|
||||
super(Dice, self).__init__(bot, connection, event)
|
||||
|
||||
def start(self):
|
||||
@@ -81,7 +80,7 @@ class Dice(Plugin):
|
||||
|
||||
logger.debug(event.recursing)
|
||||
try:
|
||||
reply_str = self.roller.do_roll(dicestr)
|
||||
reply_str = dice_roller.do_roll(dicestr)
|
||||
except AssertionError as aex:
|
||||
reply_str = f"Could not roll dice: {aex}"
|
||||
except ValueError:
|
||||
|
||||
+3
-4
@@ -4,14 +4,13 @@ import logging
|
||||
|
||||
from django.shortcuts import render
|
||||
from rest_framework.authentication import BasicAuthentication
|
||||
from rest_framework.decorators import api_view, authentication_classes, permission_classes
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.decorators import api_view, authentication_classes, permission_classes
|
||||
|
||||
from dice.roller import DiceRoller
|
||||
from dice import dice_roller
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
roller = DiceRoller()
|
||||
|
||||
|
||||
def index(request):
|
||||
@@ -34,7 +33,7 @@ def rpc_roll_dice(request):
|
||||
return Response({'detail': "Request must be JSON with a 'dice' parameter."}, status=400)
|
||||
|
||||
try:
|
||||
result_str = roller.do_roll(dice_str)
|
||||
result_str = dice_roller.do_roll(dice_str)
|
||||
return Response({'dice': dice_str, 'result': result_str})
|
||||
except AssertionError as aex:
|
||||
return Response({'detail': f"Could not roll dice: {aex}", 'dice': dice_str}, status=400)
|
||||
|
||||
@@ -3,7 +3,7 @@ from unittest import mock
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
import dice.roller
|
||||
from dice import dice_roller
|
||||
|
||||
|
||||
class DiceRollerTestCase(TestCase):
|
||||
@@ -11,7 +11,8 @@ class DiceRollerTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""Create the dice roller."""
|
||||
self.roller = dice.roller.DiceRoller()
|
||||
self.roller = dice_roller
|
||||
self.roller.ircify = False
|
||||
|
||||
def test_standard_rolls(self):
|
||||
"""Roll a variety of normal rolls."""
|
||||
|
||||
Reference in New Issue
Block a user