Lua socket irc twitch bot 没有被 ping 到?
Lua socket irc twitch bot not getting pinged?
local Bot = {
Channel = "#*twitch_channel*",
Name = "smmchrisbot",
Pass = "oauth:*code*",
Server = "irc.chat.twitch.tv",
Port = 6667
}
local socket = require("socket")
local client,err = socket.tcp()
if not client then
error(err)
end
Bot.Client = client
function Bot.Pingpong(self)
print("Fire") --Does print
local msg = Bot.Client:receive("*l") --Doesn't get anthing?
print(msg)
if msg == "PING :tmi.twitch.tv" then
Bot.Client:send("PONG :tmi.twitch.tv")
end
end
--function Bot.Chat(self,msg)
--Bot.Client:send("PRIVMSG "..Channel.." :"..msg.."\r\n\r\n")
--end
Bot.Client:settimeout(1)
Bot.Client:connect(Bot.Server, Bot.Port)
Bot:Pingpong()
Bot.Client:send("PASS "..Bot.Pass)
Bot:Pingpong()
Bot.Client:send("NICK "..Bot.Name)
Bot:Pingpong()
Bot.Client:send("JOIN "..Bot.Channel)
while true do
Bot:Pingpong()
sleep(1)
--Bot:Chat(io.read())
end
它打印 "Fire" 然后 nil,一遍又一遍。有人知道为什么吗?
答案其实很简单!我只需要在我的密码和其他东西的末尾连接“\r\n”!
local Bot = {
Channel = "#*twitch_channel*",
Name = "smmchrisbot",
Pass = "oauth:*code*",
Server = "irc.chat.twitch.tv",
Port = 6667
}
local socket = require("socket")
local client,err = socket.tcp()
if not client then
error(err)
end
Bot.Client = client
function Bot.Pingpong(self)
print("Fire") --Does print
local msg = Bot.Client:receive("*l") --Doesn't get anthing?
print(msg)
if msg == "PING :tmi.twitch.tv" then
Bot.Client:send("PONG :tmi.twitch.tv")
end
end
--function Bot.Chat(self,msg)
--Bot.Client:send("PRIVMSG "..Channel.." :"..msg.."\r\n\r\n")
--end
Bot.Client:settimeout(1)
Bot.Client:connect(Bot.Server, Bot.Port)
Bot:Pingpong()
Bot.Client:send("PASS "..Bot.Pass)
Bot:Pingpong()
Bot.Client:send("NICK "..Bot.Name)
Bot:Pingpong()
Bot.Client:send("JOIN "..Bot.Channel)
while true do
Bot:Pingpong()
sleep(1)
--Bot:Chat(io.read())
end
它打印 "Fire" 然后 nil,一遍又一遍。有人知道为什么吗?
答案其实很简单!我只需要在我的密码和其他东西的末尾连接“\r\n”!