Skip to content

Instantly share code, notes, and snippets.

@Ungsik-Yun
Created February 29, 2016 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ungsik-Yun/6abf5b06798a114e04b7 to your computer and use it in GitHub Desktop.
Save Ungsik-Yun/6abf5b06798a114e04b7 to your computer and use it in GitHub Desktop.
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