From 90ec23ae26af49c167e9bbe000eeb40520db95c3 Mon Sep 17 00:00:00 2001 From: cqst Date: Fri, 22 Aug 2025 18:21:30 -0700 Subject: better chooser --- notcqst.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'notcqst.py') diff --git a/notcqst.py b/notcqst.py index ab07897..b16c1b4 100644 --- a/notcqst.py +++ b/notcqst.py @@ -1,8 +1,12 @@ import socket import random -from time import sleep +import time from yt_dlp import YoutubeDL + +# TODO eradicate global variables +# TODO add SSL support + reconnect = 0 text_str = 0 server = "irc.libera.chat" @@ -16,10 +20,23 @@ channel_string = ("JOIN " + channel + "\n") send_to_channel_str = ("PRIVMSG " + channel + " :Hello " + "\r\n") +def ping(): + if "PING" in text_str: + split_str = text_str.split(" ") + print(split_str) + print(split_str) + print(split_str) + print(split_str) + print(split_str) + print("PONG\n") + irc.send((bytes("PONG :" + split_str[1] + "\r\n", 'utf-8'))) + + def check_youtube(): if "https://youtube.com" in text_str or "https://www.youtube.com" in text_str: split_str = text_str.split('https://') - vid_url = split_str[1].strip() + vid_url_www = split_str[1].strip() + vid_url = ''.join(("https://", vid_url_www)) with YoutubeDL() as ydl: info_dict = ydl.extract_info(vid_url, download=False) video_url = info_dict.get("url", None) @@ -33,13 +50,7 @@ def check_youtube(): def command_choose(split_spaces): - print(split_spaces) - arr_hack = len(split_spaces) - arr_hack -= 2 - choices = [] - for x in range(arr_hack): - choices.append(split_spaces[x+2]) - print(choices) + choices = split_spaces[2:] decision = random.choice(choices) irc.send((bytes("PRIVMSG " + channel + " :" + decision + "\r\n", 'utf-8'))) @@ -64,6 +75,7 @@ def command_flag(): def parse_cmd(): + ping() command_flag() check_youtube() @@ -92,7 +104,7 @@ def connect_loop(): irc.close() global reconnect reconnect += 1 - sleep(10) + time.sleep(10) connect_checked() -- cgit v1.2.3