2010-04-04 16:55:12 +02:00
|
|
|
local table = table
|
|
|
|
|
|
|
|
module "irc"
|
|
|
|
|
|
|
|
local meta = _META
|
|
|
|
|
|
|
|
function meta:send(fmt, ...)
|
2010-06-28 05:58:46 +02:00
|
|
|
self.socket:send(fmt:format(...) .. "\r\n")
|
2010-04-04 16:55:12 +02:00
|
|
|
end
|
|
|
|
|
2010-06-01 01:39:34 +02:00
|
|
|
local function sendByMethod(self, method, target, msg)
|
|
|
|
local toChannel = table.concat({method, target, ":"}, " ")
|
2010-04-04 16:55:12 +02:00
|
|
|
for line in msg:gmatch("[^\r\n]+") do
|
|
|
|
self.socket:send(table.concat{toChannel, line, "\r\n"})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-01 01:39:34 +02:00
|
|
|
function meta:sendChat(target, msg)
|
|
|
|
sendByMethod(self, "PRIVMSG", target, msg)
|
|
|
|
end
|
|
|
|
|
|
|
|
function meta:sendNotice(target, msg)
|
|
|
|
sendByMethod(self, "NOTICE", target, msg)
|
|
|
|
end
|
|
|
|
|
2010-04-04 16:55:12 +02:00
|
|
|
function meta:join(channel, key)
|
|
|
|
if key then
|
|
|
|
self:send("JOIN %s :%s", channel, key)
|
|
|
|
else
|
|
|
|
self:send("JOIN %s", channel)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function meta:part(channel)
|
2010-06-28 05:58:46 +02:00
|
|
|
self:send("PART %s", channel)
|
|
|
|
if self.track_users then
|
|
|
|
self.channels[channel] = nil
|
|
|
|
end
|
2010-04-04 16:55:12 +02:00
|
|
|
end
|
|
|
|
|
2010-06-01 01:39:34 +02:00
|
|
|
function meta:trackUsers(b)
|
|
|
|
self.track_users = b
|
|
|
|
if not b then
|
|
|
|
for k,v in pairs(self.channels) do
|
|
|
|
self.channels[k] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-04 16:55:12 +02:00
|
|
|
function meta:setMode(t)
|
|
|
|
local target = t.target or self.nick
|
|
|
|
local mode = ""
|
|
|
|
local add, rem = t.add, t.remove
|
|
|
|
|
|
|
|
assert(add or rem, "table contains neither 'add' nor 'remove'")
|
|
|
|
|
|
|
|
if add then
|
|
|
|
mode = table.concat{"+", add}
|
|
|
|
end
|
|
|
|
|
|
|
|
if rem then
|
|
|
|
mode = table.concat{mode, "-", rem}
|
|
|
|
end
|
|
|
|
|
|
|
|
self:send("MODE %s %s", target, mode)
|
|
|
|
end
|