diff --git a/tuxbot/__main__.py b/tuxbot/__main__.py index 6e03d70..65f8f24 100644 --- a/tuxbot/__main__.py +++ b/tuxbot/__main__.py @@ -161,7 +161,7 @@ async def shutdown_handler(tux: Tux, signal_type, exit_code=None) -> NoReturn: await asyncio.gather(*pending, return_exceptions=True) -async def run_bot(tux: Tux, cli_flags: Namespace, loop) -> None: +async def run_bot(tux: Tux, cli_flags: Namespace) -> None: """This run the bot. Parameters @@ -238,7 +238,7 @@ def main() -> NoReturn: dm_help=None ) - loop.run_until_complete(run_bot(tux, cli_flags, loop)) + loop.run_until_complete(run_bot(tux, cli_flags)) except KeyboardInterrupt: print(Fore.RED + "Please use quit instead of Ctrl+C to Shutdown!" diff --git a/tuxbot/cogs/anti_raid/__init__.py b/tuxbot/cogs/anti_raid/__init__.py new file mode 100644 index 0000000..e561a6c --- /dev/null +++ b/tuxbot/cogs/anti_raid/__init__.py @@ -0,0 +1,6 @@ +from .anti_raid import Warnings +from ...core.bot import Tux + + +def setup(bot: Tux): + bot.add_cog(Warnings(bot)) diff --git a/tuxbot/cogs/anti_raid/anti_raid.py b/tuxbot/cogs/anti_raid/anti_raid.py new file mode 100644 index 0000000..b1a986c --- /dev/null +++ b/tuxbot/cogs/anti_raid/anti_raid.py @@ -0,0 +1,24 @@ +import logging + +from discord.ext import commands + +from tuxbot.core import checks +from tuxbot.core.bot import Tux +from tuxbot.core.i18n import Translator + +log = logging.getLogger("tuxbot.cogs.anti_raid") +T_ = Translator("AntiRaid", __file__) + + +class AntiRaid(commands.Cog, name="AntiRaid"): + def __init__(self, bot: Tux): + self.bot = bot + + @commands.group( + name='anti_raid', + alias=['anti-raid', 'raid_protect', 'raid-protect', 'no_raid', 'no-raid'] + ) + @commands.guild_only() + @checks.is_admin() + async def _warn(self, ctx: commands.Context): + pass diff --git a/tuxbot/core/bot.py b/tuxbot/core/bot.py index f89170d..a45c146 100644 --- a/tuxbot/core/bot.py +++ b/tuxbot/core/bot.py @@ -101,6 +101,7 @@ class Tux(commands.AutoShardedBot): f"Language: {self.config('core').get('locale')}", f"Tuxbot Version: {__version__}", f"Discord.py Version: {discord.__version__}", + "Python Version: " + sys.version.replace('\n', ''), f"Shards: {self.shard_count}", f"Servers: {len(self.guilds)}", f"Users: {len(self.users)}" diff --git a/tuxbot/core/i18n.py b/tuxbot/core/i18n.py new file mode 100644 index 0000000..09f3977 --- /dev/null +++ b/tuxbot/core/i18n.py @@ -0,0 +1,70 @@ +import os +from pathlib import Path +from typing import Callable, Union, Dict + +__all__ = [ + "get_locale", + "set_locale", + "reload_locales", + "Translator", +] + +_translators = [] +_current_locale = "en-US" + + +def get_locale() -> str: + return _current_locale + + +def set_locale(locale: str) -> None: + global _current_locale + _current_locale = locale + reload_locales() + + +def reload_locales() -> None: + for translator in _translators: + translator.load_translations() + + +class Translator(Callable[[str], str]): + """Class to load locales at init.""" + + def __init__(self, name: str, file_location: Union[str, Path, os.PathLike]): + """Initializes the Translator object. + + Parameters + ---------- + name : str + The cog name. + file_location:str|Path|os.PathLike + File path for the required extension. + + """ + self.cog_folder = Path(file_location).resolve().parent + self.cog_name = name + self.translations = {} + + _translators.append(self) + + self.load_translations() + + def __call__(self, untranslated: str) -> str: + try: + return self.translations[untranslated] + except KeyError: + return untranslated + + def load_translations(self): + """Loads the current translations. + + """ + self.translations = {} + locale_path = self.cog_folder / "locales" / f"{get_locale()}.po" + + ... + + def _add_translation(self, untranslated, translated): + if translated: + self.translations[untranslated] = translated diff --git a/tuxbot/core/utils/functions/extra.py b/tuxbot/core/utils/functions/extra.py index 157fa7e..eb26d81 100644 --- a/tuxbot/core/utils/functions/extra.py +++ b/tuxbot/core/utils/functions/extra.py @@ -6,7 +6,8 @@ from discord.ext import commands, flags class ContextPlus(commands.Context): async def send(self, content=None, *args, **kwargs): - if (hasattr(self.command, 'deletable') and self.command.deletable) \ + if (hasattr(self.command, 'deletable') + and self.command.deletable) \ and kwargs.pop('deletable', True): message = await super().send(content, *args, **kwargs) await message.add_reaction('🗑') diff --git a/tuxbot/logging.py b/tuxbot/logging.py index 2013c0f..d502d5f 100644 --- a/tuxbot/logging.py +++ b/tuxbot/logging.py @@ -42,5 +42,9 @@ def init_logging(level: int, location: pathlib.Path) -> None: stdout_handler = logging.StreamHandler(sys.stdout) stdout_handler.setFormatter(formatter) + + dpy_handler.setFormatter(formatter) + base_handler.setFormatter(formatter) + dpy_logger.addHandler(dpy_handler) base_logger.addHandler(base_handler)