feat(commands:polls|Polls): start dev of poll command
This commit is contained in:
parent
b4194dcadf
commit
cfd59def74
18 changed files with 214 additions and 15 deletions
|
@ -2,6 +2,7 @@
|
||||||
<dictionary name="romain">
|
<dictionary name="romain">
|
||||||
<words>
|
<words>
|
||||||
<w>anglais</w>
|
<w>anglais</w>
|
||||||
|
<w>anonyme</w>
|
||||||
<w>appdirs</w>
|
<w>appdirs</w>
|
||||||
<w>apres</w>
|
<w>apres</w>
|
||||||
<w>asctime</w>
|
<w>asctime</w>
|
||||||
|
@ -30,6 +31,8 @@
|
||||||
<w>rprint</w>
|
<w>rprint</w>
|
||||||
<w>socketstats</w>
|
<w>socketstats</w>
|
||||||
<w>soit</w>
|
<w>soit</w>
|
||||||
|
<w>sondage</w>
|
||||||
|
<w>sondages</w>
|
||||||
<w>splt</w>
|
<w>splt</w>
|
||||||
<w>suivante</w>
|
<w>suivante</w>
|
||||||
<w>systemd</w>
|
<w>systemd</w>
|
||||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Tuxbot-bot\n"
|
"Project-Id-Version: Tuxbot-bot\n"
|
||||||
"Report-Msgid-Bugs-To: rick@gnous.eu\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"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
from .alias import *
|
from .alias import *
|
||||||
from .warn import *
|
from .warns import *
|
||||||
|
|
|
@ -2,7 +2,7 @@ import tortoise
|
||||||
from tortoise import fields
|
from tortoise import fields
|
||||||
|
|
||||||
|
|
||||||
class AliasesModel(tortoise.Model):
|
class Alias(tortoise.Model):
|
||||||
id = fields.BigIntField(pk=True)
|
id = fields.BigIntField(pk=True)
|
||||||
user_id = fields.BigIntField()
|
user_id = fields.BigIntField()
|
||||||
alias = fields.TextField(max_length=255)
|
alias = fields.TextField(max_length=255)
|
||||||
|
@ -14,7 +14,7 @@ class AliasesModel(tortoise.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return (
|
return (
|
||||||
f"<AliasesModel id={self.id} "
|
f"<Alias id={self.id} "
|
||||||
f"user_id={self.user_id} "
|
f"user_id={self.user_id} "
|
||||||
f"alias='{self.alias}' "
|
f"alias='{self.alias}' "
|
||||||
f"command='{self.command}' "
|
f"command='{self.command}' "
|
||||||
|
|
|
@ -2,7 +2,7 @@ import tortoise
|
||||||
from tortoise import fields
|
from tortoise import fields
|
||||||
|
|
||||||
|
|
||||||
class WarnsModel(tortoise.Model):
|
class Warn(tortoise.Model):
|
||||||
id = fields.BigIntField(pk=True)
|
id = fields.BigIntField(pk=True)
|
||||||
server_id = fields.BigIntField()
|
server_id = fields.BigIntField()
|
||||||
user_id = fields.BigIntField()
|
user_id = fields.BigIntField()
|
||||||
|
@ -14,7 +14,7 @@ class WarnsModel(tortoise.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return (
|
return (
|
||||||
f"<WarnsModel id={self.id} "
|
f"<Warn id={self.id} "
|
||||||
f"server_id={self.server_id} "
|
f"server_id={self.server_id} "
|
||||||
f"user_id={self.user_id} "
|
f"user_id={self.user_id} "
|
||||||
f"reason='{self.reason}' "
|
f"reason='{self.reason}' "
|
19
tuxbot/cogs/Polls/__init__.py
Normal file
19
tuxbot/cogs/Polls/__init__.py
Normal file
|
@ -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))
|
10
tuxbot/cogs/Polls/config.py
Normal file
10
tuxbot/cogs/Polls/config.py
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
from structured_config import Structure
|
||||||
|
|
||||||
|
HAS_MODELS = True
|
||||||
|
|
||||||
|
|
||||||
|
class PollsConfig(Structure):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
extra = {}
|
18
tuxbot/cogs/Polls/locales/en-US.po
Normal file
18
tuxbot/cogs/Polls/locales/en-US.po
Normal file
|
@ -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"
|
19
tuxbot/cogs/Polls/locales/fr-FR.po
Normal file
19
tuxbot/cogs/Polls/locales/fr-FR.po
Normal file
|
@ -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"
|
18
tuxbot/cogs/Polls/locales/messages.pot
Normal file
18
tuxbot/cogs/Polls/locales/messages.pot
Normal file
|
@ -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"
|
2
tuxbot/cogs/Polls/models/__init__.py
Normal file
2
tuxbot/cogs/Polls/models/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
from .polls import *
|
||||||
|
from .responses import *
|
35
tuxbot/cogs/Polls/models/polls.py
Normal file
35
tuxbot/cogs/Polls/models/polls.py
Normal file
|
@ -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__
|
22
tuxbot/cogs/Polls/models/responses.py
Normal file
22
tuxbot/cogs/Polls/models/responses.py
Normal file
|
@ -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__
|
51
tuxbot/cogs/Polls/polls.py
Normal file
51
tuxbot/cogs/Polls/polls.py
Normal file
|
@ -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=}"
|
||||||
|
)
|
|
@ -8,7 +8,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: Tuxbot-bot\n"
|
"Project-Id-Version: Tuxbot-bot\n"
|
||||||
"Report-Msgid-Bugs-To: rick@gnous.eu\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"
|
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||||
|
|
|
@ -43,6 +43,7 @@ packages: List[str] = [
|
||||||
"tuxbot.cogs.Logs",
|
"tuxbot.cogs.Logs",
|
||||||
"tuxbot.cogs.Dev",
|
"tuxbot.cogs.Dev",
|
||||||
"tuxbot.cogs.Utils",
|
"tuxbot.cogs.Utils",
|
||||||
|
"tuxbot.cogs.Polls",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -172,9 +173,9 @@ class Tux(commands.AutoShardedBot):
|
||||||
)
|
)
|
||||||
for extension in packages:
|
for extension in packages:
|
||||||
if extension in self.extensions:
|
if extension in self.extensions:
|
||||||
status = f"[green]:heavy_check_mark: {extension}"
|
status = f"[green]:heavy_check_mark: {extension} "
|
||||||
else:
|
else:
|
||||||
status = f"[red]:heavy_multiplication_x: {extension}"
|
status = f"[red]:heavy_multiplication_x: {extension} "
|
||||||
|
|
||||||
table.add_row(status)
|
table.add_row(status)
|
||||||
columns.add_renderable(table)
|
columns.add_renderable(table)
|
||||||
|
|
|
@ -37,7 +37,7 @@ def logs_data_path(instance_name: str) -> Path:
|
||||||
Path
|
Path
|
||||||
Generated path for Logs files.
|
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:
|
def cogs_data_path(instance_name: str, cog_name: str = "") -> Path:
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import random
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord import Embed
|
from discord import Embed
|
||||||
from discord.ext import commands, flags
|
from discord.ext import commands
|
||||||
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
TOKEN_REPLACEMENT = "whoops, leaked token"
|
TOKEN_REPLACEMENT = "\*" * random.randint(3, 15)
|
||||||
PASSWORD_REPLACEMENT = "whoops, leaked password"
|
PASSWORD_REPLACEMENT = "\*" * random.randint(3, 15)
|
||||||
|
|
||||||
|
|
||||||
class ContextPlus(commands.Context):
|
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):
|
def __init__(self, function, **kwargs):
|
||||||
super().__init__(function, **kwargs)
|
super().__init__(function, **kwargs)
|
||||||
self.deletable = kwargs.pop("deletable", True)
|
self.deletable = kwargs.pop("deletable", True)
|
||||||
|
@ -98,7 +99,7 @@ def command_extra(*args, **kwargs):
|
||||||
return commands.command(*args, **kwargs, cls=CommandPLus)
|
return commands.command(*args, **kwargs, cls=CommandPLus)
|
||||||
|
|
||||||
|
|
||||||
class GroupPlus(flags.FlagGroup):
|
class GroupPlus(commands.Group):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.deletable = kwargs.pop("deletable", True)
|
self.deletable = kwargs.pop("deletable", True)
|
||||||
|
|
Loading…
Reference in a new issue