4 --Implemented callbacks:
5 -- on_nick_change(user, old_nick)
7 -- on_part(chan, user, part_msg)
8 -- on_op(chan, from_user, to_user)
9 -- on_deop(chan, from_user, to_user)
10 -- on_voice(chan, from_user, to_user)
11 -- on_devoice(chan, from_user, to_user)
12 -- on_topic_change(chan)
13 -- on_invite(from_user, chan)
14 -- on_kick(chan, from_user, to_user)
15 -- on_channel_msg(chan, from_user, msg)
16 -- on_private_msg(from_user, msg)
17 -- on_channel_notice(chan, from_user, msg)
18 -- on_private_notice(from_user, msg)
19 -- on_quit(user, quit_msg)
22 -- on_channel_act(chan, from_user, msg)
23 -- on_private_act(from_user, msg)
24 -- on_dcc(from_user, to_user, arg, address, port, size)
25 -- on_ctcp_error(from_user, to_user, msg)
29 --Implemented functions:
40 -- ctcp_ping(cb, nick)
41 -- ctcp_time(cb, nick)
42 -- ctcp_version(cb, nick)
61 -- chan:set_limit(limit)
63 -- chan:set_private(b)
65 -- chan:set_invite_only(b)
66 -- chan:set_topic_lock(b)
67 -- chan:set_no_outside_messages(b)
68 -- chan:set_moderated(b)
69 -- XXX: these should not be in the public interface... actually, this whole
70 -- handling needs to be rewritten
71 -- chan:add_user(user, mode)
72 -- chan:remove_user(user)
73 -- chan:change_status(user, b, mode)
74 -- chan:contains(user)
75 -- chan:change_nick(old_nick, new_nick
77 -- dcc.send(nick, filename, [port])
78 -- dcc.accept(filename, address, port, size, [packet_size])
82 -- debug.set_output(file)
83 -- debug.message(msg_type, msg, [color])
87 -- XXX: do any of these need to be public?
88 -- misc.split(str, [delim], [end_delim], [lquotes], [rquotes])
89 -- misc.basename(path, [sep])
90 -- misc.dirname(path, [sep])
91 -- misc.str_to_int(str, [bytes], [endian])
92 -- misc.int_to_str(int, [endian])
93 -- misc.ip_str_to_int(ip_str)
94 -- misc.ip_int_to_str(ip_int)
95 -- misc.get_unique_filename(filename)
96 -- misc.try_call(fn, [...])
97 -- misc.try_call_warn(msg, fn, [...])
98 -- misc.parse_user(user)
99 -- misc.value_iter(state, arg, pred)
102 local irc = require "irc"
103 local dcc = require "irc.dcc"
107 local function print_state()
108 for chan in irc.channels() do
109 print(chan..": Channel ops: "..table.concat(chan:ops(), " "))
110 print(chan..": Channel voices: "..table.concat(chan:voices(), " "))
111 print(chan..": Channel normal users: "..table.concat(chan:users(), " "))
112 print(chan..": All channel members: "..table.concat(chan:members(), " "))
116 function irc.on_connect()
117 print("Joining channel #doytest...")
119 print("Joining channel #doytest2...")
120 irc.join("#doytest2")
123 function irc.on_me_join(chan)
124 print("Join to " .. chan .. " complete.")
125 print(chan .. ": Channel type: " .. chan.chanmode)
126 if chan.topic.text and chan.topic.text ~= "" then
127 print(chan .. ": Channel topic: " .. chan.topic.text)
128 print(" Set by " .. chan.topic.user ..
129 " at " .. os.date("%c", chan.topic.time))
131 irc.act(chan.name, "is here")
135 function irc.on_join(chan, user)
136 print("I saw a join to " .. chan)
137 if tostring(user) ~= "doylua" then
138 irc.say(tostring(chan), "Hi, " .. user)
143 function irc.on_part(chan, user, part_msg)
144 print("I saw a part from " .. chan .. " saying " .. part_msg)
148 function irc.on_nick_change(new_nick, old_nick)
149 print("I saw a nick change: " .. old_nick .. " -> " .. new_nick)
153 function irc.on_kick(chan, user)
154 print("I saw a kick in " .. chan)
158 function irc.on_quit(chan, user)
159 print("I saw a quit from " .. chan)
163 local function whois_cb(cb_data)
164 print("WHOIS data for " .. cb_data.nick)
165 if cb_data.user then print("Username: " .. cb_data.user) end
166 if cb_data.host then print("Host: " .. cb_data.host) end
167 if cb_data.realname then print("Realname: " .. cb_data.realname) end
168 if cb_data.server then print("Server: " .. cb_data.server) end
169 if cb_data.serverinfo then print("Serverinfo: " .. cb_data.serverinfo) end
170 if cb_data.away_msg then print("Awaymsg: " .. cb_data.away_msg) end
171 if cb_data.is_oper then print(nick .. "is an IRCop") end
172 if cb_data.idle_time then print("Idletime: " .. cb_data.idle_time) end
173 if cb_data.channels then
174 print("Channel list for " .. cb_data.nick .. ":")
175 for _, channel in ipairs(cb_data.channels) do print(channel) end
179 local function serverversion_cb(cb_data)
180 print("VERSION data for " .. cb_data.server)
181 print("Version: " .. cb_data.version)
182 print("Comments: " .. cb_data.comments)
185 local function ping_cb(cb_data)
186 print("CTCP PING for " .. cb_data.nick)
187 print("Roundtrip time: " .. cb_data.time .. "s")
190 local function time_cb(cb_data)
191 print("CTCP TIME for " .. cb_data.nick)
192 print("Localtime: " .. cb_data.time)
195 local function version_cb(cb_data)
196 print("CTCP VERSION for " .. cb_data.nick)
197 print("Version: " .. cb_data.version)
200 local function stime_cb(cb_data)
201 print("TIME for " .. cb_data.server)
202 print("Server time: " .. cb_data.time)
205 function irc.on_channel_msg(chan, from, msg)
206 if from == "doy" then
207 if msg == "leave" then
210 elseif msg:sub(1, 3) == "op " then
213 elseif msg:sub(1, 5) == "deop " then
214 chan:deop(msg:sub(6))
216 elseif msg:sub(1, 6) == "voice " then
217 chan:voice(msg:sub(7))
219 elseif msg:sub(1, 8) == "devoice " then
220 chan:devoice(msg:sub(9))
222 elseif msg:sub(1, 5) == "kick " then
223 chan:kick(msg:sub(6))
225 elseif msg:sub(1, 5) == "send " then
226 dcc.send(from, msg:sub(6))
228 elseif msg:sub(1, 6) == "whois " then
229 irc.whois(whois_cb, msg:sub(7))
231 elseif msg:sub(1, 8) == "sversion" then
232 irc.server_version(serverversion_cb)
234 elseif msg:sub(1, 5) == "ping " then
235 irc.ctcp_ping(ping_cb, msg:sub(6))
237 elseif msg:sub(1, 5) == "time " then
238 irc.ctcp_time(time_cb, msg:sub(6))
240 elseif msg:sub(1, 8) == "version " then
241 irc.ctcp_version(version_cb, msg:sub(9))
243 elseif msg:sub(1, 5) == "stime" then
244 irc.server_time(stime_cb)
246 elseif msg:sub(1, 6) == "trace " then
247 irc.trace(trace_cb, msg:sub(7))
249 elseif msg:sub(1, 5) == "trace" then
254 if from ~= "doylua" then
255 irc.say(chan.name, from .. ": " .. msg)
259 function irc.on_private_msg(from, msg)
260 if from == "doy" then
261 if msg == "leave" then
264 elseif msg:sub(1, 5) == "send " then
265 dcc.send(from, msg:sub(6))
269 if from ~= "doylua" then
274 function irc.on_channel_act(chan, from, msg)
275 irc.act(chan.name, "jumps on " .. from)
278 function irc.on_private_act(from, msg)
279 irc.act(from, "jumps on you")
282 function irc.on_op(chan, from, nick)
286 function irc.on_deop(chan, from, nick)
290 function irc.on_voice(chan, from, nick)
294 function irc.on_devoice(chan, from, nick)
298 function irc.on_dcc()
302 irc.connect{network = "irc.freenode.net", nick = "doylua", pass = "doylua"}