Changed a bit of style stuff, tweaked verify calls here and there

This commit is contained in:
Jakob Ovrum 2010-07-19 07:46:55 +09:00
parent 145aa5b3eb
commit a37a7618ce
2 changed files with 7 additions and 13 deletions

View File

@ -7,11 +7,7 @@ local meta = _META
function meta:send(fmt, ...) function meta:send(fmt, ...)
local bytes, err = self.socket:send(fmt:format(...) .. "\r\n") local bytes, err = self.socket:send(fmt:format(...) .. "\r\n")
if bytes then if not bytes and err ~= "timeout" and err ~= "wantwrite" then
return
end
if err ~= "timeout" and err ~= "wantwrite" then
self:invoke("OnDisconnect", err, true) self:invoke("OnDisconnect", err, true)
self:shutdown() self:shutdown()
error(err, errlevel) error(err, errlevel)
@ -27,14 +23,12 @@ local function verify(str, errLevel)
end end
function meta:sendChat(target, msg) function meta:sendChat(target, msg)
-- Split the message into segments if it includes newlines.
for line in msg:gmatch("([^\r\n]+)") do for line in msg:gmatch("([^\r\n]+)") do
self:send("PRIVMSG %s :%s", verify(target, 3), msg) self:send("PRIVMSG %s :%s", verify(target, 3), msg)
end end
end end
function meta:sendNotice(target, msg) function meta:sendNotice(target, msg)
-- Split the message into segments if it includes newlines.
for line in msg:gmatch("([^\r\n]+)") do for line in msg:gmatch("([^\r\n]+)") do
self:send("NOTICE %s :%s", verify(target, 3), msg) self:send("NOTICE %s :%s", verify(target, 3), msg)
end end
@ -73,12 +67,12 @@ function meta:setMode(t)
assert(add or rem, "table contains neither 'add' nor 'remove'") assert(add or rem, "table contains neither 'add' nor 'remove'")
if add then if add then
mode = table.concat{"+", add} mode = table.concat{"+", verify(add, 3)}
end end
if rem then if rem then
mode = table.concat{mode, "-", rem} mode = table.concat{mode, "-", verify(rem, 3)}
end end
self:send("MODE %s %s", verify(target, 3), verify(mode, 3)) self:send("MODE %s %s", verify(target, 3), mode)
end end

View File

@ -103,13 +103,13 @@ function meta_preconnect:connect(_host, _port)
if type(secure) == "table" then if type(secure) == "table" then
params = secure params = secure
else else
params = {mode="client", protocol="tlsv1"} params = {mode = "client", protocol = "tlsv1"}
end end
s = ssl.wrap(s, params) s = ssl.wrap(s, params)
success, errmsg = s:dohandshake() success, errmsg = s:dohandshake()
if not success then if not success then
error(("could not make secure connection %s"):format(errmsg), 2) error(("could not make secure connection: %s"):format(errmsg), 2)
end end
end end
@ -133,7 +133,7 @@ function meta_preconnect:connect(_host, _port)
end end
function meta:disconnect(message) function meta:disconnect(message)
local message = message or "Bye!" message = message or "Bye!"
self:invoke("OnDisconnect", message, false) self:invoke("OnDisconnect", message, false)
self:send("QUIT :%s", message) self:send("QUIT :%s", message)