This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/coin.py

46 lines
1.2 KiB
Python
Raw Normal View History

2012-02-20 04:34:17 +01:00
# Created by Lukeroge, improved by TheNoodle
2011-11-20 10:23:31 +01:00
from util import hook
import random
2012-02-29 06:47:11 +01:00
2012-02-20 04:34:17 +01:00
# used for tails: x heads: y
def flip_simple(count):
heads = 0
tails = 0
for x in range(count):
2012-02-29 06:47:11 +01:00
c = random.randint(0, 1)
if c == 0:
heads += 1
else:
tails += 1
2012-02-29 06:47:11 +01:00
return [heads, tails]
2011-11-20 10:23:31 +01:00
@hook.command(autohelp=False)
def coin(inp):
2012-02-28 03:03:43 +01:00
".coin [amount] -- Flips [amount] of coins."
2012-02-29 06:47:11 +01:00
# checking for valid input. if valid input [count=inp],
# if invalid [return error], if no input [count=1]
if inp.isdigit():
count = int(inp)
else:
if inp:
2012-02-17 01:46:09 +01:00
return "Invalid input."
else:
count = 1
2012-02-17 01:46:09 +01:00
if count > 200:
return "Too many coins! Maximum is 200."
# depending on the count, we use two different methods to get the output
if count == 1:
2012-02-29 06:47:11 +01:00
flip = random.randint(0, 1)
if flip == 1:
sidename = "heads"
else:
sidename = "tails"
2012-02-29 06:47:11 +01:00
return "You flip a coin and get " + sidename + "."
else:
flips = flip_simple(count)
2012-02-29 06:47:11 +01:00
return "You flip %s coins and get "\
"%s heads and %s tails." % (str(count), str(flips[0]), str(flips[1]))