diff --git a/.idea/dictionaries/romain.xml b/.idea/dictionaries/romain.xml index 4def97a..698fc82 100644 --- a/.idea/dictionaries/romain.xml +++ b/.idea/dictionaries/romain.xml @@ -2,6 +2,7 @@ <dictionary name="romain"> <words> <w>anglais</w> + <w>anonyme</w> <w>appdirs</w> <w>apres</w> <w>asctime</w> @@ -30,6 +31,8 @@ <w>rprint</w> <w>socketstats</w> <w>soit</w> + <w>sondage</w> + <w>sondages</w> <w>splt</w> <w>suivante</w> <w>systemd</w> diff --git a/tuxbot/cogs/Admin/locales/messages.pot b/tuxbot/cogs/Admin/locales/messages.pot index 78bd0bf..f2b176e 100644 --- a/tuxbot/cogs/Admin/locales/messages.pot +++ b/tuxbot/cogs/Admin/locales/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Tuxbot-bot\n" "Report-Msgid-Bugs-To: rick@gnous.eu\n" -"POT-Creation-Date: 2020-11-11 02:44+0100\n" +"POT-Creation-Date: 2020-11-11 16:42+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" diff --git a/tuxbot/cogs/Admin/models/__init__.py b/tuxbot/cogs/Admin/models/__init__.py index f21a8b3..7b6f395 100644 --- a/tuxbot/cogs/Admin/models/__init__.py +++ b/tuxbot/cogs/Admin/models/__init__.py @@ -1,2 +1,2 @@ from .alias import * -from .warn import * +from .warns import * diff --git a/tuxbot/cogs/Admin/models/alias.py b/tuxbot/cogs/Admin/models/alias.py index bc1ba53..2ba0073 100644 --- a/tuxbot/cogs/Admin/models/alias.py +++ b/tuxbot/cogs/Admin/models/alias.py @@ -2,7 +2,7 @@ import tortoise from tortoise import fields -class AliasesModel(tortoise.Model): +class Alias(tortoise.Model): id = fields.BigIntField(pk=True) user_id = fields.BigIntField() alias = fields.TextField(max_length=255) @@ -14,7 +14,7 @@ class AliasesModel(tortoise.Model): def __str__(self): return ( - f"<AliasesModel id={self.id} " + f"<Alias id={self.id} " f"user_id={self.user_id} " f"alias='{self.alias}' " f"command='{self.command}' " diff --git a/tuxbot/cogs/Admin/models/warn.py b/tuxbot/cogs/Admin/models/warns.py similarity index 87% rename from tuxbot/cogs/Admin/models/warn.py rename to tuxbot/cogs/Admin/models/warns.py index 6e54edd..4bda9fc 100644 --- a/tuxbot/cogs/Admin/models/warn.py +++ b/tuxbot/cogs/Admin/models/warns.py @@ -2,7 +2,7 @@ import tortoise from tortoise import fields -class WarnsModel(tortoise.Model): +class Warn(tortoise.Model): id = fields.BigIntField(pk=True) server_id = fields.BigIntField() user_id = fields.BigIntField() @@ -14,7 +14,7 @@ class WarnsModel(tortoise.Model): def __str__(self): return ( - f"<WarnsModel id={self.id} " + f"<Warn id={self.id} " f"server_id={self.server_id} " f"user_id={self.user_id} " f"reason='{self.reason}' " diff --git a/tuxbot/cogs/Polls/__init__.py b/tuxbot/cogs/Polls/__init__.py new file mode 100644 index 0000000..9230782 --- /dev/null +++ b/tuxbot/cogs/Polls/__init__.py @@ -0,0 +1,19 @@ +from collections import namedtuple + +from .polls import Polls +from .config import PollsConfig, HAS_MODELS +from ...core.bot import Tux + +VersionInfo = namedtuple("VersionInfo", "major minor micro release_level") +version_info = VersionInfo(major=2, minor=0, micro=0, release_level="alpha") + +__version__ = "v{}.{}.{}-{}".format( + version_info.major, + version_info.minor, + version_info.micro, + version_info.release_level, +).replace("\n", "") + + +def setup(bot: Tux): + bot.add_cog(Polls(bot)) diff --git a/tuxbot/cogs/Polls/config.py b/tuxbot/cogs/Polls/config.py new file mode 100644 index 0000000..e5f8b5c --- /dev/null +++ b/tuxbot/cogs/Polls/config.py @@ -0,0 +1,10 @@ +from structured_config import Structure + +HAS_MODELS = True + + +class PollsConfig(Structure): + pass + + +extra = {} diff --git a/tuxbot/cogs/Polls/locales/en-US.po b/tuxbot/cogs/Polls/locales/en-US.po new file mode 100644 index 0000000..d7bc028 --- /dev/null +++ b/tuxbot/cogs/Polls/locales/en-US.po @@ -0,0 +1,18 @@ +# English translations for Tuxbot-bot package. +# Copyright (C) 2020 THE Tuxbot-bot'S COPYRIGHT HOLDER +# This file is distributed under the same license as the Tuxbot-bot package. +# Automatically generated, 2020. +# +msgid "" +msgstr "" +"Project-Id-Version: Tuxbot-bot\n" +"Report-Msgid-Bugs-To: rick@gnous.eu\n" +"POT-Creation-Date: 2020-10-21 01:15+0200\n" +"PO-Revision-Date: 2020-10-21 01:15+0200\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: en_US\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" diff --git a/tuxbot/cogs/Polls/locales/fr-FR.po b/tuxbot/cogs/Polls/locales/fr-FR.po new file mode 100644 index 0000000..5f7d0d1 --- /dev/null +++ b/tuxbot/cogs/Polls/locales/fr-FR.po @@ -0,0 +1,19 @@ +# French translations for Tuxbot-bot package +# Traductions françaises du paquet Tuxbot-bot. +# Copyright (C) 2020 THE Tuxbot-bot'S COPYRIGHT HOLDER +# This file is distributed under the same license as the Tuxbot-bot package. +# Automatically generated, 2020. +# +msgid "" +msgstr "" +"Project-Id-Version: Tuxbot-bot\n" +"Report-Msgid-Bugs-To: rick@gnous.eu\n" +"POT-Creation-Date: 2020-10-21 01:15+0200\n" +"PO-Revision-Date: 2020-10-21 01:15+0200\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" diff --git a/tuxbot/cogs/Polls/locales/messages.pot b/tuxbot/cogs/Polls/locales/messages.pot new file mode 100644 index 0000000..9c11528 --- /dev/null +++ b/tuxbot/cogs/Polls/locales/messages.pot @@ -0,0 +1,18 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the Tuxbot-bot package. +# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: Tuxbot-bot\n" +"Report-Msgid-Bugs-To: rick@gnous.eu\n" +"POT-Creation-Date: 2020-10-21 01:15+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Language-Team: LANGUAGE <LL@li.org>\n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" diff --git a/tuxbot/cogs/Polls/models/__init__.py b/tuxbot/cogs/Polls/models/__init__.py new file mode 100644 index 0000000..e622fc8 --- /dev/null +++ b/tuxbot/cogs/Polls/models/__init__.py @@ -0,0 +1,2 @@ +from .polls import * +from .responses import * diff --git a/tuxbot/cogs/Polls/models/polls.py b/tuxbot/cogs/Polls/models/polls.py new file mode 100644 index 0000000..dfe82c4 --- /dev/null +++ b/tuxbot/cogs/Polls/models/polls.py @@ -0,0 +1,35 @@ +import tortoise +from tortoise import fields + + +class Poll(tortoise.Model): + id = fields.BigIntField(pk=True) + channel_id = fields.BigIntField() + message_id = fields.BigIntField() + author_id = fields.BigIntField() + + content = fields.JSONField() + is_anonymous = fields.BooleanField() + + available_choices = fields.IntField() + + choices: fields.ManyToManyRelation["Response"] = fields.ManyToManyField( + "models.Response", related_name="choices" + ) + + class Meta: + table = "polls" + + def __str__(self): + return ( + f"<Poll id={self.id} " + f"channel_id={self.channel_id} " + f"message_id={self.message_id} " + f"author_id={self.author_id} " + f"content={self.content} " + f"is_anonymous={self.is_anonymous} " + f"available_choices={self.available_choices} " + f"choices={self.choices}>" + ) + + __repr__ = __str__ diff --git a/tuxbot/cogs/Polls/models/responses.py b/tuxbot/cogs/Polls/models/responses.py new file mode 100644 index 0000000..9f2834c --- /dev/null +++ b/tuxbot/cogs/Polls/models/responses.py @@ -0,0 +1,22 @@ +import tortoise +from tortoise import fields + + +class Response(tortoise.Model): + response_id = fields.BigIntField(pk=True) + poll = fields.ForeignKeyField("models.Poll") + user_id = fields.BigIntField() + + choice = fields.IntField() + + class Meta: + table = "responses" + + def __str__(self): + return ( + f"<Response poll={self.poll} " + f"user_id={self.user_id} " + f"choice={self.choice}>" + ) + + __repr__ = __str__ diff --git a/tuxbot/cogs/Polls/polls.py b/tuxbot/cogs/Polls/polls.py new file mode 100644 index 0000000..21332ab --- /dev/null +++ b/tuxbot/cogs/Polls/polls.py @@ -0,0 +1,51 @@ +import logging + +from discord.ext import commands + +from tuxbot.core.utils.functions.extra import ContextPlus, group_extra +from tuxbot.core.bot import Tux +from tuxbot.core.i18n import ( + Translator, +) + +log = logging.getLogger("tuxbot.cogs.Polls") +_ = Translator("Polls", __file__) + + +class Polls(commands.Cog, name="Polls"): + def __init__(self, bot: Tux): + self.bot = bot + + # ========================================================================= + # ========================================================================= + + @group_extra(name="polls", aliases=["poll", "sondages", "sondage"]) + async def _polls(self, ctx: ContextPlus, *, message): + if ctx.invoked_subcommand is None: + args: list = message.lower().split() + is_anonymous = False + + if "--anonymous" in args: + is_anonymous = True + args.remove("--anonymous") + elif "--anonyme" in args: + is_anonymous = True + args.remove("--anonyme") + + if args[-1] != "|": + args.append("|") + + delimiters = [i for i, val in enumerate(args) if val == "|"] + + question = " ".join(args[0 : delimiters[0]]).capitalize() + answers = [] + + for i in range(len(delimiters) - 1): + start = delimiters[i] + 1 + end = delimiters[i + 1] + + answers.append(" ".join(args[start:end]).capitalize()) + + await ctx.send( + f"{message=}\n{question=}\n{answers=}\n{is_anonymous=}" + ) diff --git a/tuxbot/cogs/Utils/locales/messages.pot b/tuxbot/cogs/Utils/locales/messages.pot index 3e3e5d8..31a4f39 100644 --- a/tuxbot/cogs/Utils/locales/messages.pot +++ b/tuxbot/cogs/Utils/locales/messages.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Tuxbot-bot\n" "Report-Msgid-Bugs-To: rick@gnous.eu\n" -"POT-Creation-Date: 2020-11-11 02:44+0100\n" +"POT-Creation-Date: 2020-11-11 16:42+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language-Team: LANGUAGE <LL@li.org>\n" diff --git a/tuxbot/core/bot.py b/tuxbot/core/bot.py index c7c9bd9..ca7bbbc 100644 --- a/tuxbot/core/bot.py +++ b/tuxbot/core/bot.py @@ -43,6 +43,7 @@ packages: List[str] = [ "tuxbot.cogs.Logs", "tuxbot.cogs.Dev", "tuxbot.cogs.Utils", + "tuxbot.cogs.Polls", ] @@ -172,9 +173,9 @@ class Tux(commands.AutoShardedBot): ) for extension in packages: if extension in self.extensions: - status = f"[green]:heavy_check_mark: {extension}" + status = f"[green]:heavy_check_mark: {extension} " else: - status = f"[red]:heavy_multiplication_x: {extension}" + status = f"[red]:heavy_multiplication_x: {extension} " table.add_row(status) columns.add_renderable(table) diff --git a/tuxbot/core/utils/data_manager.py b/tuxbot/core/utils/data_manager.py index a28a824..ad8eafd 100644 --- a/tuxbot/core/utils/data_manager.py +++ b/tuxbot/core/utils/data_manager.py @@ -37,7 +37,7 @@ def logs_data_path(instance_name: str) -> Path: Path Generated path for Logs files. """ - return data_path(instance_name) / "Logs" + return data_path(instance_name) / "logs" def cogs_data_path(instance_name: str, cog_name: str = "") -> Path: diff --git a/tuxbot/core/utils/functions/extra.py b/tuxbot/core/utils/functions/extra.py index 1b79911..cd0d26a 100644 --- a/tuxbot/core/utils/functions/extra.py +++ b/tuxbot/core/utils/functions/extra.py @@ -1,15 +1,16 @@ import asyncio +import random import discord from discord import Embed -from discord.ext import commands, flags +from discord.ext import commands from rich.console import Console console = Console() -TOKEN_REPLACEMENT = "whoops, leaked token" -PASSWORD_REPLACEMENT = "whoops, leaked password" +TOKEN_REPLACEMENT = "\*" * random.randint(3, 15) +PASSWORD_REPLACEMENT = "\*" * random.randint(3, 15) class ContextPlus(commands.Context): @@ -88,7 +89,7 @@ class ContextPlus(commands.Context): ) -class CommandPLus(flags.FlagCommand): +class CommandPLus(commands.Command): def __init__(self, function, **kwargs): super().__init__(function, **kwargs) self.deletable = kwargs.pop("deletable", True) @@ -98,7 +99,7 @@ def command_extra(*args, **kwargs): return commands.command(*args, **kwargs, cls=CommandPLus) -class GroupPlus(flags.FlagGroup): +class GroupPlus(commands.Group): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.deletable = kwargs.pop("deletable", True)