From 7acabe1a96603ae9d7213fc082bc8a3acd6a1401 Mon Sep 17 00:00:00 2001 From: astieman Date: Mon, 11 Feb 2019 23:31:19 -0700 Subject: Readded fun.py file to evergreen and added roll command. --- bot/seasons/evergreen/fun.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 bot/seasons/evergreen/fun.py (limited to 'bot') diff --git a/bot/seasons/evergreen/fun.py b/bot/seasons/evergreen/fun.py new file mode 100644 index 00000000..ebc10fca --- /dev/null +++ b/bot/seasons/evergreen/fun.py @@ -0,0 +1,40 @@ +import logging +import random + +from discord.ext import commands + +log = logging.getLogger(__name__) + + +class Fun: + """ + A collection of general commands for fun. + """ + + def __init__(self, bot): + self.bot = bot + + @commands.command() + async def roll(self, ctx, str_input: str = None): + output = "" + + if not str_input: + output = "To use .roll, format it as such: .roll (number)" + else: + try: + num_rolls = int(str_input) + if num_rolls > 6: + num_rolls = 6 + elif num_rolls < 1: + return + for i in range(num_rolls): + output += ":terning%d: " % random.randint(1, 6) + except ValueError: + return + await ctx.send(output) + + +# Required in order to load the cog, use the class name in the add_cog function. +def setup(bot): + bot.add_cog(Fun(bot)) + log.debug("Fun cog loaded") -- cgit v1.2.3 From 03c07170279efd43ab4ac4e593db978cd0bab3ef Mon Sep 17 00:00:00 2001 From: astieman Date: Thu, 14 Feb 2019 21:32:10 -0700 Subject: Code review changes implemented. Reverted so error handling is done by base bot. --- bot/seasons/evergreen/fun.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/fun.py b/bot/seasons/evergreen/fun.py index ebc10fca..afe70462 100644 --- a/bot/seasons/evergreen/fun.py +++ b/bot/seasons/evergreen/fun.py @@ -15,22 +15,14 @@ class Fun: self.bot = bot @commands.command() - async def roll(self, ctx, str_input: str = None): + async def roll(self, ctx, num_rolls: int): output = "" - - if not str_input: - output = "To use .roll, format it as such: .roll (number)" - else: - try: - num_rolls = int(str_input) - if num_rolls > 6: - num_rolls = 6 - elif num_rolls < 1: - return - for i in range(num_rolls): - output += ":terning%d: " % random.randint(1, 6) - except ValueError: - return + if num_rolls > 6: + num_rolls = 6 + elif num_rolls < 0: + output = ":no_entry: You must roll at least once." + for _ in range(num_rolls): + output += ":terning%d: " % random.randint(1, 6) await ctx.send(output) -- cgit v1.2.3 From e915fbb58e410238451b32597cf4420b305d8a43 Mon Sep 17 00:00:00 2001 From: astieman Date: Fri, 15 Feb 2019 15:06:21 -0700 Subject: 2nd code review complete. Default roll once and warning to roll at least once implemented. --- bot/seasons/evergreen/fun.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/evergreen/fun.py b/bot/seasons/evergreen/fun.py index afe70462..b531e82f 100644 --- a/bot/seasons/evergreen/fun.py +++ b/bot/seasons/evergreen/fun.py @@ -15,11 +15,11 @@ class Fun: self.bot = bot @commands.command() - async def roll(self, ctx, num_rolls: int): + async def roll(self, ctx, num_rolls: int = 1): output = "" if num_rolls > 6: num_rolls = 6 - elif num_rolls < 0: + elif num_rolls < 1: output = ":no_entry: You must roll at least once." for _ in range(num_rolls): output += ":terning%d: " % random.randint(1, 6) -- cgit v1.2.3 From 0a7f2793a1bf594dec8a74d46fb0e3e7e1a8dc62 Mon Sep 17 00:00:00 2001 From: astieman Date: Sat, 16 Feb 2019 11:39:47 -0700 Subject: 3rd code review. Added docstring. --- bot/seasons/evergreen/fun.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bot') diff --git a/bot/seasons/evergreen/fun.py b/bot/seasons/evergreen/fun.py index b531e82f..afe37b75 100644 --- a/bot/seasons/evergreen/fun.py +++ b/bot/seasons/evergreen/fun.py @@ -16,6 +16,9 @@ class Fun: @commands.command() async def roll(self, ctx, num_rolls: int = 1): + """ + Outputs a number of random dice emotes (up to 6) + """ output = "" if num_rolls > 6: num_rolls = 6 -- cgit v1.2.3