ram optimization

This commit is contained in:
Romain J 2021-04-21 18:28:09 +02:00
parent 4a508b1851
commit eca6e7b268
10 changed files with 23 additions and 22 deletions

View file

@ -6,6 +6,7 @@
<excludeFolder url="file://$MODULE_DIR$/dist" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
<excludeFolder url="file://$MODULE_DIR$/data" />
<excludeFolder url="file://$MODULE_DIR$/.mypy_cache" />
</content>
<orderEntry type="jdk" jdkName="Python 3.10 (tuxbot_bot)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />

View file

@ -3,7 +3,7 @@ from typing import Dict
def sort_by(_events: Counter) -> dict[str, dict]:
majors = [
majors = (
"guild",
"channel",
"message",
@ -12,7 +12,7 @@ def sort_by(_events: Counter) -> dict[str, dict]:
"presence",
"voice",
"other",
]
)
sorted_events: Dict[str, Dict] = {m: {} for m in majors}
for event, count in _events:

View file

@ -146,14 +146,14 @@ async def get_pydig_result(
def check_ip_version_or_raise(version: str) -> Union[bool, NoReturn]:
if version in ["4", "6", "None"]:
if version in ("4", "6", "None"):
return True
raise InvalidIp(_("Invalid ip version"))
def check_query_type_or_raise(query_type: str) -> Union[bool, NoReturn]:
query_types = [
query_types = (
"a",
"aaaa",
"cname",
@ -164,7 +164,7 @@ def check_query_type_or_raise(query_type: str) -> Union[bool, NoReturn]:
"txt",
"ptr",
"mx",
]
)
if query_type in query_types:
return True

View file

@ -151,7 +151,7 @@ class Network(commands.Cog):
"Unable to collect information through CloudFlare",
ctx,
self.bot.config,
).format()
)
)
@command_extra(name="getheaders", aliases=["headers"], deletable=True)

View file

@ -1,5 +1,5 @@
emotes = [chr(0x1F1E6 + i) for i in range(26)]
check = [chr(0x2714), chr(0x2716)]
check = (chr(0x2714), chr(0x2716))
def get(count):

View file

@ -1,11 +1,11 @@
from .. import __version__, version_info, VersionInfo, ExitCodes
from .config import Config, ConfigFile
__all__ = [
__all__ = (
"Config",
"ConfigFile",
"__version__",
"version_info",
"VersionInfo",
"ExitCodes",
]
)

View file

@ -3,7 +3,7 @@ import datetime
import importlib
import logging
from collections import Counter
from typing import List, Union
from typing import List, Union, Tuple
import aiohttp
import discord
@ -33,7 +33,7 @@ from . import exceptions
log = logging.getLogger("tuxbot")
packages: List[str] = [
packages: Tuple = (
"jishaku",
"tuxbot.cogs.Admin",
"tuxbot.cogs.Logs",
@ -42,7 +42,7 @@ packages: List[str] = [
"tuxbot.cogs.Polls",
"tuxbot.cogs.Custom",
"tuxbot.cogs.Network",
]
)
class Tux(commands.AutoShardedBot):
@ -81,7 +81,7 @@ class Tux(commands.AutoShardedBot):
else:
kwargs["owner_ids"] = self.config.Core.owners_id
message_cache_size = 100_000
message_cache_size = 10_000
kwargs["max_messages"] = message_cache_size
self.max_messages = message_cache_size
@ -258,7 +258,7 @@ class Tux(commands.AutoShardedBot):
if ctx is not None and ctx.valid:
if message.guild and ctx.command in search_for(
self.config.Servers, message.guild.id, "disabled_command", []
self.config.Servers, message.guild.id, "disabled_command", ()
):
raise exceptions.DisabledCommandByServerOwner

View file

@ -8,14 +8,14 @@ from structured_config import (
ConfigFile,
)
__all__ = [
__all__ = (
"Config",
"ConfigFile",
"search_for",
"set_for_key",
"set_for",
"set_if_none",
]
)
log = logging.getLogger("tuxbot.core.config")

View file

@ -1,7 +1,7 @@
import logging
import os
from pathlib import Path
from typing import Union, Dict, List, NoReturn, Any
from typing import Union, Dict, NoReturn, Any, Tuple
from babel.messages.pofile import read_po
@ -13,9 +13,9 @@ log = logging.getLogger("tuxbot.core.i18n")
_translators = []
available_locales: Dict[str, List[str]] = {
"en-US": ["english", "anglais", "en", "us", "en-us"],
"fr-FR": ["français", "francais", "french", "fr", "be", "fr-fr"],
available_locales: Dict[str, Tuple] = {
"en-US": ("english", "anglais", "en", "us", "en-us"),
"fr-FR": ("français", "francais", "french", "fr", "be", "fr-fr"),
}

View file

@ -10,7 +10,7 @@ from discord.ext.commands import (
from tuxbot.core.utils.functions.extra import ContextPlus
__all__ = [
__all__ = (
"bot_has_permissions",
"has_permissions",
"is_owner",
@ -18,7 +18,7 @@ __all__ = [
"is_admin",
"check_permissions",
"guild_owner_or_permissions",
]
)
def is_mod():