Compare commits
2 Commits
eb635952fb
...
f969f7d3f1
Author | SHA1 | Date | |
---|---|---|---|
f969f7d3f1
|
|||
1c2e0fda9f
|
@@ -17,7 +17,7 @@ logger: Logger = get_logger(__name__)
|
||||
class PycordGuild:
|
||||
"""Dataclass of DB entry of a guild"""
|
||||
|
||||
__slots__ = ("_id", "id", "channel_id", "category_id", "timezone", "language")
|
||||
__slots__ = ("_id", "id", "channel_id", "category_id", "timezone")
|
||||
__short_name__ = "guild"
|
||||
__collection__ = col_guilds
|
||||
|
||||
@@ -26,7 +26,6 @@ class PycordGuild:
|
||||
channel_id: int | None
|
||||
category_id: int | None
|
||||
timezone: str
|
||||
language: str | None
|
||||
|
||||
@classmethod
|
||||
async def from_id(
|
||||
@@ -146,7 +145,6 @@ class PycordGuild:
|
||||
"channel_id": self.channel_id,
|
||||
"category_id": self.category_id,
|
||||
"timezone": self.timezone,
|
||||
"language": self.language,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
@@ -156,7 +154,6 @@ class PycordGuild:
|
||||
"channel_id": None,
|
||||
"category_id": None,
|
||||
"timezone": "UTC",
|
||||
"language": None,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
@@ -226,11 +223,3 @@ class PycordGuild:
|
||||
# TODO Add documentation
|
||||
async def reset_timezone(self, cache: Optional[Cache] = None) -> None:
|
||||
await self._remove(cache, "timezone")
|
||||
|
||||
# TODO Add documentation
|
||||
async def set_language(self, language: str, cache: Optional[Cache] = None) -> None:
|
||||
await self._set(cache, language=language)
|
||||
|
||||
# TODO Add documentation
|
||||
async def reset_language(self, cache: Optional[Cache] = None) -> None:
|
||||
await self._remove(cache, "language")
|
||||
|
@@ -9,10 +9,11 @@ from discord import (
|
||||
)
|
||||
from discord.ext.commands import Cog
|
||||
from discord.utils import basic_autocomplete
|
||||
from libbot.i18n import in_every_locale, _
|
||||
|
||||
from classes import PycordGuild
|
||||
from classes.pycord_bot import PycordBot
|
||||
from modules.utils import autocomplete_languages, autocomplete_timezones
|
||||
from modules.utils import autocomplete_timezones
|
||||
|
||||
|
||||
class Config(Cog):
|
||||
@@ -21,42 +22,50 @@ class Config(Cog):
|
||||
def __init__(self, bot: PycordBot):
|
||||
self.bot: PycordBot = bot
|
||||
|
||||
# TODO Introduce i18n
|
||||
command_group: SlashCommandGroup = SlashCommandGroup("config", "Guild management")
|
||||
command_group: SlashCommandGroup = SlashCommandGroup(
|
||||
name="config",
|
||||
description=_("description", "commands", "config"),
|
||||
description_localizations=in_every_locale("description", "commands", "config"),
|
||||
)
|
||||
|
||||
# TODO Introduce i18n
|
||||
@command_group.command(
|
||||
name="set",
|
||||
description="Configure the guild",
|
||||
description=_("description", "commands", "config_set"),
|
||||
description_localizations=in_every_locale("description", "commands", "config_set"),
|
||||
)
|
||||
@option(
|
||||
"category",
|
||||
description=_("description", "commands", "config_set", "options", "category"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "config_set", "options", "category"
|
||||
),
|
||||
required=True,
|
||||
)
|
||||
@option("category", description="Category where channels for each user will be created", required=True)
|
||||
@option("channel", description="Text channel for admin notifications", required=True)
|
||||
@option(
|
||||
"timezone",
|
||||
description="Timezone in which events take place",
|
||||
description=_("description", "commands", "config_set", "options", "timezone"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "config_set", "options", "timezone"
|
||||
),
|
||||
autocomplete=basic_autocomplete(autocomplete_timezones),
|
||||
required=True,
|
||||
)
|
||||
@option(
|
||||
"language",
|
||||
description="Language for bot's messages",
|
||||
autocomplete=basic_autocomplete(autocomplete_languages),
|
||||
required=True,
|
||||
)
|
||||
async def command_config_set(
|
||||
self,
|
||||
ctx: ApplicationContext,
|
||||
category: CategoryChannel,
|
||||
channel: TextChannel,
|
||||
timezone: str,
|
||||
language: str,
|
||||
) -> None:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
|
||||
try:
|
||||
timezone_parsed: ZoneInfo = ZoneInfo(timezone)
|
||||
except ZoneInfoNotFoundError:
|
||||
await ctx.respond(f"Timezone {timezone} was not found.")
|
||||
await ctx.respond(
|
||||
self.bot._("timezone_invalid", "messages", locale=ctx.locale).format(timezone=timezone)
|
||||
)
|
||||
return
|
||||
|
||||
await guild.update(
|
||||
@@ -64,47 +73,52 @@ class Config(Cog):
|
||||
channel_id=channel.id,
|
||||
category_id=category.id,
|
||||
timezone=str(timezone_parsed),
|
||||
language=language,
|
||||
)
|
||||
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Okay.")
|
||||
await ctx.respond(self.bot._("config_set", "messages", locale=ctx.locale))
|
||||
|
||||
# TODO Introduce i18n
|
||||
@command_group.command(
|
||||
name="reset",
|
||||
description="Reset the guild's configuration",
|
||||
description=_("description", "commands", "config_reset"),
|
||||
description_localizations=in_every_locale("description", "commands", "config_reset"),
|
||||
)
|
||||
@option(
|
||||
"confirm",
|
||||
description=_("description", "commands", "config_reset", "options", "confirm"),
|
||||
description_localizations=in_every_locale(
|
||||
"description", "commands", "config_reset", "options", "confirm"
|
||||
),
|
||||
required=False,
|
||||
)
|
||||
@option("confirm", description="Confirmation of the operation", required=False)
|
||||
async def command_config_reset(self, ctx: ApplicationContext, confirm: bool = False) -> None:
|
||||
if confirm is None or not confirm:
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Operation not confirmed.")
|
||||
await ctx.respond(self.bot._("operation_unconfirmed", "messages", locale=ctx.locale))
|
||||
return
|
||||
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
|
||||
await guild.purge(self.bot.cache)
|
||||
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Okay.")
|
||||
await ctx.respond(self.bot._("config_reset", "messages", locale=ctx.locale))
|
||||
|
||||
# TODO Introduce i18n
|
||||
@command_group.command(
|
||||
name="show",
|
||||
description="Show the guild's configuration",
|
||||
description=_("description", "commands", "config_show"),
|
||||
description_localizations=in_every_locale("description", "commands", "config_show"),
|
||||
)
|
||||
async def command_config_show(self, ctx: ApplicationContext) -> None:
|
||||
guild: PycordGuild = await self.bot.find_guild(ctx.guild.id)
|
||||
|
||||
if not guild.is_configured():
|
||||
# TODO Make a nice message
|
||||
await ctx.respond("Guild is not configured.")
|
||||
await ctx.respond(self.bot._("guild_unconfigured_admin", "messages", locale=ctx.locale))
|
||||
return
|
||||
|
||||
# TODO Make a nice message
|
||||
await ctx.respond(
|
||||
f"**Guild config**\n\nChannel: <#{guild.channel_id}>\nCategory: <#{guild.category_id}>\nTimezone: {guild.timezone}\nLanguage: {guild.language}"
|
||||
self.bot._("config_show", "messages", locale=ctx.locale).format(
|
||||
channel_id=guild.channel_id,
|
||||
category_id=guild.category_id,
|
||||
timezone=guild.timezone,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"locale": "en",
|
||||
"locale": "en-US",
|
||||
"debug": false,
|
||||
"bot": {
|
||||
"owners": [
|
||||
|
41
locale/en-US.json
Normal file
41
locale/en-US.json
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"messages": {
|
||||
"operation_unconfirmed": "Operation not confirmed.",
|
||||
"guild_unconfigured": "Guild is not configured. Please, report this to the administrator.",
|
||||
"guild_unconfigured_admin": "Guild is not configured. Please, configure it using `/config set`.",
|
||||
"timezone_invalid": "Timezone **{timezone}** was not found. Please, select one of the timezones provided by the autocompletion.",
|
||||
"config_set": "Configuration has been updated. You can review it anytime using `/config show`.",
|
||||
"config_reset": "Configuration has been reset. You can update it using `/config set`, otherwise no events can be held.",
|
||||
"config_show": "**Guild config**\n\nChannel: <#{channel_id}>\nCategory: <#{category_id}>\nTimezone: {timezone}"
|
||||
},
|
||||
"commands": {
|
||||
"config": {
|
||||
"description": "Guild management"
|
||||
},
|
||||
"config_set": {
|
||||
"description": "Configure the guild",
|
||||
"options": {
|
||||
"category": {
|
||||
"description": "Category where channels for each user will be created"
|
||||
},
|
||||
"channel": {
|
||||
"description": "Text channel for admin notifications"
|
||||
},
|
||||
"timezone": {
|
||||
"description": "Timezone in which events take place"
|
||||
}
|
||||
}
|
||||
},
|
||||
"config_reset": {
|
||||
"description": "Reset the guild's configuration",
|
||||
"options": {
|
||||
"confirm": {
|
||||
"description": "Confirmation of the operation"
|
||||
}
|
||||
}
|
||||
},
|
||||
"config_show": {
|
||||
"description": "Show the guild's configuration"
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"messages": {}
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"messages": {}
|
||||
}
|
@@ -5,6 +5,7 @@ from zoneinfo import ZoneInfo, available_timezones
|
||||
from bson import ObjectId
|
||||
from discord import AutocompleteContext, OptionChoice
|
||||
from pymongo import ASCENDING
|
||||
from typing_extensions import deprecated
|
||||
|
||||
from modules.database import col_events, col_stages, col_users
|
||||
|
||||
@@ -15,6 +16,7 @@ async def autocomplete_timezones(ctx: AutocompleteContext) -> List[str]:
|
||||
return sorted(list(available_timezones()))
|
||||
|
||||
|
||||
@deprecated
|
||||
async def autocomplete_languages(ctx: AutocompleteContext) -> List[str]:
|
||||
"""Return locales supported by the bot"""
|
||||
|
||||
|
Reference in New Issue
Block a user