From d0a9e658a6fdebdcd7b373bc3d9fc3d12b368080 Mon Sep 17 00:00:00 2001 From: Romain J Date: Fri, 13 Sep 2019 11:20:17 +0200 Subject: [PATCH] update(doc|readme): Add cogs.admin's commands todo refactor(command|admin): rewrite some of all admin's command --- README.md | 20 ++++++++- cogs/admin.py | 73 ++++++++++++++++++++++++-------- locales/en/LC_MESSAGES/admin.po | 2 +- locales/en/LC_MESSAGES/utils.mo | Bin 0 -> 363 bytes locales/en/LC_MESSAGES/utils.po | 22 ++++++++++ locales/fr/LC_MESSAGES/admin.mo | Bin 585 -> 583 bytes locales/fr/LC_MESSAGES/admin.po | 4 +- locales/fr/LC_MESSAGES/utils.mo | Bin 0 -> 520 bytes locales/fr/LC_MESSAGES/utils.po | 22 ++++++++++ 9 files changed, 121 insertions(+), 22 deletions(-) create mode 100644 locales/en/LC_MESSAGES/utils.mo create mode 100644 locales/en/LC_MESSAGES/utils.po create mode 100644 locales/fr/LC_MESSAGES/utils.mo create mode 100644 locales/fr/LC_MESSAGES/utils.po diff --git a/README.md b/README.md index 0c8af88..c236d12 100644 --- a/README.md +++ b/README.md @@ -27,4 +27,22 @@ ## Ultimate : - [ ] Send email or Telegram's message when something is wrong on the bot - - [ ] Create skynet (group of multiple commands about sky (planes, meteo,...)) \ No newline at end of file + - [ ] Create skynet (group of multiple commands about sky (planes, meteo,...)) + + --- + + # Cogs.admin commands + + - [ ] upload + - [x] ban + - [x] kick + - [x] clear + - [x] say + - [x] sayto `removed`, now : `say to` + - [x] sayto_dm `removed`, now : `say to` + - [x] editsay `removed`, now : `say edit` + - [x] addreaction `renamed` + - [ ] delete + - [ ] deletefrom + - [ ] embed + \ No newline at end of file diff --git a/cogs/admin.py b/cogs/admin.py index b106dff..85e2762 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -1,4 +1,5 @@ import datetime +from typing import Union import discord from discord.ext import commands @@ -55,22 +56,49 @@ class Admin(commands.Cog): """---------------------------------------------------------------------""" - @commands.command(name='say') - async def _say(self, ctx: commands.Context, *, to_say: str): + @commands.group(name='say', invoke_without_command=True) + async def _say(self, ctx: commands.Context, *, content: str): try: await ctx.message.delete() - await ctx.send(to_say) except discord.errors.Forbidden: - await ctx.send(to_say) + pass + + await ctx.send(content) + + @_say.command(name='edit') + async def _say_edit(self, ctx: commands.Context, message_id: int, *, + content: str): + try: + await ctx.message.delete() + except discord.errors.Forbidden: + pass + + try: + message: discord.Message = await ctx.channel.fetch_message( + message_id) + await message.edit(content=content) + except (discord.errors.NotFound, discord.errors.Forbidden): + await ctx.send(Texts('utils').get("Unable to find the message")) + + @_say.command(name='to') + async def _say_to(self, ctx: commands.Context, + channel: Union[discord.TextChannel, discord.User], *, + content): + try: + await ctx.message.delete() + except discord.errors.Forbidden: + pass + + await channel.send(content) """---------------------------------------------------------------------""" @commands.command(name='ban') async def _ban(self, ctx: commands.Context, user: discord.User, *, reason=""): - member: discord.Member = await ctx.guild.fetch_member(user.id) + try: + member: discord.Member = await ctx.guild.fetch_member(user.id) - if member: try: await member.ban(reason=reason) e: discord.Embed = await self.kick_ban_message( @@ -83,17 +111,17 @@ class Admin(commands.Cog): await ctx.send(embed=e) except discord.Forbidden: await ctx.send(Texts('admin').get("Unable to ban this user")) - else: - await ctx.send(Texts('admin').get("Unable to find the user...")) + except discord.errors.NotFound: + await ctx.send(Texts('utils').get("Unable to find the user...")) """---------------------------------------------------------------------""" @commands.command(name='kick') async def _kick(self, ctx: commands.Context, user: discord.User, *, reason=""): - member: discord.Member = await ctx.guild.fetch_member(user.id) + try: + member: discord.Member = await ctx.guild.fetch_member(user.id) - if member: try: await member.kick(reason=reason) e: discord.Embed = await self.kick_ban_message( @@ -105,9 +133,9 @@ class Admin(commands.Cog): await ctx.send(embed=e) except discord.Forbidden: - await ctx.send(Texts('admin').get("Unable to ban this user")) - else: - await ctx.send(Texts('admin').get("Unable to find the user...")) + await ctx.send(Texts('admin').get("Unable to kick this user")) + except discord.errors.NotFound: + await ctx.send(Texts('utils').get("Unable to find the user...")) """---------------------------------------------------------------------""" @@ -130,15 +158,24 @@ class Admin(commands.Cog): async def _react_add(self, ctx: commands.Context, message_id: int, *, emojis: str): emojis: list = emojis.split(' ') - message: discord.Message = await ctx.channel.fetch_message(message_id) - for emoji in emojis: - await message.add_reaction(emoji) + try: + message: discord.Message = await ctx.channel.fetch_message( + message_id) + + for emoji in emojis: + await message.add_reaction(emoji) + except discord.errors.NotFound: + await ctx.send(Texts('utils').get("Unable to find the message")) @_react.command(name='clear') async def _react_remove(self, ctx: commands.Context, message_id: int): - message: discord.Message = await ctx.channel.fetch_message(message_id) - await message.clear_reactions() + try: + message: discord.Message = await ctx.channel.fetch_message( + message_id) + await message.clear_reactions() + except discord.errors.NotFound: + await ctx.send(Texts('utils').get("Unable to find the message")) """---------------------------------------------------------------------""" diff --git a/locales/en/LC_MESSAGES/admin.po b/locales/en/LC_MESSAGES/admin.po index e824822..12b07d3 100644 --- a/locales/en/LC_MESSAGES/admin.po +++ b/locales/en/LC_MESSAGES/admin.po @@ -21,5 +21,5 @@ msgstr "" msgid "Unable to ban this user" msgstr "" -msgid "Unable to find the user..." +msgid "Unable to kick this user" msgstr "" \ No newline at end of file diff --git a/locales/en/LC_MESSAGES/utils.mo b/locales/en/LC_MESSAGES/utils.mo new file mode 100644 index 0000000000000000000000000000000000000000..e56e9c9c4f698196d1c9f23390bf6da85a3ddd45 GIT binary patch literal 363 zcmYjM!A`?43>^}u9yxQ!f!lCNCy=(VO$%!_D$;i9x=C;gn<+&jt0ZI9WJ`&UtGF+;z;ObD^tDU&O)?@Et;mRG$SiMf8a|&wjx_c zY2vNY9OedK>b)OC>bwbGSv+TC~=^h2oAWk9Vf%Ec2sx^EMkG&`o6g%<%Gsgx zD^pCpIEuy5ec)4XUTKTk-DqoP*5a4Fst>Bvw`BLKOoMi^$rms@>N+nkXh7&)wJ&wS f$nd$e-V!w$_wXL>T1M)&K-(?z>y`xmjo14HFE3?c literal 0 HcmV?d00001 diff --git a/locales/en/LC_MESSAGES/utils.po b/locales/en/LC_MESSAGES/utils.po new file mode 100644 index 0000000..01482bf --- /dev/null +++ b/locales/en/LC_MESSAGES/utils.po @@ -0,0 +1,22 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2019-09-08 19:04+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" + + +msgid "Unable to find the user..." +msgstr "" + +msgid "Unable to find the message" +msgstr "" \ No newline at end of file diff --git a/locales/fr/LC_MESSAGES/admin.mo b/locales/fr/LC_MESSAGES/admin.mo index 13bb393553ca810e15c1d5d40c6d01cd068d22e5..139da3d412f105c10f9a7065cadff84a814a6a36 100644 GIT binary patch delta 97 zcmX@fa-3y?iK+wx14B0u+cGjRECJGzK>P^ERsqs~fV3)*R-71V!14B0u+cGjRECbS#K>P&ARsqugfV3)*R-PDXBaoJvm!eRTk*ZKy roLZ!(r?+u&8>3vRLQ1MaNl|`jS!$6&j(TZHW=>{tVo7Q#NCg7`GEW(c diff --git a/locales/fr/LC_MESSAGES/admin.po b/locales/fr/LC_MESSAGES/admin.po index e6eeaca..338992d 100644 --- a/locales/fr/LC_MESSAGES/admin.po +++ b/locales/fr/LC_MESSAGES/admin.po @@ -21,5 +21,5 @@ msgstr "Merci d'entrer une raison" msgid "Unable to ban this user" msgstr "Impossible de bannir cet utilisateur" -msgid "Unable to find the user..." -msgstr "Impossibe de trouver l'utilisateur..." \ No newline at end of file +msgid "Unable to kick this user" +msgstr "Impossible d'expulser cet utilisateur" \ No newline at end of file diff --git a/locales/fr/LC_MESSAGES/utils.mo b/locales/fr/LC_MESSAGES/utils.mo new file mode 100644 index 0000000000000000000000000000000000000000..332a6c26004e31d0443a3894e6117b14108e91f6 GIT binary patch literal 520 zcmZuu%Wm5+5LA(#bj&fxVJ}4w0ae*>0b6+>s?E4UB+Kv%Xl{(Pkr~LOKvF?`?l!!G;EfqbeH-hY@tc&VYq<`_LIgVec&Lh9L>r44-7%Wv~0e;~C3xHj3eU9%aed zT|VJ{Dy(A*Bb2R#(v`TUBcs%&Tmwm`9sAdM&EW$W!C zO|L5%Xj5MKS(5R0_njd0hgvyQ^v13xvksr#m%0*Cox^$~j74|3T->n!yRP-}fQE6k z)`e7M1pRyI{4pvtG;qPb?INgmCAzj*Q174, YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2019-09-08 19:04+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" + + +msgid "Unable to find the user..." +msgstr "Impossibe de trouver l'utilisateur..." + +msgid "Unable to find the message" +msgstr "Impossible de trouver le message" \ No newline at end of file