Skip to content

Commit 9997176

Browse files
committed
🏷️ Template v5.4.1
1 parent 729fd69 commit 9997176

File tree

10 files changed

+47
-39
lines changed

10 files changed

+47
-39
lines changed

UPDATES.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

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

5+
### Version 5.4.1 (22 December 2022)
6+
7+
* Loading files relatively to where the `bot.py` file is located, so that you can start the bot from anywhere in your system
8+
59
### Version 5.4 (8 December 2022)
610

711
* Added `@commands.bot_has_permissions()` checks and handle the exception for it

bot.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
2-
Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
2+
Copyright © Krypton 2019-2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
33
Description:
4-
This is a template to create your own discord bot in python.
4+
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4
6+
Version: 5.4.1
77
"""
88

99
import asyncio
@@ -20,10 +20,10 @@
2020

2121
import exceptions
2222

23-
if not os.path.isfile("config.json"):
23+
if not os.path.isfile(f"{os.path.realpath(os.path.dirname(__file__))}/config.json"):
2424
sys.exit("'config.json' not found! Please add it and try again.")
2525
else:
26-
with open("config.json") as file:
26+
with open(f"{os.path.realpath(os.path.dirname(__file__))}/config.json") as file:
2727
config = json.load(file)
2828

2929
"""
@@ -74,8 +74,8 @@
7474

7575

7676
async def init_db():
77-
async with aiosqlite.connect("database/database.db") as db:
78-
with open("database/schema.sql") as file:
77+
async with aiosqlite.connect(f"{os.path.realpath(os.path.dirname(__file__))}/database/database.db") as db:
78+
with open(f"{os.path.realpath(os.path.dirname(__file__))}/database/schema.sql") as file:
7979
await db.executescript(file.read())
8080
await db.commit()
8181

@@ -213,7 +213,7 @@ async def load_cogs() -> None:
213213
"""
214214
The code in this function is executed whenever the bot will start.
215215
"""
216-
for file in os.listdir(f"./cogs"):
216+
for file in os.listdir(f"{os.path.realpath(os.path.dirname(__file__))}/cogs"):
217217
if file.endswith(".py"):
218218
extension = file[:-3]
219219
try:

cogs/fun.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""""
2-
Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
2+
Copyright © Krypton 2019-2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
33
Description:
4-
This is a template to create your own discord bot in python.
4+
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4
6+
Version: 5.4.1
77
"""
88

99
import random

cogs/general.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""""
2-
Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
2+
Copyright © Krypton 2019-2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
33
Description:
4-
This is a template to create your own discord bot in python.
4+
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4
6+
Version: 5.4.1
77
"""
88

99
import platform

cogs/moderation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""""
2-
Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
2+
Copyright © Krypton 2019-2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
33
Description:
4-
This is a template to create your own discord bot in python.
4+
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4
6+
Version: 5.4.1
77
"""
88

99
import discord

cogs/owner.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""""
2-
Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
2+
Copyright © Krypton 2019-2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
33
Description:
4-
This is a template to create your own discord bot in python.
4+
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4
6+
Version: 5.4.1
77
"""
88

99
import discord

cogs/template.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""""
2-
Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
2+
Copyright © Krypton 2019-2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
33
Description:
4-
This is a template to create your own discord bot in python.
4+
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4
6+
Version: 5.4.1
77
"""
88

99
from discord.ext import commands

exceptions/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""""
2-
Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
2+
Copyright © Krypton 2019-2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
33
Description:
4-
This is a template to create your own discord bot in python.
4+
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4
6+
Version: 5.4.1
77
"""
88

99
from discord.ext import commands

helpers/checks.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
""""
2-
Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
2+
Copyright © Krypton 2019-2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
33
Description:
4-
This is a template to create your own discord bot in python.
4+
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4
6+
Version: 5.4.1
77
"""
88

99
import json

helpers/db_manager.py

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
""""
2-
Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
2+
Copyright © Krypton 2019-2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
33
Description:
4-
This is a template to create your own discord bot in python.
4+
🐍 A simple template to start to code your own and personalized discord bot in Python programming language.
55
6-
Version: 5.4
6+
Version: 5.4.1
77
"""
88

9+
import os
10+
911
import aiosqlite
1012

13+
DATABASE_PATH = f"{os.path.realpath(os.path.dirname(__file__))}/database/database.db"
14+
1115

1216
async def is_blacklisted(user_id: int) -> bool:
1317
"""
@@ -16,7 +20,7 @@ async def is_blacklisted(user_id: int) -> bool:
1620
:param user_id: The ID of the user that should be checked.
1721
:return: True if the user is blacklisted, False if not.
1822
"""
19-
async with aiosqlite.connect("database/database.db") as db:
23+
async with aiosqlite.connect(DATABASE_PATH) as db:
2024
async with db.execute("SELECT * FROM blacklist WHERE user_id=?", (user_id,)) as cursor:
2125
result = await cursor.fetchone()
2226
return result is not None
@@ -28,7 +32,7 @@ async def add_user_to_blacklist(user_id: int) -> int:
2832
2933
:param user_id: The ID of the user that should be added into the blacklist.
3034
"""
31-
async with aiosqlite.connect("database/database.db") as db:
35+
async with aiosqlite.connect(DATABASE_PATH) as db:
3236
await db.execute("INSERT INTO blacklist(user_id) VALUES (?)", (user_id,))
3337
await db.commit()
3438
rows = await db.execute("SELECT COUNT(*) FROM blacklist")
@@ -43,7 +47,7 @@ async def remove_user_from_blacklist(user_id: int) -> int:
4347
4448
:param user_id: The ID of the user that should be removed from the blacklist.
4549
"""
46-
async with aiosqlite.connect("database/database.db") as db:
50+
async with aiosqlite.connect(DATABASE_PATH) as db:
4751
await db.execute("DELETE FROM blacklist WHERE user_id=?", (user_id,))
4852
await db.commit()
4953
rows = await db.execute("SELECT COUNT(*) FROM blacklist")
@@ -59,7 +63,7 @@ async def add_warn(user_id: int, server_id: int, moderator_id: int, reason: str)
5963
:param user_id: The ID of the user that should be warned.
6064
:param reason: The reason why the user should be warned.
6165
"""
62-
async with aiosqlite.connect("database/database.db") as db:
66+
async with aiosqlite.connect(DATABASE_PATH) as db:
6367
rows = await db.execute("SELECT id FROM warns WHERE user_id=? AND server_id=? ORDER BY id DESC LIMIT 1", (user_id, server_id,))
6468
async with rows as cursor:
6569
result = await cursor.fetchone()
@@ -77,7 +81,7 @@ async def remove_warn(warn_id: int, user_id: int, server_id: int) -> int:
7781
:param user_id: The ID of the user that was warned.
7882
:param server_id: The ID of the server where the user has been warned
7983
"""
80-
async with aiosqlite.connect("database/database.db") as db:
84+
async with aiosqlite.connect(DATABASE_PATH) as db:
8185
await db.execute("DELETE FROM warns WHERE id=? AND user_id=? AND server_id=?", (warn_id, user_id, server_id,))
8286
await db.commit()
8387
rows = await db.execute("SELECT COUNT(*) FROM warns WHERE user_id=? AND server_id=?", (user_id, server_id,))
@@ -94,11 +98,11 @@ async def get_warnings(user_id: int, server_id: int) -> list:
9498
:param server_id: The ID of the server that should be checked.
9599
:return: A list of all the warnings of the user.
96100
"""
97-
async with aiosqlite.connect("database/database.db") as db:
101+
async with aiosqlite.connect(DATABASE_PATH) as db:
98102
rows = await db.execute("SELECT user_id, server_id, moderator_id, reason, strftime('%s', created_at), id FROM warns WHERE user_id=? AND server_id=?", (user_id, server_id,))
99103
async with rows as cursor:
100104
result = await cursor.fetchall()
101105
result_list = []
102106
for row in result:
103107
result_list.append(row)
104-
return result_list
108+
return result_list

0 commit comments

Comments
 (0)