diff --git a/sweebot.py b/sweebot.py index 61b1900..efaad1f 100644 --- a/sweebot.py +++ b/sweebot.py @@ -851,41 +851,47 @@ while True: try: for i in command: parse = urlparse(i) - if parse.scheme == "gemini": - gsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - gemsocket = ssl.wrap_socket(gsocket) - gemsocket.connect((parse.hostname, 1965)) - gemsocket.send(bytes(i + "\r\n", "UTF-8")) - received = "" - while True: - gemresponse = gemsocket.recv(2048) - if gemresponse: - received += gemresponse.decode() - else: - 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 + while True: + if parse.scheme == "gemini": + gsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + gemsocket = ssl.wrap_socket(gsocket) + gemsocket.connect((parse.hostname, 1965)) + gemsocket.send(bytes(i + "\r\n", "UTF-8")) + received = "" + while True: + gemresponse = gemsocket.recv(2048) + if gemresponse: + received += gemresponse.decode() 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: - multiline("(" + nick + ") [No title found]", channel) + received = received.replace("\r", "") + firstline = True + title = False + redirected = False + for i in received.split("\n"): + if firstline: + 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: exc = str(ex) multiline("(" + nick + f") [Request error: {exc}]", channel)