mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
[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:
parent
7f390df879
commit
b085c1501f
1
changelog.d/general/3284.bugfix.rst
Normal file
1
changelog.d/general/3284.bugfix.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
[General] Adds a maximum amount to roll command.
|
||||||
@ -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):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user