1
1
""""
2
- Copyright © Krypton 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
2
+ Copyright © Krypton 2019- 2022 - https://github.com/kkrypt0nn (https://krypton.ninja)
3
3
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 .
5
5
6
- Version: 5.4
6
+ Version: 5.4.1
7
7
"""
8
8
9
+ import os
10
+
9
11
import aiosqlite
10
12
13
+ DATABASE_PATH = f"{ os .path .realpath (os .path .dirname (__file__ ))} /database/database.db"
14
+
11
15
12
16
async def is_blacklisted (user_id : int ) -> bool :
13
17
"""
@@ -16,7 +20,7 @@ async def is_blacklisted(user_id: int) -> bool:
16
20
:param user_id: The ID of the user that should be checked.
17
21
:return: True if the user is blacklisted, False if not.
18
22
"""
19
- async with aiosqlite .connect ("database/database.db" ) as db :
23
+ async with aiosqlite .connect (DATABASE_PATH ) as db :
20
24
async with db .execute ("SELECT * FROM blacklist WHERE user_id=?" , (user_id ,)) as cursor :
21
25
result = await cursor .fetchone ()
22
26
return result is not None
@@ -28,7 +32,7 @@ async def add_user_to_blacklist(user_id: int) -> int:
28
32
29
33
:param user_id: The ID of the user that should be added into the blacklist.
30
34
"""
31
- async with aiosqlite .connect ("database/database.db" ) as db :
35
+ async with aiosqlite .connect (DATABASE_PATH ) as db :
32
36
await db .execute ("INSERT INTO blacklist(user_id) VALUES (?)" , (user_id ,))
33
37
await db .commit ()
34
38
rows = await db .execute ("SELECT COUNT(*) FROM blacklist" )
@@ -43,7 +47,7 @@ async def remove_user_from_blacklist(user_id: int) -> int:
43
47
44
48
:param user_id: The ID of the user that should be removed from the blacklist.
45
49
"""
46
- async with aiosqlite .connect ("database/database.db" ) as db :
50
+ async with aiosqlite .connect (DATABASE_PATH ) as db :
47
51
await db .execute ("DELETE FROM blacklist WHERE user_id=?" , (user_id ,))
48
52
await db .commit ()
49
53
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)
59
63
:param user_id: The ID of the user that should be warned.
60
64
:param reason: The reason why the user should be warned.
61
65
"""
62
- async with aiosqlite .connect ("database/database.db" ) as db :
66
+ async with aiosqlite .connect (DATABASE_PATH ) as db :
63
67
rows = await db .execute ("SELECT id FROM warns WHERE user_id=? AND server_id=? ORDER BY id DESC LIMIT 1" , (user_id , server_id ,))
64
68
async with rows as cursor :
65
69
result = await cursor .fetchone ()
@@ -77,7 +81,7 @@ async def remove_warn(warn_id: int, user_id: int, server_id: int) -> int:
77
81
:param user_id: The ID of the user that was warned.
78
82
:param server_id: The ID of the server where the user has been warned
79
83
"""
80
- async with aiosqlite .connect ("database/database.db" ) as db :
84
+ async with aiosqlite .connect (DATABASE_PATH ) as db :
81
85
await db .execute ("DELETE FROM warns WHERE id=? AND user_id=? AND server_id=?" , (warn_id , user_id , server_id ,))
82
86
await db .commit ()
83
87
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:
94
98
:param server_id: The ID of the server that should be checked.
95
99
:return: A list of all the warnings of the user.
96
100
"""
97
- async with aiosqlite .connect ("database/database.db" ) as db :
101
+ async with aiosqlite .connect (DATABASE_PATH ) as db :
98
102
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 ,))
99
103
async with rows as cursor :
100
104
result = await cursor .fetchall ()
101
105
result_list = []
102
106
for row in result :
103
107
result_list .append (row )
104
- return result_list
108
+ return result_list
0 commit comments