Update modules/ban_engine.py

This commit is contained in:
Nova Cat 2025-01-10 18:54:51 -08:00
parent efff8c0904
commit d525b4a91e

View file

@ -12,26 +12,29 @@ class IRCatModule:
self.useSQLengine = True self.useSQLengine = True
self.SQLengine = sql self.SQLengine = sql
def onValidate(self, socket, ip): def onValidate(self, socket, ip):
print("IP is banned, killing connection now...") bans = open(self.ban_provider).read().split("\n")
reason = " ".join(i.split(" ")[1:]) for i in bans:
host = self.host if ip in i.split(" ")[0]:
socket.sendall(bytes(f":{host} 465 * :You are banned from this server\r\n","UTF-8")) print("IP is banned, killing connection now...")
socket.sendall(bytes(f"ERROR :Closing Link: {ip} (K-Lined: {reason})\r\n","UTF-8")) reason = " ".join(i.split(" ")[1:])
raise Exception("K-Lined: " + " ".join(i.split(" ")[1:])) host = self.host
def onSocket(self, socket, value, ip, cachedNick=None): socket.sendall(bytes(f":{host} 465 * :You are banned from this server\r\n","UTF-8"))
if self.useSQLengine: socket.sendall(bytes(f"ERROR :Closing Link: {ip} (K-Lined: {reason})\r\n","UTF-8"))
pass raise Exception("K-Lined: " + " ".join(i.split(" ")[1:]))
else: def onSocket(self, socket, value, ip, cachedNick=None, validated=False):
bans = open(self.ban_provider).read().split("\n") if validated:
for i in bans: if self.useSQLengine:
if ip in i.split(" ")[0]: pass
print("IP is banned, killing connection now...") else:
reason = " ".join(i.split(" ")[1:]) bans = open(self.ban_provider).read().split("\n")
host = self.host for i in bans:
socket.sendall(bytes(f":{host} 465 * :You are banned from this server\r\n","UTF-8")) if ip in i.split(" ")[0]:
socket.sendall(bytes(f"ERROR :Closing Link: {ip} (K-Lined: {reason})\r\n","UTF-8")) print("IP is banned, killing connection now...")
raise Exception("Banned: " + " ".join(i.split(" ")[1:])) reason = " ".join(i.split(" ")[1:])
pass host = self.host
socket.sendall(bytes(f":{host} 465 * :You are banned from this server\r\n","UTF-8"))
socket.sendall(bytes(f"ERROR :Closing Link: {ip} (K-Lined: {reason})\r\n","UTF-8"))
raise Exception("Banned: " + " ".join(i.split(" ")[1:]))
def ban(self, target_mask, reason="The ban() hammer has spoken!"): def ban(self, target_mask, reason="The ban() hammer has spoken!"):
if self.useSQLengine: if self.useSQLengine:
cur = self.SQLengine.conn.cursor() cur = self.SQLengine.conn.cursor()