-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
85 lines (77 loc) · 2.45 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sqlite3
db_file_name = 'data.db'
# Query the DB and Return All Records
def show_all():
global db_file_name
conn = sqlite3.connect(db_file_name)
c = conn.cursor()
c.execute("SELECT rowid, * FROM data")
items = c.fetchall()
conn.commit()
conn.close()
return items
def show_all_server_specific(guild_id):
global db_file_name
conn = sqlite3.connect(db_file_name)
c = conn.cursor()
c.execute("SELECT commands, text_from_command FROM data WHERE guild_id = (?)", (guild_id,))
info = c.fetchall()
conn.commit()
conn.close()
return info
# Add A New Record To The Table
def add_record(record_info):
global db_file_name
conn = sqlite3.connect(db_file_name)
c = conn.cursor()
c.execute("INSERT INTO data VALUES (?, ?, ?)", record_info)
conn.commit()
conn.close()
def delete_record(guild_id, command):
global db_file_name
conn = sqlite3.connect(db_file_name)
c = conn.cursor()
if command_check(guild_id, command) == 'exists':
c.execute("DELETE FROM data WHERE guild_id = (?) AND commands = (?)", (guild_id, command))
conn.commit()
conn.close()
else:
conn.commit()
conn.close()
return 'There is no command with this name on your server'
# Looks For A Specific Command
def command_lookup(guild_id, command):
global db_file_name
conn = sqlite3.connect(db_file_name)
c = conn.cursor()
c.execute("SELECT text_from_command FROM data WHERE guild_id = (?) AND commands = (?)", (guild_id, command))
info = c.fetchone()
conn.commit()
conn.close()
return info
# Checks If A guild_id Is Saved In DB
def guildID_check(guild_id):
global db_file_name
conn = sqlite3.connect(db_file_name)
c = conn.cursor()
c.execute("SELECT EXISTS(SELECT 1 FROM data WHERE guild_id = ?)", (guild_id,))
exists = c.fetchone()
conn.commit()
conn.close()
if exists:
return 'exists'
else:
return 'not found'
# Checks If A command Is Saved In DB
def command_check(guild_id, command):
global db_file_name
conn = sqlite3.connect(db_file_name)
c = conn.cursor()
c.execute("SELECT EXISTS(SELECT 1 FROM data WHERE guild_id = (?) and commands = (?) )", (guild_id, command))
exists = c.fetchone()
conn.commit()
conn.close()
if exists:
return 'exists'
else:
return 'not found'