Created
February 29, 2016 10:10
-
-
Save Ungsik-Yun/6abf5b06798a114e04b7 to your computer and use it in GitHub Desktop.
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
from slackbot.bot import respond_to | |
from slackbot.bot import listen_to | |
import re | |
import random | |
@listen_to("!주사위 (\d*)d(\d+)", re.IGNORECASE) | |
@listen_to("!roll (\d*)d(\d+)", re.IGNORECASE) | |
def roll_dice(msg, num_of_dice=1, die=6): | |
if die == '': | |
die = 6 | |
else: | |
die = int(die) | |
if num_of_dice == '': | |
num_of_dice = 1 | |
else: | |
num_of_dice = int(num_of_dice) | |
msg.reply("%d 면체를 %d 개 굴림 " % (die, num_of_dice)) | |
roll_result = [random.randrange(1, die, 1) for i in range(num_of_dice)] | |
roll_sum = sum(roll_result) | |
msg.reply("굴림: %s\n합계: %d\n평균: %.2f" % (roll_result, roll_sum, float(roll_sum)/float(len(roll_result)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment