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:
Brian S. Stephan 2022-07-14 23:00:05 -05:00
parent 1f5dc50d89
commit 76bcdd5fef
Signed by: bss
GPG Key ID: 3DE06D3180895FCB
2 changed files with 15 additions and 6 deletions

View File

@ -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

View File

@ -149,6 +149,10 @@ BOOTSTRAP3 = {
# IRC module stuff
# dice
DICE_PREFIX_ROLLER = False
# karma
KARMA_IGNORE_CHATTER_TARGETS = []