plug the cypher system roller into the irc plugin
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
@@ -7,11 +7,15 @@ from django.conf import settings
|
||||
|
||||
from irc.client import NickMask
|
||||
|
||||
from dice.lib import cypher_roll
|
||||
from dice.roller import DiceRoller
|
||||
from ircbot.lib import Plugin
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
CYPHER_ROLL_REGEX = r'(T(?P<difficulty>\d+))?(?P<mods>(?:\s*(-|\+)\d+)*)\s*(?P<comment>.*)?'
|
||||
CYPHER_COMMAND_REGEX = r'^!cypher\s+(' + CYPHER_ROLL_REGEX + ')'
|
||||
|
||||
|
||||
class Dice(Plugin):
|
||||
"""Roll simple or complex dice strings."""
|
||||
@@ -24,6 +28,8 @@ class Dice(Plugin):
|
||||
|
||||
def start(self):
|
||||
"""Set up the handlers."""
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], CYPHER_COMMAND_REGEX,
|
||||
self.handle_cypher_roll, -20)
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!roll\s+(.*)$',
|
||||
self.handle_roll, -20)
|
||||
self.connection.reactor.add_global_regex_handler(['pubmsg', 'privmsg'], r'^!random\s+(.*)$',
|
||||
@@ -38,6 +44,45 @@ class Dice(Plugin):
|
||||
|
||||
super(Dice, self).stop()
|
||||
|
||||
def handle_cypher_roll(self, connection, event, match):
|
||||
"""Handle the !cypher roll."""
|
||||
nick = NickMask(event.source).nick
|
||||
task = match.group(1)
|
||||
|
||||
task_group = re.search(CYPHER_ROLL_REGEX, task)
|
||||
difficulty = int(task_group.group('difficulty')) if task_group.group('difficulty') else None
|
||||
mods = task_group.group('mods')
|
||||
comment = task_group.group('comment')
|
||||
result, beats, success, effect = cypher_roll(difficulty=difficulty, mods=mods)
|
||||
|
||||
if success is not None:
|
||||
if success:
|
||||
if effect:
|
||||
result_str = f"9succeeded, with {effect}!"
|
||||
else:
|
||||
result_str = "9succeeded!"
|
||||
else:
|
||||
if effect:
|
||||
result_str = f"4failed, with {effect}!"
|
||||
else:
|
||||
result_str = "4failed."
|
||||
else:
|
||||
if effect:
|
||||
result_str = f"beats a difficulty {beats} task, with {effect}!"
|
||||
else:
|
||||
result_str = f"beats a difficulty {beats} task."
|
||||
|
||||
if success is not None:
|
||||
# show the adjusted difficulty
|
||||
detail_str = f"14(d20={result} vs. diff. {difficulty}{mods})"
|
||||
else:
|
||||
detail_str = f"14(d20={result} with {mods} levels)"
|
||||
|
||||
if comment:
|
||||
return self.bot.reply(event, f"{nick}: {comment} {result_str} {detail_str}")
|
||||
else:
|
||||
return self.bot.reply(event, f"{nick}: your check {result_str} {detail_str}")
|
||||
|
||||
def handle_random(self, connection, event, match):
|
||||
"""Handle the !random command which picks an item from a list."""
|
||||
nick = NickMask(event.source).nick
|
||||
|
||||
Reference in New Issue
Block a user