Update server.py

This commit is contained in:
Nova Cat 2025-01-08 21:53:04 -08:00
parent 30b55d2a26
commit cc8a70333f

View file

@ -2,7 +2,7 @@
__version__ = "0.0.1-pre-alpha" __version__ = "0.0.1-pre-alpha"
print(f"Codename IRCat v{__version__}") print(f"Codename IRCat v{__version__}")
print("Welcome! /ᐠ ˵> ⩊ <˵マ") print("Welcome! /ᐠ ˵> ⩊ <˵マ")
import socket, ssl, time, threading, traceback, sys, subprocess, yaml, sqlite3, os, bcrypt import socket, ssl, time, threading, traceback, sys, subprocess, yaml, sqlite3, os, bcrypt, importlib.util
from requests import get from requests import get
if not len(sys.argv) == 2: if not len(sys.argv) == 2:
print("IRCat requires the following arguments: config.yml") print("IRCat requires the following arguments: config.yml")
@ -25,6 +25,8 @@ ping_timeout = 255
restrict_ip = '' restrict_ip = ''
global banlist global banlist
banlist = {} banlist = {}
global mods
mods = {"sql_provider": None, "command": [], "allsocket": [], "banprovider": None}
def updateklines(): def updateklines():
global banlist global banlist
try: try:
@ -73,30 +75,36 @@ with open(sys.argv[1], 'r') as file:
try: ssl_pkey = data["ssl_pkey"] try: ssl_pkey = data["ssl_pkey"]
except: except:
print("IRCat needs an SSL Private Key to use SSL!") print("IRCat needs an SSL Private Key to use SSL!")
try: modules = data["modules"]
except:
print("IRCat needs at least one module enabled.")
sys.exit(1)
updateklines() updateklines()
file.close() file.close()
print("Successfully loaded config!") print("Successfully loaded config!")
class IRCat_DATA_BROKER: for i in modules:
def __init__(self): if not os.path.isabs(i):
if not os.path.isfile(data_path): i = "modules/" + i
print("Creating database file...") try:
open(data_path, "w").write("") print(f"Importing module {i}...")
self.conn = sqlite3.connect(data_path) temp_module = importlib.import_module(i)
db = self.conn.cursor() if temp_module.__ircat_type__ == "sql.provider":
print("Creating NickServ table...") global modules
db.execute("""CREATE table IF NOT EXISTS nickserv (user varchar(255), modes varchar(255), hash varchar(255), cloak varchar(255))""") if modules["sql_provider"] != None:
print("Creating Groups table...") modules["sql_provider"] = temp_module
db.execute("""CREATE table IF NOT EXISTS groups (name varchar(255), owner varchar(255))""") else:
print("Creating ChanServ table...") raise Exception(f"Tried to import {i} as an SQL provider, but something's already the SQL provider.")
db.execute("""CREATE table IF NOT EXISTS chanserv (name varchar(255), modes varchar(255), params varchar(255), owner varchar(255), usermodes varchar(255), optimodes varchar(255))""") elif temp_module.__ircat_type__ == "command":
def nickserv_identify(self, nick, password:str): global modules
db = self.conn.cursor() modules["command"].append(temp_module)
password = password.encode("UTF-8") except:
db.execute("SELECT * FROM nickserv WHERE user=?;", [nick]) print(f"Module {i} failed to load.")
if db.fetchall() == []: print(traceback.format_exc())
return ["Nickname doesn't exist."] sys.exit(1)
if modules["sql_provider"] == None:
config = IRCat_DATA_BROKER() print("IRCat needs an SQL provider.")
sys.exit(1)
config = modules["sql_provider"].broker()
sockets = {} sockets = {}
sockets_ssl = {} sockets_ssl = {}
# Open the specified non-SSL sockets. # Open the specified non-SSL sockets.