More SQLite3 use
This commit is contained in:
parent
2caffd84bd
commit
d387efe3b3
1 changed files with 38 additions and 53 deletions
79
sweebot.py
79
sweebot.py
|
@ -16,12 +16,33 @@ class config:
|
||||||
self.database = self.conn.cursor()
|
self.database = self.conn.cursor()
|
||||||
def perms(self, cloak: str):
|
def perms(self, cloak: str):
|
||||||
try:
|
try:
|
||||||
self.database.execute(f"SELECT * FROM users WHERE username = '{cloak}';")
|
self.database.execute(f"SELECT * FROM users WHERE username = ?;", (cloak))
|
||||||
output = self.database.fetchall()
|
output = self.database.fetchall()
|
||||||
return output[0][1]
|
return output[0][1]
|
||||||
except:
|
except:
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
return ''
|
return ''
|
||||||
|
def chansettings(self, chan: str):
|
||||||
|
try:
|
||||||
|
self.database.execute("SELECT * FROM chans WHERE chan = ?;", (chan))
|
||||||
|
output = self.database.fetchall()
|
||||||
|
temp = output[0][1].split(",")
|
||||||
|
return temp if temp != [''] else []
|
||||||
|
except:
|
||||||
|
print(traceback.format_exc())
|
||||||
|
return []
|
||||||
|
def setchanconfig(self, chan: str, flags: list):
|
||||||
|
try:
|
||||||
|
if self.chansettings(chan) == []:
|
||||||
|
print("[!!!] Channel doesn't exist in config")
|
||||||
|
self.database.execute("INSERT INTO chans (chan, flags) values(?, '+config');", (chan))
|
||||||
|
flag = self.chansettings(chan) + flags
|
||||||
|
self.database.execute("UPDATE chans SET FLAGS = ? WHERE chan = ?", (",".join(flag),chan))
|
||||||
|
|
||||||
|
except:
|
||||||
|
print(traceback.format_exc())
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
# Code snippet from my buddy Irish
|
# Code snippet from my buddy Irish
|
||||||
# Define a dictionary to map terminal color codes to IRC color codes
|
# Define a dictionary to map terminal color codes to IRC color codes
|
||||||
|
@ -467,47 +488,19 @@ while True:
|
||||||
|
|
||||||
|
|
||||||
elif command[0] == "$config":
|
elif command[0] == "$config":
|
||||||
if perms == "full":
|
|
||||||
try:
|
try:
|
||||||
#if True:
|
|
||||||
if len(command) > 2:
|
if len(command) > 2:
|
||||||
if command[1] == "colonthree":
|
if perms == "full":
|
||||||
file = open("/home/swee/chans").read().split("\n")
|
pass
|
||||||
file2 = open("/home/swee/chanconfig").read().split("\n")
|
|
||||||
|
|
||||||
if command[2] == "1":
|
|
||||||
if not channel in file:
|
|
||||||
file.append(channel)
|
|
||||||
print(file)
|
|
||||||
file2.append("100000000")
|
|
||||||
print(file2)
|
|
||||||
else:
|
|
||||||
file2[file.index(channel)]="1" + file2[file.index(channel)][1:]
|
|
||||||
print("\n".join(file))
|
|
||||||
open("/home/swee/chans", 'w').write("\n".join(file))
|
|
||||||
|
|
||||||
open("/home/swee/chanconfig", 'w').write("\n".join(file2))
|
|
||||||
irc.send_irc(channel, nick + ": Config complete, I will now use the colonthree function in " + channel)
|
|
||||||
elif command[2] == "0":
|
|
||||||
if not channel in file:
|
|
||||||
file.append(channel)
|
|
||||||
file2.append("000000000")
|
|
||||||
else:
|
|
||||||
file2[file.index(channel)]="0" + file2[file.index(channel)][1:]
|
|
||||||
open("/home/swee/chans", 'w').write("\n".join(file))
|
|
||||||
open("/home/swee/chanconfig", 'w').write("\n".join(file2))
|
|
||||||
irc.send_irc(channel, nick + ": Config complete, I will no longer use the colonthree function in " + channel)
|
|
||||||
else:
|
|
||||||
irc.send_irc(channel, nick + ": Values are: 1, 0")
|
|
||||||
else:
|
|
||||||
irc.send_irc(channel, nick + ": Not enough arguments")
|
|
||||||
except Exception as ex:
|
|
||||||
irc.send_irc(channel, nick + ": " + ex.__class__.__name__)
|
|
||||||
else:
|
else:
|
||||||
irc.send_irc(channel, nick + ": Permission denied")
|
irc.send_irc(channel, nick + ": Permission denied")
|
||||||
block+=1
|
block+=1
|
||||||
run-=1
|
run-=1
|
||||||
update()
|
update()
|
||||||
|
else:
|
||||||
|
multiline("Configuration for " + channel + ": " + " ".join(sbconfig.chansettings(channel)), channel)
|
||||||
|
except ex:
|
||||||
|
multiline(str(ex), channel)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -542,19 +535,11 @@ while True:
|
||||||
|
|
||||||
|
|
||||||
elif command[0] == ":3":
|
elif command[0] == ":3":
|
||||||
if channel in open("/home/swee/chans").read().split("\n"):
|
if not "-colonthree" in sbconfig.chansettings(channel):
|
||||||
print()
|
multiline(":3", channel)
|
||||||
if open("/home/swee/chanconfig").read().split("\n")[open("/home/swee/chans").read().split("\n").index(channel)][0] == "1":
|
|
||||||
irc.send_irc(channel, ":3")
|
|
||||||
else:
|
|
||||||
irc.send_irc(channel, ":3")
|
|
||||||
elif ":3c" in command:
|
elif ":3c" in command:
|
||||||
if channel in open("/home/swee/chans").read().split("\n"):
|
if not "-colonthree" in sbconfig.chansettings(channel):
|
||||||
print()
|
multiline(choice(threes), channel)
|
||||||
if open("/home/swee/chanconfig").read().split("\n")[open("/home/swee/chans").read().split("\n").index(channel)][0] == "1":
|
|
||||||
irc.send_irc(channel, choice(threes))
|
|
||||||
else:
|
|
||||||
irc.send_irc(channel, choice(threes))
|
|
||||||
elif "JOIN" in text and "#nixsanctuary" in text:
|
elif "JOIN" in text and "#nixsanctuary" in text:
|
||||||
nick = text.split(":")[1].split("!")[0]
|
nick = text.split(":")[1].split("!")[0]
|
||||||
if not "swee" in nick:
|
if not "swee" in nick:
|
||||||
|
|
Loading…
Reference in a new issue