update(doc|readme): Add cogs.admin's commands todo

refactor(command|admin): rewrite some of all admin's command
This commit is contained in:
Romain J 2019-09-13 11:20:17 +02:00
parent d6f155e682
commit d0a9e658a6
9 changed files with 121 additions and 22 deletions

View file

@ -27,4 +27,22 @@
## Ultimate : ## Ultimate :
- [ ] Send email or Telegram's message when something is wrong on the bot - [ ] 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,...))
---
# 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

View file

@ -1,4 +1,5 @@
import datetime import datetime
from typing import Union
import discord import discord
from discord.ext import commands from discord.ext import commands
@ -55,22 +56,49 @@ class Admin(commands.Cog):
"""---------------------------------------------------------------------""" """---------------------------------------------------------------------"""
@commands.command(name='say') @commands.group(name='say', invoke_without_command=True)
async def _say(self, ctx: commands.Context, *, to_say: str): async def _say(self, ctx: commands.Context, *, content: str):
try: try:
await ctx.message.delete() await ctx.message.delete()
await ctx.send(to_say)
except discord.errors.Forbidden: 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') @commands.command(name='ban')
async def _ban(self, ctx: commands.Context, user: discord.User, *, async def _ban(self, ctx: commands.Context, user: discord.User, *,
reason=""): 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: try:
await member.ban(reason=reason) await member.ban(reason=reason)
e: discord.Embed = await self.kick_ban_message( e: discord.Embed = await self.kick_ban_message(
@ -83,17 +111,17 @@ class Admin(commands.Cog):
await ctx.send(embed=e) await ctx.send(embed=e)
except discord.Forbidden: except discord.Forbidden:
await ctx.send(Texts('admin').get("Unable to ban this user")) await ctx.send(Texts('admin').get("Unable to ban this user"))
else: except discord.errors.NotFound:
await ctx.send(Texts('admin').get("Unable to find the user...")) await ctx.send(Texts('utils').get("Unable to find the user..."))
"""---------------------------------------------------------------------""" """---------------------------------------------------------------------"""
@commands.command(name='kick') @commands.command(name='kick')
async def _kick(self, ctx: commands.Context, user: discord.User, *, async def _kick(self, ctx: commands.Context, user: discord.User, *,
reason=""): 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: try:
await member.kick(reason=reason) await member.kick(reason=reason)
e: discord.Embed = await self.kick_ban_message( e: discord.Embed = await self.kick_ban_message(
@ -105,9 +133,9 @@ class Admin(commands.Cog):
await ctx.send(embed=e) await ctx.send(embed=e)
except discord.Forbidden: except discord.Forbidden:
await ctx.send(Texts('admin').get("Unable to ban this user")) await ctx.send(Texts('admin').get("Unable to kick this user"))
else: except discord.errors.NotFound:
await ctx.send(Texts('admin').get("Unable to find the user...")) 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, *, async def _react_add(self, ctx: commands.Context, message_id: int, *,
emojis: str): emojis: str):
emojis: list = emojis.split(' ') emojis: list = emojis.split(' ')
message: discord.Message = await ctx.channel.fetch_message(message_id)
for emoji in emojis: try:
await message.add_reaction(emoji) 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') @_react.command(name='clear')
async def _react_remove(self, ctx: commands.Context, message_id: int): async def _react_remove(self, ctx: commands.Context, message_id: int):
message: discord.Message = await ctx.channel.fetch_message(message_id) try:
await message.clear_reactions() 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"))
"""---------------------------------------------------------------------""" """---------------------------------------------------------------------"""

View file

@ -21,5 +21,5 @@ msgstr ""
msgid "Unable to ban this user" msgid "Unable to ban this user"
msgstr "" msgstr ""
msgid "Unable to find the user..." msgid "Unable to kick this user"
msgstr "" msgstr ""

Binary file not shown.

View file

@ -0,0 +1,22 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""

Binary file not shown.

View file

@ -21,5 +21,5 @@ msgstr "Merci d'entrer une raison"
msgid "Unable to ban this user" msgid "Unable to ban this user"
msgstr "Impossible de bannir cet utilisateur" msgstr "Impossible de bannir cet utilisateur"
msgid "Unable to find the user..." msgid "Unable to kick this user"
msgstr "Impossibe de trouver l'utilisateur..." msgstr "Impossible d'expulser cet utilisateur"

Binary file not shown.

View file

@ -0,0 +1,22 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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"