From 0b115557e6da576c8df5361dc51f6edb3235997d Mon Sep 17 00:00:00 2001 From: Krypton Date: Fri, 6 Jan 2023 13:25:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F=20Template=20v5.4.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added `blacklist show` command to see the list of blacklisted users * `blacklist remove` and `blacklist add` commands now send proper error messages --- UPDATES.md | 5 +++++ bot.py | 2 +- cogs/fun.py | 2 +- cogs/general.py | 2 +- cogs/moderation.py | 2 +- cogs/owner.py | 43 +++++++++++++++++++++++++++++++++++++----- cogs/template.py | 2 +- exceptions/__init__.py | 2 +- helpers/checks.py | 2 +- helpers/db_manager.py | 15 ++++++++++++++- 10 files changed, 64 insertions(+), 13 deletions(-) diff --git a/UPDATES.md b/UPDATES.md index 97e1a253..01068fd6 100644 --- a/UPDATES.md +++ b/UPDATES.md @@ -2,6 +2,11 @@ Here is the list of all the updates that I made on this template. +### Version 5.4.2 (06 January 2023) + +* Added `blacklist show` command to see the list of blacklisted users +* `blacklist remove` and `blacklist add` commands now send proper error messages + ### Version 5.4.1 (22 December 2022) * Loading files relatively to where the `bot.py` file is located, so that you can start the bot from anywhere in your system diff --git a/bot.py b/bot.py index d55b30d4..d1d1e6d5 100644 --- a/bot.py +++ b/bot.py @@ -3,7 +3,7 @@ Description: 🐍 A simple template to start to code your own and personalized discord bot in Python programming language. -Version: 5.4.1 +Version: 5.4.2 """ import asyncio diff --git a/cogs/fun.py b/cogs/fun.py index 55c62b04..cb07edef 100644 --- a/cogs/fun.py +++ b/cogs/fun.py @@ -3,7 +3,7 @@ Description: 🐍 A simple template to start to code your own and personalized discord bot in Python programming language. -Version: 5.4.1 +Version: 5.4.2 """ import random diff --git a/cogs/general.py b/cogs/general.py index 4180e4fa..b316ff25 100644 --- a/cogs/general.py +++ b/cogs/general.py @@ -3,7 +3,7 @@ Description: 🐍 A simple template to start to code your own and personalized discord bot in Python programming language. -Version: 5.4.1 +Version: 5.4.2 """ import platform diff --git a/cogs/moderation.py b/cogs/moderation.py index 2f28cdcb..86c431eb 100644 --- a/cogs/moderation.py +++ b/cogs/moderation.py @@ -3,7 +3,7 @@ Description: 🐍 A simple template to start to code your own and personalized discord bot in Python programming language. -Version: 5.4.1 +Version: 5.4.2 """ import discord diff --git a/cogs/owner.py b/cogs/owner.py index 708cbf2f..164870da 100644 --- a/cogs/owner.py +++ b/cogs/owner.py @@ -3,7 +3,7 @@ Description: 🐍 A simple template to start to code your own and personalized discord bot in Python programming language. -Version: 5.4.1 +Version: 5.4.2 """ import discord @@ -260,6 +260,39 @@ async def blacklist(self, context: Context) -> None: ) await context.send(embed=embed) + @blacklist.command( + base="blacklist", + name="show", + description="Shows the list of all blacklisted users.", + ) + @checks.is_owner() + async def blacklist_show(self, context: Context) -> None: + """ + Shows the list of all blacklisted users. + + :param context: The hybrid command context. + """ + blacklisted_users = await db_manager.get_blacklisted_users() + if len(blacklisted_users) == 0: + embed = discord.Embed( + description="There are currently no blacklisted users.", + color=0xE02B2B + ) + await context.send(embed=embed) + return + + embed = discord.Embed( + title="Blacklisted users", + color=0x9C84EF + ) + users = [] + for bluser in blacklisted_users: + user = self.bot.get_user(int(bluser[0])) or await self.bot.fetch_user(int(bluser[0])) + users.append( + f"• {user.mention} ({user}) - Blacklisted ") + embed.description = "\n".join(users) + await context.send(embed=embed) + @blacklist.command( base="blacklist", name="add", @@ -278,7 +311,7 @@ async def blacklist_add(self, context: Context, user: discord.User) -> None: if await db_manager.is_blacklisted(user_id): embed = discord.Embed( title="Error!", - description=f"**{user.name}** is not in the blacklist.", + description=f"**{user.name}** is already in the blacklist.", color=0xE02B2B ) await context.send(embed=embed) @@ -290,7 +323,7 @@ async def blacklist_add(self, context: Context, user: discord.User) -> None: color=0x9C84EF ) embed.set_footer( - text=f"There are now {total} {'user' if total == 1 else 'users'} in the blacklist" + text=f"There {'is' if total == 1 else 'are'} now {total} {'user' if total == 1 else 'users'} in the blacklist" ) await context.send(embed=embed) @@ -312,7 +345,7 @@ async def blacklist_remove(self, context: Context, user: discord.User) -> None: if not await db_manager.is_blacklisted(user_id): embed = discord.Embed( title="Error!", - description=f"**{user.name}** is already in the blacklist.", + description=f"**{user.name}** is not in the blacklist.", color=0xE02B2B ) await context.send(embed=embed) @@ -324,7 +357,7 @@ async def blacklist_remove(self, context: Context, user: discord.User) -> None: color=0x9C84EF ) embed.set_footer( - text=f"There are now {total} {'user' if total == 1 else 'users'} in the blacklist" + text=f"There {'is' if total == 1 else 'are'} now {total} {'user' if total == 1 else 'users'} in the blacklist" ) await context.send(embed=embed) diff --git a/cogs/template.py b/cogs/template.py index be427124..924d413e 100644 --- a/cogs/template.py +++ b/cogs/template.py @@ -3,7 +3,7 @@ Description: 🐍 A simple template to start to code your own and personalized discord bot in Python programming language. -Version: 5.4.1 +Version: 5.4.2 """ from discord.ext import commands diff --git a/exceptions/__init__.py b/exceptions/__init__.py index f143be08..a77a4366 100644 --- a/exceptions/__init__.py +++ b/exceptions/__init__.py @@ -3,7 +3,7 @@ Description: 🐍 A simple template to start to code your own and personalized discord bot in Python programming language. -Version: 5.4.1 +Version: 5.4.2 """ from discord.ext import commands diff --git a/helpers/checks.py b/helpers/checks.py index dd1d3736..25df99c4 100644 --- a/helpers/checks.py +++ b/helpers/checks.py @@ -3,7 +3,7 @@ Description: 🐍 A simple template to start to code your own and personalized discord bot in Python programming language. -Version: 5.4.1 +Version: 5.4.2 """ import json diff --git a/helpers/db_manager.py b/helpers/db_manager.py index 2fd0c90b..5045c410 100644 --- a/helpers/db_manager.py +++ b/helpers/db_manager.py @@ -3,7 +3,7 @@ Description: 🐍 A simple template to start to code your own and personalized discord bot in Python programming language. -Version: 5.4.1 +Version: 5.4.2 """ import os @@ -13,6 +13,19 @@ DATABASE_PATH = f"{os.path.realpath(os.path.dirname(__file__))}/../database/database.db" +async def get_blacklisted_users() -> list: + """ + This function will return the list of all blacklisted users. + + :param user_id: The ID of the user that should be checked. + :return: True if the user is blacklisted, False if not. + """ + async with aiosqlite.connect(DATABASE_PATH) as db: + async with db.execute("SELECT user_id, strftime('%s', created_at) FROM blacklist") as cursor: + result = await cursor.fetchall() + return result + + async def is_blacklisted(user_id: int) -> bool: """ This function will check if a user is blacklisted.