Created
December 17, 2012 21:44
-
-
Save brunobord/4322573 to your computer and use it in GitHub Desktop.
rôliste bot : a bot that can roll dice.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*- coding: utf8 -*- | |
import random | |
import logging | |
from cmdbot.core import Bot | |
from cmdbot.decorators import no_verb, regex | |
from cmdbot.core import logger | |
from cmdbot.configs import ArgumentConfiguration | |
logger.setLevel(logging.DEBUG) | |
class Roliste(Bot): | |
welcome_message = "Salut les rôleux !" | |
config_class = ArgumentConfiguration | |
@no_verb | |
@regex(r'^(\d+)?d(\d+)([\+\-])?(\d+)?$') | |
def do_roll(self, line, match): | |
"Roll dice. ex: 2d6, d20, 3d6+2,..." | |
nb_dice, faces, sign, factor = match.groups() | |
if nb_dice is None: | |
nb_dice = 1 | |
dices = [random.randint(1, long(faces)) for x in xrange(0, long(nb_dice))] | |
score = sum(dices) | |
if sign == '+': | |
score += long(factor) | |
elif sign == '-': | |
score -= long(factor) | |
summary = '' | |
if nb_dice > 1: | |
summary = ' (%s)' % ', '.join(unicode(dice) for dice in dices) | |
self.reply('score: %d%s' % (score, summary), line=line) | |
if __name__ == '__main__': | |
b = Roliste() | |
b.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment