config flag for having !dice/!random prefix the nick
with the discord-irc bridge in play, the bot was sending all !roll results to the bridge user, which wasn't all that useful
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
"""Roll dice when asked, intended for RPGs."""
|
||||
import logging
|
||||
import re
|
||||
import random
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from irc.client import NickMask
|
||||
|
||||
@@ -38,23 +40,23 @@ class Dice(Plugin):
|
||||
|
||||
def handle_random(self, connection, event, match):
|
||||
"""Handle the !random command which picks an item from a list."""
|
||||
|
||||
nick = NickMask(event.source).nick
|
||||
choices = match.group(1)
|
||||
|
||||
choices_list = choices.split(' ')
|
||||
choice = random.choice(choices_list)
|
||||
choice = random.SystemRandom().choice(choices_list)
|
||||
|
||||
logger.debug(event.recursing)
|
||||
if event.recursing:
|
||||
reply = "{0:s}".format(choice)
|
||||
else:
|
||||
elif settings.DICE_PREFIX_ROLLER:
|
||||
reply = "{0:s}: {1:s}".format(nick, choice)
|
||||
else:
|
||||
reply = "{0:s}".format(choice)
|
||||
return self.bot.reply(event, reply)
|
||||
|
||||
def handle_roll(self, connection, event, match):
|
||||
"""Handle the !roll command which covers most common dice stuff."""
|
||||
|
||||
nick = NickMask(event.source).nick
|
||||
dicestr = match.group(1)
|
||||
|
||||
@@ -68,8 +70,11 @@ class Dice(Plugin):
|
||||
|
||||
if event.recursing:
|
||||
reply = "{0:s}".format(reply_str)
|
||||
else:
|
||||
elif settings.DICE_PREFIX_ROLLER:
|
||||
reply = "{0:s}: {1:s}".format(nick, reply_str)
|
||||
else:
|
||||
reply = "{0:s}".format(reply_str)
|
||||
return self.bot.reply(event, re.sub(r'(\d+)(.*?\s+)(\(.*?\))', r'\1\214\3', reply))
|
||||
|
||||
|
||||
plugin = Dice
|
||||
|
||||
Reference in New Issue
Block a user