Skip to content

Commit

Permalink
🏷️ Template v5.4.2
Browse files Browse the repository at this point in the history
* Added `blacklist show` command to see the list of blacklisted users
* `blacklist remove` and `blacklist add` commands now send proper error messages
  • Loading branch information
kkrypt0nn committed Jan 6, 2023
1 parent b2e62c7 commit 0b11555
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 13 deletions.
5 changes: 5 additions & 0 deletions UPDATES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cogs/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cogs/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 38 additions & 5 deletions cogs/owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <t:{bluser[1]}>")
embed.description = "\n".join(users)
await context.send(embed=embed)

@blacklist.command(
base="blacklist",
name="add",
Expand All @@ -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)
Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion cogs/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion helpers/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion helpers/db_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 0b11555

Please sign in to comment.