summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--notcqst.py70
1 files changed, 50 insertions, 20 deletions
diff --git a/notcqst.py b/notcqst.py
index b5cc1b7..c07ff91 100644
--- a/notcqst.py
+++ b/notcqst.py
@@ -1,11 +1,24 @@
import socket
import random
+import time
from yt_dlp import YoutubeDL
+reconnect = 0
+text_str = 0
+server = "irc.libera.chat"
+channel = "##tech-tangents"
+botnick = "notcqst"
+
+irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+user_str = ("USER " + botnick + " " + botnick + " " + botnick + " :" + botnick + "\n")
+nick_str = ("NICK " + botnick + "\n")
+channel_string = ("JOIN " + channel + "\n")
+send_to_channel_str = ("PRIVMSG " + channel + " :Hello " + "\r\n")
+
def check_youtube():
if "https://youtube.com" in text_str or "https://www.youtube.com" in text_str:
- split_str = text_str.split('##tech-tangents :')
+ split_str = text_str.split('https://')
vid_url = split_str[1].strip()
with YoutubeDL() as ydl:
info_dict = ydl.extract_info(vid_url, download=False)
@@ -55,31 +68,48 @@ def parse_cmd():
check_youtube()
-server = "irc.libera.chat"
-channel = "##tech-tangents"
-botnick = "notcqst"
-
-irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+def connect_checked():
+ if reconnect >= 3:
+ exit(1)
+ else:
+ irc.connect((server, 6667))
+ irc.send(bytes(user_str, 'utf-8'))
+ irc.send(bytes(nick_str, 'utf-8'))
+ irc.send(bytes(channel_string, 'utf-8'))
+ irc.send(bytes(send_to_channel_str, 'utf-8'))
+ connect_loop()
+
+
+def connect_loop():
+ while 1:
+ text = irc.recv(2040)
+ if not text:
+ break
+ print(text)
+ global text_str
+ text_str = text.decode("utf-8")
+ parse_cmd()
+ irc.close()
+ global reconnect
+ reconnect += 1
+ sleep(10)
+ connect_checked()
-user_str = ("USER " + botnick + " " + botnick + " " + botnick + " :" + botnick + "\n")
-nick_str = ("NICK " + botnick + "\n")
-channel_string = ("JOIN " + channel + "\n")
-send_to_channel_str = ("PRIVMSG " + channel + " :Hello " + "\r\n")
print("connecting to: " + server)
+connect_checked()
+
+
+
+
+
+
+
+
+
-irc.connect((server, 6667))
-irc.send(bytes(user_str, 'utf-8'))
-irc.send(bytes(nick_str, 'utf-8'))
-irc.send(bytes(channel_string, 'utf-8'))
-irc.send(bytes(send_to_channel_str, 'utf-8'))
-while 1:
- text = irc.recv(2040)
- print(text)
- text_str = text.decode("utf-8")
- parse_cmd()