2020-06-11 01:06:30 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import discord
|
|
|
|
from discord.ext import commands
|
|
|
|
|
2020-11-08 01:07:27 +01:00
|
|
|
from tuxbot.core.utils import checks
|
2020-06-11 01:06:30 +02:00
|
|
|
from tuxbot.core.bot import Tux
|
2020-10-19 21:44:29 +02:00
|
|
|
from tuxbot.core.config import set_for_key
|
2020-10-19 15:04:10 +02:00
|
|
|
from tuxbot.core.config import Config
|
2020-10-19 00:20:58 +02:00
|
|
|
from tuxbot.core.i18n import (
|
|
|
|
Translator,
|
|
|
|
find_locale,
|
|
|
|
get_locale_name,
|
|
|
|
available_locales,
|
|
|
|
)
|
2020-09-02 00:08:06 +02:00
|
|
|
from tuxbot.core.utils.functions.extra import (
|
2020-10-19 00:20:58 +02:00
|
|
|
group_extra,
|
|
|
|
command_extra,
|
|
|
|
ContextPlus,
|
2020-09-02 00:08:06 +02:00
|
|
|
)
|
2020-06-11 01:06:30 +02:00
|
|
|
|
2020-11-09 01:18:55 +01:00
|
|
|
log = logging.getLogger("tuxbot.cogs.Admin")
|
2020-06-11 01:06:30 +02:00
|
|
|
_ = Translator("Admin", __file__)
|
|
|
|
|
|
|
|
|
|
|
|
class Admin(commands.Cog, name="Admin"):
|
|
|
|
def __init__(self, bot: Tux):
|
|
|
|
self.bot = bot
|
|
|
|
|
2020-06-11 19:43:00 +02:00
|
|
|
async def _save_lang(self, ctx: ContextPlus, lang: str):
|
2020-10-19 21:44:29 +02:00
|
|
|
set_for_key(
|
2020-10-19 15:04:10 +02:00
|
|
|
self.bot.config.Servers, ctx.guild.id, Config.Server, locale=lang
|
|
|
|
)
|
2020-06-11 19:43:00 +02:00
|
|
|
|
2020-11-11 01:05:36 +01:00
|
|
|
# =========================================================================
|
|
|
|
# =========================================================================
|
|
|
|
|
2020-06-11 19:43:00 +02:00
|
|
|
@group_extra(name="lang", aliases=["locale", "langue"], deletable=True)
|
2020-06-11 01:06:30 +02:00
|
|
|
@commands.guild_only()
|
|
|
|
@checks.is_admin()
|
|
|
|
async def _lang(self, ctx: ContextPlus):
|
|
|
|
"""Manage lang settings."""
|
|
|
|
|
|
|
|
@_lang.command(name="set", aliases=["define", "choice"])
|
|
|
|
async def _lang_set(self, ctx: ContextPlus, lang: str):
|
|
|
|
try:
|
2020-06-11 19:43:00 +02:00
|
|
|
await self._save_lang(ctx, find_locale(lang.lower()))
|
2020-06-11 01:06:30 +02:00
|
|
|
await ctx.send(
|
2020-10-19 00:20:58 +02:00
|
|
|
_(
|
|
|
|
"Locale changed to {lang} successfully",
|
|
|
|
ctx,
|
|
|
|
self.bot.config,
|
|
|
|
).format(lang=f"`{get_locale_name(lang).lower()}`")
|
2020-06-11 01:06:30 +02:00
|
|
|
)
|
|
|
|
except NotImplementedError:
|
2020-06-11 19:43:00 +02:00
|
|
|
await self._lang_list(ctx)
|
2020-06-11 01:06:30 +02:00
|
|
|
|
|
|
|
@_lang.command(name="list", aliases=["liste", "all", "view"])
|
|
|
|
async def _lang_list(self, ctx: ContextPlus):
|
2020-10-19 00:20:58 +02:00
|
|
|
description = ""
|
2020-09-02 00:08:06 +02:00
|
|
|
for key, value in available_locales.items():
|
|
|
|
description += f":flag_{key[-2:].lower()}: {value[0]}\n"
|
|
|
|
|
2020-06-11 01:06:30 +02:00
|
|
|
e = discord.Embed(
|
2020-06-11 19:43:00 +02:00
|
|
|
title=_("List of available locales: ", ctx, self.bot.config),
|
2020-09-02 00:08:06 +02:00
|
|
|
description=description,
|
2020-06-11 19:43:00 +02:00
|
|
|
color=0x36393E,
|
2020-06-11 01:06:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
await ctx.send(embed=e)
|
2020-09-02 00:08:06 +02:00
|
|
|
|
|
|
|
# =========================================================================
|
|
|
|
|
|
|
|
@command_extra(name="quit", aliases=["shutdown"], deletable=False)
|
|
|
|
@commands.guild_only()
|
|
|
|
@checks.is_owner()
|
|
|
|
async def _quit(self, ctx: ContextPlus):
|
|
|
|
await ctx.send("*quit...*")
|
|
|
|
await self.bot.shutdown()
|
|
|
|
|
|
|
|
@command_extra(name="restart", deletable=False)
|
|
|
|
@commands.guild_only()
|
|
|
|
@checks.is_owner()
|
|
|
|
async def _restart(self, ctx: ContextPlus):
|
|
|
|
await ctx.send("*restart...*")
|
|
|
|
await self.bot.shutdown(restart=True)
|