Update sweebot.py
Some checks are pending
Check syntax / check (push) Waiting to run

This commit is contained in:
Nova Cat 2025-01-12 20:32:31 -08:00
parent e39f9c3f94
commit a45796883e

View file

@ -851,41 +851,47 @@ while True:
try: try:
for i in command: for i in command:
parse = urlparse(i) parse = urlparse(i)
if parse.scheme == "gemini": while True:
gsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if parse.scheme == "gemini":
gemsocket = ssl.wrap_socket(gsocket) gsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
gemsocket.connect((parse.hostname, 1965)) gemsocket = ssl.wrap_socket(gsocket)
gemsocket.send(bytes(i + "\r\n", "UTF-8")) gemsocket.connect((parse.hostname, 1965))
received = "" gemsocket.send(bytes(i + "\r\n", "UTF-8"))
while True: received = ""
gemresponse = gemsocket.recv(2048) while True:
if gemresponse: gemresponse = gemsocket.recv(2048)
received += gemresponse.decode() if gemresponse:
else: received += gemresponse.decode()
break
received = received.replace("\r", "")
firstline = True
title = False
for i in received.split("\n"):
if firstline:
if i.split(" ")[0][0] != "2":
title = True
multiline("(" + nick + f") [{i}]", channel)
break
else: else:
firstline = False
if i.split(" ")[1] != "text/gemini":
typee = i.split(" ")[1]
multiline("(" + nick + f") [Non-Gemtext file: {typee}]", channel)
title = True
break break
else: received = received.replace("\r", "")
if i.split(" ")[0][0] == "#": firstline = True
title = True title = False
multiline("(" + nick + f") " + i[2:], channel) redirected = False
break for i in received.split("\n"):
if not title: if firstline:
multiline("(" + nick + ") [No title found]", channel) if i.split(" ")[0][0] == "3":
redirected = True
parsed = urlparse(i.split(" ")[2])
break
elif i.split(" ")[0][0] != "2":
title = True
multiline("(" + nick + f") [{i}]", channel)
break
else:
firstline = False
if i.split(" ")[1] != "text/gemini":
typee = i.split(" ")[1]
multiline("(" + nick + f") [Non-Gemtext file: {typee}]", channel)
title = True
break
else:
if i.split(" ")[0][0] == "#":
title = True
multiline("(" + nick + f") " + i[2:], channel)
break
if not title and not redirected:
multiline("(" + nick + ") [No title found]", channel)
except Exception as ex: except Exception as ex:
exc = str(ex) exc = str(ex)
multiline("(" + nick + f") [Request error: {exc}]", channel) multiline("(" + nick + f") [Request error: {exc}]", channel)