-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.py
72 lines (50 loc) · 2.12 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
import sqlite3
from sqlite3 import Error
db_file = "serverinfo.db"
try:
conn = sqlite3.connect(db_file)
c = conn.cursor()
print("Connected to SQL")
except Error as e:
print(e)
def GetServer(guildid):
c.execute("SELECT * FROM {tn} WHERE {idf}={my_id}".\
format(tn="server", idf="ID", my_id=guildid))
return c.fetchone()
def ClearServer(guildid, channelname, prefix, ownerid):
c.execute("UPDATE server SET DefaultChannel = ?, Prefix = ?, OwnerID = ?, President = 'null', VicePresident = 'null', Secretary = 'null' WHERE id = ?", (channelname, prefix, ownerid, guildid))
conn.commit()
def SetServer(guildid, channelname, prefix, ownerid):
c.execute("INSERT INTO server (id, DefaultChannel, Prefix, OwnerID) VALUES (?, ?, ?, ?)", (guildid, channelname, prefix, ownerid))
conn.commit()
def FindUser(id):
c.execute("SELECT * FROM {tn} WHERE {idf}={my_id}".\
format(tn='users', idf='UserID', my_id=id))
return c.fetchone()
def SetPrefix(prefix, server):
input = "'{}'".format(prefix)
var = "UPDATE server SET Prefix = {data} WHERE ID = {serverid}".format(data=input, serverid=server)
c.execute(var)
conn.commit()
def SetDefaultChannel(channel, server):
input = "'{}'".format(channel)
var = "UPDATE server SET DefaultChannel = {data} WHERE ID = {serverid}".format(data=input, serverid=server)
c.execute(var)
conn.commit()
def AddAdmin(id, role, server):
var = "UPDATE server SET {role2} = {userid} WHERE ID = {serverid}".format(role2=role, userid=id, serverid=server)
c.execute(var)
conn.commit()
def RemoveAdmin(role, server):
var = "UPDATE server SET {role2} = {userid} WHERE ID = {serverid}".format(role2=role, userid='null', serverid=server)
c.execute(var)
conn.commit()
def InsertUser(userid, name):
input = "'{}'".format(name)
var = "INSERT INTO {tn} ({col0}, {col1}) VALUES ({id}, {user})".\
format(tn='users', col0='UserID', col1='Username', id=userid, user=input)
c.execute(var)
conn.commit()
def RemoveUser(userid):
c.execute("DELETE FROM users WHERE UserID = {0}".format(userid))
conn.commit()