Skip to content

Commit 0b11555

Browse files
committed
🏷️ Template v5.4.2
* Added `blacklist show` command to see the list of blacklisted users * `blacklist remove` and `blacklist add` commands now send proper error messages
1 parent b2e62c7 commit 0b11555

File tree

10 files changed

+64
-13
lines changed

10 files changed

+64
-13
lines changed

UPDATES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
Here is the list of all the updates that I made on this template.
44

5+
### Version 5.4.2 (06 January 2023)
6+
7+
* Added `blacklist show` command to see the list of blacklisted users
8+
* `blacklist remove` and `blacklist add` commands now send proper error messages
9+
510
### Version 5.4.1 (22 December 2022)
611

712
* Loading files relatively to where the `bot.py` file is located, so that you can start the bot from anywhere in your system

bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4.1
6+
Version: 5.4.2
77
"""
88

99
import asyncio

cogs/fun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4.1
6+
Version: 5.4.2
77
"""
88

99
import random

cogs/general.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4.1
6+
Version: 5.4.2
77
"""
88

99
import platform

cogs/moderation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4.1
6+
Version: 5.4.2
77
"""
88

99
import discord

cogs/owner.py

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4.1
6+
Version: 5.4.2
77
"""
88

99
import discord
@@ -260,6 +260,39 @@ async def blacklist(self, context: Context) -> None:
260260
)
261261
await context.send(embed=embed)
262262

263+
@blacklist.command(
264+
base="blacklist",
265+
name="show",
266+
description="Shows the list of all blacklisted users.",
267+
)
268+
@checks.is_owner()
269+
async def blacklist_show(self, context: Context) -> None:
270+
"""
271+
Shows the list of all blacklisted users.
272+
273+
:param context: The hybrid command context.
274+
"""
275+
blacklisted_users = await db_manager.get_blacklisted_users()
276+
if len(blacklisted_users) == 0:
277+
embed = discord.Embed(
278+
description="There are currently no blacklisted users.",
279+
color=0xE02B2B
280+
)
281+
await context.send(embed=embed)
282+
return
283+
284+
embed = discord.Embed(
285+
title="Blacklisted users",
286+
color=0x9C84EF
287+
)
288+
users = []
289+
for bluser in blacklisted_users:
290+
user = self.bot.get_user(int(bluser[0])) or await self.bot.fetch_user(int(bluser[0]))
291+
users.append(
292+
f"• {user.mention} ({user}) - Blacklisted <t:{bluser[1]}>")
293+
embed.description = "\n".join(users)
294+
await context.send(embed=embed)
295+
263296
@blacklist.command(
264297
base="blacklist",
265298
name="add",
@@ -278,7 +311,7 @@ async def blacklist_add(self, context: Context, user: discord.User) -> None:
278311
if await db_manager.is_blacklisted(user_id):
279312
embed = discord.Embed(
280313
title="Error!",
281-
description=f"**{user.name}** is not in the blacklist.",
314+
description=f"**{user.name}** is already in the blacklist.",
282315
color=0xE02B2B
283316
)
284317
await context.send(embed=embed)
@@ -290,7 +323,7 @@ async def blacklist_add(self, context: Context, user: discord.User) -> None:
290323
color=0x9C84EF
291324
)
292325
embed.set_footer(
293-
text=f"There are now {total} {'user' if total == 1 else 'users'} in the blacklist"
326+
text=f"There {'is' if total == 1 else 'are'} now {total} {'user' if total == 1 else 'users'} in the blacklist"
294327
)
295328
await context.send(embed=embed)
296329

@@ -312,7 +345,7 @@ async def blacklist_remove(self, context: Context, user: discord.User) -> None:
312345
if not await db_manager.is_blacklisted(user_id):
313346
embed = discord.Embed(
314347
title="Error!",
315-
description=f"**{user.name}** is already in the blacklist.",
348+
description=f"**{user.name}** is not in the blacklist.",
316349
color=0xE02B2B
317350
)
318351
await context.send(embed=embed)
@@ -324,7 +357,7 @@ async def blacklist_remove(self, context: Context, user: discord.User) -> None:
324357
color=0x9C84EF
325358
)
326359
embed.set_footer(
327-
text=f"There are now {total} {'user' if total == 1 else 'users'} in the blacklist"
360+
text=f"There {'is' if total == 1 else 'are'} now {total} {'user' if total == 1 else 'users'} in the blacklist"
328361
)
329362
await context.send(embed=embed)
330363

cogs/template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4.1
6+
Version: 5.4.2
77
"""
88

99
from discord.ext import commands

exceptions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4.1
6+
Version: 5.4.2
77
"""
88

99
from discord.ext import commands

helpers/checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4.1
6+
Version: 5.4.2
77
"""
88

99
import json

helpers/db_manager.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4.1
6+
Version: 5.4.2
77
"""
88

99
import os
@@ -13,6 +13,19 @@
1313
DATABASE_PATH = f"{os.path.realpath(os.path.dirname(__file__))}/../database/database.db"
1414

1515

16+
async def get_blacklisted_users() -> list:
17+
"""
18+
This function will return the list of all blacklisted users.
19+
20+
:param user_id: The ID of the user that should be checked.
21+
:return: True if the user is blacklisted, False if not.
22+
"""
23+
async with aiosqlite.connect(DATABASE_PATH) as db:
24+
async with db.execute("SELECT user_id, strftime('%s', created_at) FROM blacklist") as cursor:
25+
result = await cursor.fetchall()
26+
return result
27+
28+
1629
async def is_blacklisted(user_id: int) -> bool:
1730
"""
1831
This function will check if a user is blacklisted.

0 commit comments

Comments
 (0)