dice: don't address roller when recursing

allows !echo blah [!random foo bar] to reply with "blah bar" rather
than "blah bss: bar", for example
This commit is contained in:
Brian S. Stephan 2017-03-02 09:40:23 -06:00
parent 44c8863d35
commit 936db45359
1 changed files with 14 additions and 2 deletions

View File

@ -3,6 +3,7 @@
# this breaks yacc, but ply might be happy in py3
#from __future__ import unicode_literals
import logging
import math
import re
import random
@ -14,6 +15,9 @@ import ply.yacc as yacc
from ircbot.lib import Plugin
logger = logging.getLogger(__name__)
class Dice(Plugin):
"""Roll simple or complex dice strings."""
@ -50,7 +54,11 @@ class Dice(Plugin):
choices_list = choices.split(' ')
choice = random.choice(choices_list)
reply = "{0:s}: {1:s}".format(nick, choice)
logger.debug(event._recursing)
if event._recursing:
reply = "{0:s}".format(choice)
else:
reply = "{0:s}: {1:s}".format(nick, choice)
return self.bot.reply(event, reply)
def handle_roll(self, connection, event, match):
@ -59,7 +67,11 @@ class Dice(Plugin):
nick = NickMask(event.source).nick
dicestr = match.group(1)
reply = "{0:s}: {1:s}".format(nick, self.roller.do_roll(dicestr))
logger.debug(event._recursing)
if event._recursing:
reply = "{0:s}".format(self.roller.do_roll(dicestr))
else:
reply = "{0:s}: {1:s}".format(nick, self.roller.do_roll(dicestr))
return self.bot.reply(event, re.sub(r'(\d+)(.*?\s+)(\(.*?\))', r'\1\214\3', reply))
def handle_ctech(self, connection, event, match):