I am using python to connect to my channel and (among other things in the future) send messages to the channel. What I have works, except I cannot see the message until I reload the page in the browser. Upon reload, I see the message. A friend of mine observed the same behavior. Chat in my channel and others works as expected otherwise - it has something to do with how I am sending it in python.
I use send_message(irc, message) to encode and then send the message and I call it in join_chat(). Here is the full code:
from dotenv import load_dotenv
import os
import socket
load_dotenv()
SERVER=os.getenv("SERVER")
PORT=int(os.getenv("PORT"))
OAUTH=os.getenv("OAUTH")
BOT_NAME=os.getenv("BOT_NAME")
CHANNEL=os.getenv("CHANNEL")
OWNER=os.getenv("OWNER")
irc=socket.socket()
irc.connect((SERVER, PORT))
irc.send(( "PASS " + OAUTH + "\n" +
"NICK " + BOT_NAME + "\n" +
"JOIN #" + CHANNEL + "\n").encode())
def join_chat():
loaded = False
while not loaded:
# saves 1024 bytes at a time
readbuffer_join = irc.recv(1024).decode()
# split into lines and discard last line (empty)
for line in readbuffer_join.split('\n')[:-1]:
print(line)
loaded = check_load_complete(line)
def check_load_complete(line):
if 'End of /NAMES list' not in line: return False
print(f'{BOT_NAME} joined {CHANNEL}\'s channel')
send_message(irc, f'{BOT_NAME} joined the channel')
return True
def send_message(irc, message):
message = (f'PRIVMSG #{CHANNEL} :{message}\n').encode()
irc.send(message)
join_chat()
I have tried as many variations of message as I could think of. breaking the encoding to a separate line., using \r instead of or in addition to \n, getting rid of \n, string concat instead of fstrings, etc. Of course the message getting sent must be valid because I do see it after reload, so maybe something is wrong with the state of irc when I call send_message(irc, "some message")?
Thanks Barry that actually explains a lot. It must be relatively new - the guide I’m watching doesn’t have the same issue (~2017). I wonder what constitutes “quiet”.
I did a quick search to answer that same question (can you send a message via the API) and evidently I came to the wrong conclusion! I guess I wouldn’t.
I marked your initial response as the solution. Thanks for the clarification on my follow-up questions.
I found my problem - it’s not related to a quiet chat but I will report my findings because there is something I find odd about it. Also, another symptom I observed is that I could not read anything from the socket buffer.
My NICK in my python script included a capital. When I changed it to lowercase it worked. What I find odd is that it seems new accounts can be made with capital letters but it seems they get converted to all lowercase. That’s how I noticed - I made a new account with capitals, saw it got converted, then used lowercase. Then I thought to use lowercase on my old account and it worked.
I’m getting the buffer and printing it as shown in my original post. Which shows:
:tmi.twitch.tv 001 nonethewiserer :Welcome, GLHF!
:tmi.twitch.tv 002 nonethewiserer :Your host is tmi.twitch.tv
:tmi.twitch.tv 003 nonethewiserer :This server is rather new
:tmi.twitch.tv 004 nonethewiserer :-
:tmi.twitch.tv 375 nonethewiserer :-
:tmi.twitch.tv 372 nonethewiserer :You are in a maze of twisty passages, all alike.
:tmi.twitch.tv 376 nonethewiserer :>
:nonethewiserer!nonethewiserer@nonethewiserer.tmi.twitch.tv JOIN #Nonethewiserer
:nonethewiserer.tmi.twitch.tv 353 nonethewiserer = #Nonethewiserer :nonethewiserer
:nonethewiserer.tmi.twitch.tv 366 nonethewiserer #Nonethewiserer :End of /NAMES list
Jukebox joined Nonethewiserer’s channel
Not sure if this is expected or not. I don’t quite understand how I provide Nonethewiserer and see JOIN #Nonethewiserer on the fourth to last line of the output, when - like you say - it should be lowercase. I’m not looking for an explanation (you’ve been very helpful already) - I’m just sharing this information because I can’t square it. Maybe it makes perfect sense though. Anyways, now I cannot reproduce the successful message sent after refresh after retesting.