Facing difficulties sending bytes containing white spaces python irc bot
0
votes
1
answer
214
views
Trying to make a basic irc bot in python (3.9.2) that can response specific commands when invoked. It works although when a response contains whitespace or a space, only the first word gets displayed by the bot, for example;
me > @hello
bot > hi
me > @how is the weather?
bot > the
it was supposed to say, the weather seems nice today
Here's the code
import sys
import time
import socket
import string
server_address="irc.libera.chat"
server_port = 6667
botnick="lamebot"
channel_name="##megadouched"
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((server_address,server_port))
irc.setblocking(False)
time.sleep(1)
irc.send(bytes("USER "+botnick+" "+botnick+" "+botnick+" bot has joined the chat\r\n", "UTF-8"))
time.sleep(1)
irc.send(bytes("NICK "+botnick+"\n", "UTF-8"))
time.sleep(1)
irc.send(bytes("JOIN "+channel_name+"\n", "UTF-8"))
irc_privmsg = 'b"PRIVMSG "+channel_name+" Hello\r\n"'
while True:
try:
text = irc.recv(4096)
except Exception:
pass
if text.find(bytes(":@hi", "UTF-8"))!=-1:
irc.sendall(bytes("PRIVMSG "+channel_name+" Hello\r\n", "UTF-8"))
text=b""
elif text.find(bytes(":@how is the weather?", "UTF-8"))!=-1:
irc.sendall(bytes("PRIVMSG "+channel_name+" the weather today seems nice\r\n", "UTF-8"))
text=b""
input()
Asked by atheros
(256 rep)
Jul 19, 2022, 01:56 PM
Last activity: Jul 19, 2022, 06:18 PM
Last activity: Jul 19, 2022, 06:18 PM