This commit is contained in:
Nova Cat 2024-12-09 18:27:40 -08:00
parent 923ae1cbcf
commit dde81e5df9

View file

@ -2,7 +2,7 @@
__version__ = "0.0.1-pre-alpha"
print(f"INTERNET RELAY CAT v{__version__}")
print("Welcome! /ᐠ ˵> ⩊ <˵マ")
import socket, time, threading, traceback, sys, os, yaml
import socket, time, threading, traceback, sys, subprocess, yaml
from requests import get
if not len(sys.argv) == 2:
print("IRCat requires the following arguments: config.yml")
@ -148,6 +148,9 @@ def session(connection, client):
property_list[pending]["last_ping"] = time.time()
property_list[pending]["ping_pending"] = False
elif command == "PART":
if len(args) == 0:
connection.sendall(bytes(f":{server} {pending} 461 {command} :Not enough parameters\r\n","UTF-8"))
else:
channel = text.split(" ")[1]
for i in channels_list[channel]:
try:
@ -159,6 +162,9 @@ def session(connection, client):
except:
print(traceback.format_exc())
elif command == "WHO":
if len(args) == 0:
connection.sendall(bytes(f":{server} {pending} 461 {command} :Not enough parameters\r\n","UTF-8"))
else:
channel = text.split(" ")[1]
if channel in channels_list:
for i in channels_list[channel]:
@ -174,6 +180,9 @@ def session(connection, client):
connection.sendall(bytes(f":{server} 366 {pending} {channel} :End of /WHO list.\r\n","UTF-8"))
elif command == "WHOIS":
if len(args) == 0:
connection.sendall(bytes(f":{server} {pending} 461 {command} :Not enough parameters\r\n","UTF-8"))
else:
target = text.split(" ")[1]
if target in property_list:
who_user = property_list[target]["username"]
@ -187,6 +196,9 @@ def session(connection, client):
else:
connection.sendall(bytes(f":{server} 401 {pending} {target} :No such nick/channel\r\n","UTF-8"))
elif command == "NAMES":
if len(args) == 0:
connection.sendall(bytes(f":{server} {pending} 461 {command} :Not enough parameters\r\n","UTF-8"))
else:
channel = text.split(" ")[1]
if channel in channels_list:
if pending in channels_list[channel]:
@ -194,6 +206,7 @@ def session(connection, client):
connection.sendall(bytes(f":{server} 353 {pending} = {channel} :{users}\r\n","UTF-8"))
connection.sendall(bytes(f":{server} 366 {pending} {channel} :End of /NAMES list.\r\n","UTF-8"))
elif command == "PRIVMSG":
if len(args) >= 2:
target = text.split(" ")[1]
if target in channels_list:
if pending in channels_list[target]:
@ -207,7 +220,10 @@ def session(connection, client):
nickname_list[target].sendall(bytes(f":{pending}!~{username}@{hostname} {text}\r\n","UTF-8"))
else:
connection.sendall(bytes(f":{server} 401 {pending} {target} :No such nick/channel\r\n","UTF-8"))
else:
connection.sendall(bytes(f":{server} {pending} 461 {command} :Not enough parameters\r\n","UTF-8"))
elif command == "NOTICE":
if len(args) >= 2:
target = text.split(" ")[1]
if target in channels_list:
if pending in channels_list[target]:
@ -221,6 +237,8 @@ def session(connection, client):
nickname_list[target].sendall(bytes(f":{pending}!~{username}@{hostname} {text}\r\n","UTF-8"))
else:
connection.sendall(bytes(f":{server} 401 {pending} {target} :No such nick/channel\r\n","UTF-8"))
else:
connection.sendall(bytes(f":{server} {pending} 461 {command} :Not enough parameters\r\n","UTF-8"))
elif command == "QUIT":
# Parse the quit message.
done = []
@ -253,7 +271,22 @@ def session(connection, client):
safe_quit = True
break
elif command == "GITSERV":
connection.sendall(bytes(f":GitServ!~IRCat@IRCatCore NOTICE {pending} :Hello!\r\n","UTF-8"))
if len(args) == 0:
connection.sendall(bytes(f":{server} {pending} 461 {command} :Not enough parameters\r\n","UTF-8"))
elif args[0].upper() == "PULL":
updater = subprocess.run(["git", "pull"])
if updater.stdout.decode().strip() == "Already up to date.":
connection.sendall(bytes(f":GitServ!~IRCat@IRCatCore NOTICE {pending} :IRCat is already up-to-date.\r\n","UTF-8"))
else:
connection.sendall(bytes(f":GitServ!~IRCat@IRCatCore NOTICE {pending} :Done, it is recommended to use /UPDATE if you're an IRC op\r\n","UTF-8"))
elif args[0].upper() == "VERSION":
connection.sendall(bytes(f":GitServ!~IRCat@IRCatCore NOTICE {pending} :Codename IRCat version {__version__}\r\n","UTF-8"))
connection.sendall(bytes(f":GitServ!~IRCat@IRCatCore NOTICE {pending} :This is Codename IRCat's integrated services.\r\n","UTF-8"))
else:
connection.sendall(bytes(f":GitServ!~IRCat@IRCatCore NOTICE {pending} :GitServ Usage:\r\n","UTF-8"))
connection.sendall(bytes(f":GitServ!~IRCat@IRCatCore NOTICE {pending} :PULL - Pulls the latest version of Codename IRCat\r\n","UTF-8"))
connection.sendall(bytes(f":GitServ!~IRCat@IRCatCore NOTICE {pending} :VERSION - Gets the version number of this service.\r\n","UTF-8"))