mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Core] Add a cli flag for setting a max size of message cache (#3474)
* Add an arg in cli to change message cache size
* Add an arg in cli to change message cache size
* Changelog
* Actually pass None in message_cache_size
* Update cli.py
* Add a cli arg to disable message cache.
* Add a cli arg to disable message cache.
* well go away you useless
* you actually are an int
* Check if message cache is higher than 0 when set it.
* Use sys.maxsize as max cache size.
* Update cli.py
* Add bot.max_messages property.
* typos
* 🤦
* style
This commit is contained in:
parent
8454239a98
commit
e44fc69d14
1
changelog.d/3474.feature.rst
Normal file
1
changelog.d/3474.feature.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add a cli flag for setting a max size of message cache
|
||||||
@ -149,6 +149,12 @@ class RedBase(
|
|||||||
if "command_not_found" not in kwargs:
|
if "command_not_found" not in kwargs:
|
||||||
kwargs["command_not_found"] = "Command {} not found.\n{}"
|
kwargs["command_not_found"] = "Command {} not found.\n{}"
|
||||||
|
|
||||||
|
message_cache_size = cli_flags.message_cache_size
|
||||||
|
if cli_flags.no_message_cache:
|
||||||
|
message_cache_size = None
|
||||||
|
kwargs["max_messages"] = message_cache_size
|
||||||
|
self._max_messages = message_cache_size
|
||||||
|
|
||||||
self._uptime = None
|
self._uptime = None
|
||||||
self._checked_time_accuracy = None
|
self._checked_time_accuracy = None
|
||||||
self._color = discord.Embed.Empty # This is needed or color ends up 0x000000
|
self._color = discord.Embed.Empty # This is needed or color ends up 0x000000
|
||||||
@ -271,6 +277,10 @@ class RedBase(
|
|||||||
def colour(self) -> NoReturn:
|
def colour(self) -> NoReturn:
|
||||||
raise AttributeError("Please fetch the embed colour with `get_embed_colour`")
|
raise AttributeError("Please fetch the embed colour with `get_embed_colour`")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_messages(self) -> Optional[int]:
|
||||||
|
return self._max_messages
|
||||||
|
|
||||||
async def allowed_by_whitelist_blacklist(
|
async def allowed_by_whitelist_blacklist(
|
||||||
self,
|
self,
|
||||||
who: Optional[Union[discord.Member, discord.User]] = None,
|
who: Optional[Union[discord.Member, discord.User]] = None,
|
||||||
|
|||||||
@ -74,6 +74,22 @@ async def interactive_config(red, token_set, prefix_set, *, print_header=True):
|
|||||||
return token
|
return token
|
||||||
|
|
||||||
|
|
||||||
|
def positive_int(arg: str) -> int:
|
||||||
|
try:
|
||||||
|
x = int(arg)
|
||||||
|
except ValueError:
|
||||||
|
raise argparse.ArgumentTypeError("Message cache size has to be a number.")
|
||||||
|
if x < 1000:
|
||||||
|
raise argparse.ArgumentTypeError(
|
||||||
|
"Message cache size has to be greater than or equal to 1000."
|
||||||
|
)
|
||||||
|
if x > sys.maxsize:
|
||||||
|
raise argparse.ArgumentTypeError(
|
||||||
|
f"Message cache size has to be lower than or equal to {sys.maxsize}."
|
||||||
|
)
|
||||||
|
return x
|
||||||
|
|
||||||
|
|
||||||
def parse_cli_flags(args):
|
def parse_cli_flags(args):
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Red - Discord Bot", usage="redbot <instance_name> [arguments]"
|
description="Red - Discord Bot", usage="redbot <instance_name> [arguments]"
|
||||||
@ -212,6 +228,15 @@ def parse_cli_flags(args):
|
|||||||
"all of the data on the host machine."
|
"all of the data on the host machine."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--message-cache-size",
|
||||||
|
type=positive_int,
|
||||||
|
default=1000,
|
||||||
|
help="Set the maximum number of messages to store in the internal message cache.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--no-message-cache", action="store_true", help="Disable the internal message cache.",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args(args)
|
args = parser.parse_args(args)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user