From d5afdcc60b0cb6ae0aac8e171e3aa40916ce163f Mon Sep 17 00:00:00 2001 From: Romain J Date: Mon, 16 Dec 2019 19:36:55 +0100 Subject: [PATCH] update(command|info): add git to link's field --- README.md | 8 ++++---- bot.py | 12 +++++++----- cogs/admin.py | 16 ++++++++-------- cogs/basics.py | 14 +++++++++++--- cogs/utils/extra.py | 21 +++++++++++++++++++++ extras/locales/en/LC_MESSAGES/commands.mo | Bin 0 -> 28 bytes extras/locales/en/LC_MESSAGES/commands.po | 0 extras/locales/fr/LC_MESSAGES/commands.mo | Bin 0 -> 28 bytes extras/locales/fr/LC_MESSAGES/commands.po | 0 9 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 cogs/utils/extra.py create mode 100644 extras/locales/en/LC_MESSAGES/commands.mo create mode 100644 extras/locales/en/LC_MESSAGES/commands.po create mode 100644 extras/locales/fr/LC_MESSAGES/commands.mo create mode 100644 extras/locales/fr/LC_MESSAGES/commands.po diff --git a/README.md b/README.md index 37224ee..0c8e709 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,8 @@ ## Launcher requirements : - [ ] Can install the bot - - [x] Can launch the bot - - [x] Can propose updates + - [ ] Can launch the bot + - [ ] Can propose updates ## New commands : @@ -27,7 +27,7 @@ ## Ultimate : - [ ] Send email or Telegram's message when something is wrong on the bot - - [ ] Create skynet (group of multiple commands about sky (planes, meteo,...)) + - [ ] Create skynet (group of multiple commands about sky (planes, meteo, AI,...)) --- @@ -57,7 +57,7 @@ --- - # Cogs.ci commands + # Cogs.ci commands `canceled until the frontend development` - [ ] ci (help?) - [ ] ci show - [ ] ci register diff --git a/bot.py b/bot.py index dc97a0d..7a023ae 100755 --- a/bot.py +++ b/bot.py @@ -10,6 +10,7 @@ import discord import git from discord.ext import commands +from cogs.utils.database import Database from cogs.utils.config import Config from cogs.utils.lang import Texts from cogs.utils.version import Version @@ -22,10 +23,10 @@ build = git.Repo(search_parent_directories=True).head.object.hexsha log = logging.getLogger(__name__) l_extensions: List[str] = [ - 'cogs.admin', + # 'cogs.admin', 'cogs.basics', - 'cogs.utility', - 'cogs.logs', + # 'cogs.utility', + # 'cogs.logs', # 'cogs.poll', 'jishaku', ] @@ -46,7 +47,7 @@ async def _prefix_callable(bot, message: discord.message) -> list: class TuxBot(commands.AutoShardedBot): - def __init__(self): + def __init__(self, database): super().__init__(command_prefix=_prefix_callable, pm_help=None, help_command=None, description=description, help_attrs=dict(hidden=True), @@ -60,6 +61,7 @@ class TuxBot(commands.AutoShardedBot): self.uptime: datetime = datetime.datetime.utcnow() self._prev_events = deque(maxlen=10) self.session = aiohttp.ClientSession(loop=self.loop) + self.database = database self.config = Config('./configs/config.cfg') self.prefixes = Config('./configs/prefixes.cfg') @@ -189,7 +191,7 @@ if __name__ == "__main__": print(Texts().get('Starting...')) - bot = TuxBot() + bot = TuxBot(Database(Config("./configs/config.cfg"))) try: with setup_logging(): bot.run() diff --git a/cogs/admin.py b/cogs/admin.py index dcf82f6..812e1f7 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -372,9 +372,9 @@ class Admin(commands.Cog): @_warn.command(name='remove', aliases=['revoke']) async def _warn_remove(self, ctx: commands.Context, warn_id: int): - warn = self.bot.database.session\ - .query(Warn)\ - .filter(Warn.id == warn_id)\ + warn = self.bot.database.session \ + .query(Warn) \ + .filter(Warn.id == warn_id) \ .one() self.bot.database.session.delete(warn) @@ -395,9 +395,9 @@ class Admin(commands.Cog): @_warn.command(name='edit', aliases=['change']) async def _warn_edit(self, ctx: commands.Context, warn_id: int, *, reason): - warn = self.bot.database.session\ - .query(Warn)\ - .filter(Warn.id == warn_id)\ + warn = self.bot.database.session \ + .query(Warn) \ + .filter(Warn.id == warn_id) \ .one() warn.reason = reason @@ -413,8 +413,8 @@ class Admin(commands.Cog): available = self.bot.database.session \ .query(Lang.value) \ .filter(Lang.key == 'available') \ - .one()[0] \ - .split(', ') + .first()[0] \ + .split(',') if locale.lower() not in available: await ctx.send( diff --git a/cogs/basics.py b/cogs/basics.py index 8df6358..e1b3c95 100644 --- a/cogs/basics.py +++ b/cogs/basics.py @@ -10,6 +10,7 @@ from discord.ext import commands from bot import TuxBot from .utils.lang import Texts +from .utils.extra import commandExtra, groupExtra from tcp_latency import measure_latency @@ -26,7 +27,9 @@ class Basics(commands.Cog): """---------------------------------------------------------------------""" - @commands.command(name='ping') + @commandExtra(name='ping', + category='basics', + description=Texts('commands').get('basics.ping')) async def _ping(self, ctx: commands.Context): start = time.perf_counter() await ctx.trigger_typing() @@ -64,7 +67,9 @@ class Basics(commands.Cog): return total, file_amount - @commands.command(name='info', aliases=['about']) + @commands.command(name='info', aliases=['about'], + category='basics', + description=Texts('commands').get('basics.info')) async def _info(self, ctx: commands.Context): proc = psutil.Process() lines, files = self.fetch_info() @@ -133,6 +138,7 @@ class Basics(commands.Cog): name=f"__:link: {Texts('basics', ctx).get('Links')}__", value="[tuxbot.gnous.eu](https://tuxbot.gnous.eu/) " "| [gnous.eu](https://gnous.eu/) " + "| [git](https://git.gnous.eu/gnouseu/tuxbot-bot) " f"| [{Texts('basics', ctx).get('Invite')}](https://discordapp.com/oauth2/authorize?client_id=301062143942590465&scope=bot&permissions=268749888)", inline=False ) @@ -144,7 +150,9 @@ class Basics(commands.Cog): """---------------------------------------------------------------------""" - @commands.command(name='credits', aliases=['contributors', 'authors']) + @commands.command(name='credits', aliases=['contributors', 'authors'], + category='basics', + description=Texts('commands').get('basics.credits')) async def _credits(self, ctx: commands.Context): e = discord.Embed( title=Texts('basics', ctx).get('Contributors'), diff --git a/cogs/utils/extra.py b/cogs/utils/extra.py new file mode 100644 index 0000000..6cecb38 --- /dev/null +++ b/cogs/utils/extra.py @@ -0,0 +1,21 @@ +from discord.ext import commands + + +class commandsPlus(commands.Command): + def __init__(self, func, **kwargs): + super().__init__(func, **kwargs) + self.category = kwargs.pop("category") + + +def commandExtra(*args, **kwargs): + return commands.command(*args, **kwargs, cls=commandsPlus) + + +class GroupPlus(commands.Group): + def __init__(self, func, **kwargs): + super().__init__(func, **kwargs) + self.category = kwargs.pop("category") + + +def groupExtra(*args, **kwargs): + return commands.group(*args, **kwargs, cls=GroupPlus) diff --git a/extras/locales/en/LC_MESSAGES/commands.mo b/extras/locales/en/LC_MESSAGES/commands.mo new file mode 100644 index 0000000000000000000000000000000000000000..4b144831cf5f75c62f6e9446b91ce164bb3c8dee GIT binary patch literal 28 Tcmca7#4?ou3S@vZ2*UsXEKdQ# literal 0 HcmV?d00001 diff --git a/extras/locales/en/LC_MESSAGES/commands.po b/extras/locales/en/LC_MESSAGES/commands.po new file mode 100644 index 0000000..e69de29 diff --git a/extras/locales/fr/LC_MESSAGES/commands.mo b/extras/locales/fr/LC_MESSAGES/commands.mo new file mode 100644 index 0000000000000000000000000000000000000000..4b144831cf5f75c62f6e9446b91ce164bb3c8dee GIT binary patch literal 28 Tcmca7#4?ou3S@vZ2*UsXEKdQ# literal 0 HcmV?d00001 diff --git a/extras/locales/fr/LC_MESSAGES/commands.po b/extras/locales/fr/LC_MESSAGES/commands.po new file mode 100644 index 0000000..e69de29