diff --git a/cogs/Help.py b/cogs/Help.py index 8f64ce5..2cba362 100644 --- a/cogs/Help.py +++ b/cogs/Help.py @@ -7,7 +7,7 @@ from discord.ext import commands from bot import TuxBot from utils import Texts, GroupPlus -from utils.paginator import FieldPages +from utils import FieldPages log = logging.getLogger(__name__) diff --git a/cogs/Polls.py b/cogs/Polls.py index 23bab84..1fb9c2d 100644 --- a/cogs/Polls.py +++ b/cogs/Polls.py @@ -8,7 +8,8 @@ from yarl import URL from bot import TuxBot from utils import PollModel, ResponsesModel -from utils import Texts, emotes as utils_emotes +from utils import Texts +from utils.functions import emotes as utils_emotes from utils import groupExtra log = logging.getLogger(__name__) diff --git a/cogs/Useful.py b/cogs/Useful.py index 5d469eb..3436ec2 100644 --- a/cogs/Useful.py +++ b/cogs/Useful.py @@ -1,9 +1,9 @@ # Created by romain at 04/01/2020 - import logging import os import pathlib import platform +import random import re import socket import time @@ -18,7 +18,7 @@ from tcp_latency import measure_latency from bot import TuxBot from utils import Texts -from utils import commandExtra +from utils import commandExtra, groupExtra log = logging.getLogger(__name__) @@ -66,6 +66,19 @@ class Useful(commands.Cog): return (file_amount, total_lines), ( python_file_amount, total_python_lines) + @staticmethod + def luhn_checker(number: int): + digits = [int(x) for x in reversed(str(number))] + + for index, digit in enumerate(digits, start=1): + digit = digit * 2 if index % 2 == 0 else digit + if digit >= 10: + digit = sum(int(x) for x in list(str(digit))) + + digits[index - 1] = digit + + return sum(digits) % 10 == 0 + ########################################################################### @commandExtra(name='iplocalise', category='network', @@ -339,6 +352,43 @@ class Useful(commands.Cog): await ctx.send(embed=e) + ########################################################################### + @groupExtra(name='cb', aliases=['cc'], + category='misc', + description=Texts('useful_help').get('_cb'), + help=Texts('useful_help').get('_cb__short')) + async def _cb(self, ctx: commands.Context): + if ctx.invoked_subcommand is None: + await ctx.send_help('cb') + + @_cb.command(name='validate', aliases=['valid', 'correct'], + category='misc', + description=Texts('useful_help').get('_cb_validate'), + help=Texts('useful_help').get('_cb_validate__short')) + async def _cb_validate(self, ctx: commands.Context, *, number: int): + valid = self.luhn_checker(number) + + await ctx.send( + Texts( + 'useful', ctx + ).get( + 'valid_credit_card' + if valid + else 'invalid_credit_card' + ) + ) + + @_cb.command(name='generate', aliases=['new', 'get'], + category='misc', + description=Texts('useful_help').get('_cb_generate'), + help=Texts('useful_help').get('_cb_generate__short')) + async def _cb_generate(self, ctx: commands.Context): + number = random.randint(4000_0000_0000_0000, 5999_9999_9999_9999) + while not self.luhn_checker(number): + number = random.randint(4000_0000_0000_0000, 5999_9999_9999_9999) + + await ctx.send(''.join(str(digit) for digit in str(number))) + def setup(bot: TuxBot): bot.add_cog(Useful(bot)) diff --git a/extras/locales/en/LC_MESSAGES/admin.mo b/extras/locales/en/LC_MESSAGES/admin.mo deleted file mode 100644 index cd65b5e..0000000 Binary files a/extras/locales/en/LC_MESSAGES/admin.mo and /dev/null differ diff --git a/extras/locales/en/LC_MESSAGES/base.mo b/extras/locales/en/LC_MESSAGES/base.mo deleted file mode 100644 index e56e9c9..0000000 Binary files a/extras/locales/en/LC_MESSAGES/base.mo and /dev/null differ diff --git a/extras/locales/en/LC_MESSAGES/poll.mo b/extras/locales/en/LC_MESSAGES/poll.mo deleted file mode 100644 index e56e9c9..0000000 Binary files a/extras/locales/en/LC_MESSAGES/poll.mo and /dev/null differ diff --git a/extras/locales/en/LC_MESSAGES/utils.mo b/extras/locales/en/LC_MESSAGES/utils.mo deleted file mode 100644 index e56e9c9..0000000 Binary files a/extras/locales/en/LC_MESSAGES/utils.mo and /dev/null differ diff --git a/extras/locales/fr/LC_MESSAGES/admin.mo b/extras/locales/fr/LC_MESSAGES/admin.mo deleted file mode 100644 index ea26574..0000000 Binary files a/extras/locales/fr/LC_MESSAGES/admin.mo and /dev/null differ diff --git a/extras/locales/fr/LC_MESSAGES/base.mo b/extras/locales/fr/LC_MESSAGES/base.mo deleted file mode 100644 index b967b85..0000000 Binary files a/extras/locales/fr/LC_MESSAGES/base.mo and /dev/null differ diff --git a/extras/locales/fr/LC_MESSAGES/poll.mo b/extras/locales/fr/LC_MESSAGES/poll.mo deleted file mode 100644 index 41187c1..0000000 Binary files a/extras/locales/fr/LC_MESSAGES/poll.mo and /dev/null differ diff --git a/extras/locales/fr/LC_MESSAGES/utils.mo b/extras/locales/fr/LC_MESSAGES/utils.mo deleted file mode 100644 index 332a6c2..0000000 Binary files a/extras/locales/fr/LC_MESSAGES/utils.mo and /dev/null differ diff --git a/generate_locales.sh b/generate_locales.sh index ee2ad88..78be2cd 100755 --- a/generate_locales.sh +++ b/generate_locales.sh @@ -2,14 +2,14 @@ BASEDIR=$(pwd) -cd "$BASEDIR/extras/locales/en/LC_MESSAGES" +cd "$BASEDIR/utils/locales/en/LC_MESSAGES" for i in *.po ; do [[ -f "$i" ]] || continue /usr/lib/python3.8/Tools/i18n/msgfmt.py -o "${i%.po}.mo" "${i%.po}" done -cd "$BASEDIR/extras/locales/fr/LC_MESSAGES" +cd "$BASEDIR/utils/locales/fr/LC_MESSAGES" for i in *.po ; do [[ -f "$i" ]] || continue diff --git a/utils/__init__.py b/utils/__init__.py index 9335559..a60b691 100755 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -1,9 +1,8 @@ -from .database import Database from .models import * -from .config import * -from .lang import * -from .version import * +from utils.functions.config import * +from utils.functions.lang import * +from utils.functions.version import * -from .extra import * -from .paginator import * +from utils.functions.extra import * +from utils.functions.paginator import * diff --git a/extras/locales/en/LC_MESSAGES/user.po b/utils/functions/__init__.py similarity index 100% rename from extras/locales/en/LC_MESSAGES/user.po rename to utils/functions/__init__.py diff --git a/utils/config.py b/utils/functions/config.py similarity index 100% rename from utils/config.py rename to utils/functions/config.py diff --git a/utils/database.py b/utils/functions/database.py similarity index 100% rename from utils/database.py rename to utils/functions/database.py diff --git a/utils/emotes.py b/utils/functions/emotes.py similarity index 100% rename from utils/emotes.py rename to utils/functions/emotes.py diff --git a/utils/extra.py b/utils/functions/extra.py similarity index 100% rename from utils/extra.py rename to utils/functions/extra.py diff --git a/utils/lang.py b/utils/functions/lang.py similarity index 86% rename from utils/lang.py rename to utils/functions/lang.py index 1a21062..4be303b 100644 --- a/utils/lang.py +++ b/utils/functions/lang.py @@ -1,8 +1,8 @@ import gettext from .config import Config -from utils import Database +from .database import Database -from .models.lang import LangModel +from utils.models.lang import LangModel from discord.ext import commands @@ -12,7 +12,7 @@ class Texts: self.base = base def get(self, text: str) -> str: - texts = gettext.translation(self.base, localedir='extras/locales', + texts = gettext.translation(self.base, localedir='utils/locales', languages=[self.locale]) texts.install() return texts.gettext(text) diff --git a/utils/paginator.py b/utils/functions/paginator.py similarity index 100% rename from utils/paginator.py rename to utils/functions/paginator.py diff --git a/utils/version.py b/utils/functions/version.py similarity index 100% rename from utils/version.py rename to utils/functions/version.py diff --git a/extras/locales/en/LC_MESSAGES/admin.po b/utils/locales/en/LC_MESSAGES/admin.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/admin.po rename to utils/locales/en/LC_MESSAGES/admin.po diff --git a/extras/locales/en/LC_MESSAGES/admin_help.po b/utils/locales/en/LC_MESSAGES/admin_help.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/admin_help.po rename to utils/locales/en/LC_MESSAGES/admin_help.po diff --git a/extras/locales/en/LC_MESSAGES/base.po b/utils/locales/en/LC_MESSAGES/base.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/base.po rename to utils/locales/en/LC_MESSAGES/base.po diff --git a/extras/locales/en/LC_MESSAGES/help.po b/utils/locales/en/LC_MESSAGES/help.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/help.po rename to utils/locales/en/LC_MESSAGES/help.po diff --git a/extras/locales/en/LC_MESSAGES/logs.po b/utils/locales/en/LC_MESSAGES/logs.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/logs.po rename to utils/locales/en/LC_MESSAGES/logs.po diff --git a/extras/locales/en/LC_MESSAGES/poll.po b/utils/locales/en/LC_MESSAGES/poll.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/poll.po rename to utils/locales/en/LC_MESSAGES/poll.po diff --git a/extras/locales/en/LC_MESSAGES/poll_help.po b/utils/locales/en/LC_MESSAGES/poll_help.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/poll_help.po rename to utils/locales/en/LC_MESSAGES/poll_help.po diff --git a/extras/locales/en/LC_MESSAGES/useful.po b/utils/locales/en/LC_MESSAGES/useful.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/useful.po rename to utils/locales/en/LC_MESSAGES/useful.po diff --git a/extras/locales/en/LC_MESSAGES/useful_help.po b/utils/locales/en/LC_MESSAGES/useful_help.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/useful_help.po rename to utils/locales/en/LC_MESSAGES/useful_help.po diff --git a/extras/locales/fr/LC_MESSAGES/user.po b/utils/locales/en/LC_MESSAGES/user.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/user.po rename to utils/locales/en/LC_MESSAGES/user.po diff --git a/extras/locales/en/LC_MESSAGES/user_help.po b/utils/locales/en/LC_MESSAGES/user_help.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/user_help.po rename to utils/locales/en/LC_MESSAGES/user_help.po diff --git a/extras/locales/en/LC_MESSAGES/utils.po b/utils/locales/en/LC_MESSAGES/utils.po similarity index 100% rename from extras/locales/en/LC_MESSAGES/utils.po rename to utils/locales/en/LC_MESSAGES/utils.po diff --git a/extras/locales/fr/LC_MESSAGES/admin.po b/utils/locales/fr/LC_MESSAGES/admin.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/admin.po rename to utils/locales/fr/LC_MESSAGES/admin.po diff --git a/extras/locales/fr/LC_MESSAGES/admin_help.po b/utils/locales/fr/LC_MESSAGES/admin_help.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/admin_help.po rename to utils/locales/fr/LC_MESSAGES/admin_help.po diff --git a/extras/locales/fr/LC_MESSAGES/base.po b/utils/locales/fr/LC_MESSAGES/base.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/base.po rename to utils/locales/fr/LC_MESSAGES/base.po diff --git a/extras/locales/fr/LC_MESSAGES/help.po b/utils/locales/fr/LC_MESSAGES/help.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/help.po rename to utils/locales/fr/LC_MESSAGES/help.po diff --git a/extras/locales/fr/LC_MESSAGES/logs.po b/utils/locales/fr/LC_MESSAGES/logs.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/logs.po rename to utils/locales/fr/LC_MESSAGES/logs.po diff --git a/extras/locales/fr/LC_MESSAGES/logs_help.po b/utils/locales/fr/LC_MESSAGES/logs_help.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/logs_help.po rename to utils/locales/fr/LC_MESSAGES/logs_help.po diff --git a/extras/locales/fr/LC_MESSAGES/poll.po b/utils/locales/fr/LC_MESSAGES/poll.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/poll.po rename to utils/locales/fr/LC_MESSAGES/poll.po diff --git a/extras/locales/fr/LC_MESSAGES/poll_help.po b/utils/locales/fr/LC_MESSAGES/poll_help.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/poll_help.po rename to utils/locales/fr/LC_MESSAGES/poll_help.po diff --git a/extras/locales/fr/LC_MESSAGES/useful.po b/utils/locales/fr/LC_MESSAGES/useful.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/useful.po rename to utils/locales/fr/LC_MESSAGES/useful.po diff --git a/extras/locales/fr/LC_MESSAGES/useful_help.po b/utils/locales/fr/LC_MESSAGES/useful_help.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/useful_help.po rename to utils/locales/fr/LC_MESSAGES/useful_help.po diff --git a/utils/locales/fr/LC_MESSAGES/user.po b/utils/locales/fr/LC_MESSAGES/user.po new file mode 100644 index 0000000..e69de29 diff --git a/extras/locales/fr/LC_MESSAGES/user_help.po b/utils/locales/fr/LC_MESSAGES/user_help.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/user_help.po rename to utils/locales/fr/LC_MESSAGES/user_help.po diff --git a/extras/locales/fr/LC_MESSAGES/utils.po b/utils/locales/fr/LC_MESSAGES/utils.po similarity index 100% rename from extras/locales/fr/LC_MESSAGES/utils.po rename to utils/locales/fr/LC_MESSAGES/utils.po