[General] Max amount to roll (#3395)

* [General] Rolls max amount

Adds max amount to roll.

* Removed redundant code.

* QA changes

* Add typehinting.
This commit is contained in:
Stonedestroyer 2020-01-20 22:49:46 +01:00 committed by Michael H
parent 7f390df879
commit b085c1501f
2 changed files with 13 additions and 2 deletions

View File

@ -0,0 +1 @@
[General] Adds a maximum amount to roll command.

View File

@ -2,6 +2,7 @@ import datetime
import time import time
from enum import Enum from enum import Enum
from random import randint, choice from random import randint, choice
from typing import Final
import aiohttp import aiohttp
import discord import discord
from redbot.core import commands from redbot.core import commands
@ -31,6 +32,9 @@ class RPSParser:
self.choice = None self.choice = None
MAX_ROLL: Final[int] = 2 ** 64 - 1
@cog_i18n(_) @cog_i18n(_)
class General(commands.Cog): class General(commands.Cog):
"""General commands.""" """General commands."""
@ -87,15 +91,21 @@ class General(commands.Cog):
`<number>` defaults to 100. `<number>` defaults to 100.
""" """
author = ctx.author author = ctx.author
if number > 1: if 1 < number <= MAX_ROLL:
n = randint(1, number) n = randint(1, number)
await ctx.send( await ctx.send(
"{author.mention} :game_die: {n} :game_die:".format( "{author.mention} :game_die: {n} :game_die:".format(
author=author, n=humanize_number(n) author=author, n=humanize_number(n)
) )
) )
else: elif number <= 1:
await ctx.send(_("{author.mention} Maybe higher than 1? ;P").format(author=author)) await ctx.send(_("{author.mention} Maybe higher than 1? ;P").format(author=author))
else:
await ctx.send(
_("{author.mention} Max allowed number is {maxamount}.").format(
author=author, maxamount=humanize_number(MAX_ROLL)
)
)
@commands.command() @commands.command()
async def flip(self, ctx, user: discord.Member = None): async def flip(self, ctx, user: discord.Member = None):