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 0000000..e56e9c9 Binary files /dev/null and b/locales/en/LC_MESSAGES/utils.mo differ 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 13bb393..139da3d 100644 Binary files a/locales/fr/LC_MESSAGES/admin.mo and b/locales/fr/LC_MESSAGES/admin.mo differ 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 0000000..332a6c2 Binary files /dev/null and b/locales/fr/LC_MESSAGES/utils.mo differ diff --git a/locales/fr/LC_MESSAGES/utils.po b/locales/fr/LC_MESSAGES/utils.po new file mode 100644 index 0000000..9a8d3e6 --- /dev/null +++ b/locales/fr/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 "Impossibe de trouver l'utilisateur..." + +msgid "Unable to find the message" +msgstr "Impossible de trouver le message" \ No newline at end of file