diff --git a/sweebot.py b/sweebot.py index 3a1f50f..cb1ac92 100644 --- a/sweebot.py +++ b/sweebot.py @@ -16,12 +16,33 @@ class config: self.database = self.conn.cursor() def perms(self, cloak: str): 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() return output[0][1] except: print(traceback.format_exc()) 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 # Define a dictionary to map terminal color codes to IRC color codes @@ -467,47 +488,19 @@ while True: elif command[0] == "$config": - if perms == "full": - try: - #if True: - if len(command) > 2: - if command[1] == "colonthree": - file = open("/home/swee/chans").read().split("\n") - 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") + try: + if len(command) > 2: + if perms == "full": + pass else: - irc.send_irc(channel, nick + ": Not enough arguments") - except Exception as ex: - irc.send_irc(channel, nick + ": " + ex.__class__.__name__) - else: - irc.send_irc(channel, nick + ": Permission denied") - block+=1 - run-=1 - update() + irc.send_irc(channel, nick + ": Permission denied") + block+=1 + run-=1 + 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": - if channel in open("/home/swee/chans").read().split("\n"): - print() - 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") + if not "-colonthree" in sbconfig.chansettings(channel): + multiline(":3", channel) elif ":3c" in command: - if channel in open("/home/swee/chans").read().split("\n"): - print() - 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)) + if not "-colonthree" in sbconfig.chansettings(channel): + multiline(choice(threes), channel) elif "JOIN" in text and "#nixsanctuary" in text: nick = text.split(":")[1].split("!")[0] if not "swee" in nick: