handle JOIN, PART and NICK
This commit is contained in:
parent
f953cad787
commit
fdfb591c13
|
@ -30,14 +30,16 @@ stringx = require "pl.stringx"
|
||||||
|
|
||||||
["Ketracel command"]: (state, sender, target, cmd, args) =>
|
["Ketracel command"]: (state, sender, target, cmd, args) =>
|
||||||
switch string.upper cmd
|
switch string.upper cmd
|
||||||
|
when "STATE"
|
||||||
|
1 + 1
|
||||||
when "VHOST"
|
when "VHOST"
|
||||||
if #args > 0
|
if #args > 0
|
||||||
ln.log
|
ln.log
|
||||||
:sender, vhost: args[1], action: "setting vhost"
|
:sender, vhost: args[1], action: "setting vhost"
|
||||||
self\VHOST sender, args[1]
|
self\VHOST sender, args[1]
|
||||||
self\PRIVMSG "Ketracel", sender, "your vhost is now " ..args[1]
|
self\NOTICE "Ketracel", sender, "your vhost is now " ..args[1]
|
||||||
else
|
else
|
||||||
self\PRIVMSG "Ketracel", sender, "usage: VHOST <your.vhost>"
|
self\NOTICE "Ketracel", sender, "usage: VHOST <your.vhost>"
|
||||||
else
|
else
|
||||||
self\PRIVMSG "Ketracel", sender, "i don't know " .. cmd
|
self\NOTICE "Ketracel", sender, "i don't know " .. cmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,16 @@ moon = require "moon"
|
||||||
["PRIVMSG"]: (state, nick, target, message) =>
|
["PRIVMSG"]: (state, nick, target, message) =>
|
||||||
string.format ":%s PRIVMSG %s :%s", nick, target, message
|
string.format ":%s PRIVMSG %s :%s", nick, target, message
|
||||||
|
|
||||||
|
["NOTICE"]: (state, nick, target, message) =>
|
||||||
|
string.format ":%s NOTICE %s :%s", nick, target, message
|
||||||
|
|
||||||
|
["PART"]: (state, nick, chan, why) =>
|
||||||
|
state.channels[chan].members[nick] = nil
|
||||||
|
if #state.channels[chan].members == 0
|
||||||
|
state.channels[chan] = nil
|
||||||
|
|
||||||
|
string.format ":%s PART %s :%s", nick, chan, why
|
||||||
|
|
||||||
handlers:
|
handlers:
|
||||||
["ERROR"]: (state, sender, params) =>
|
["ERROR"]: (state, sender, params) =>
|
||||||
error string.format "%s: %s", sender[1], params[1]
|
error string.format "%s: %s", sender[1], params[1]
|
||||||
|
@ -71,6 +81,35 @@ moon = require "moon"
|
||||||
["PONG"]: (state, sender, params) =>
|
["PONG"]: (state, sender, params) =>
|
||||||
sender, params[1]
|
sender, params[1]
|
||||||
|
|
||||||
|
["JOIN"]: (state, sender, params) =>
|
||||||
|
chan = params[1]
|
||||||
|
mode = {}
|
||||||
|
bell = string.find chan, "\x07"
|
||||||
|
if bell
|
||||||
|
sp = {string.sub(chan, 1, bell - 1), string.sub(chan, bell + 1)}
|
||||||
|
chan = sp[1]
|
||||||
|
mode = if sp[2] == "o"
|
||||||
|
{"@"}
|
||||||
|
nick = string.lower sender[1]
|
||||||
|
|
||||||
|
if not state.channels[chan]
|
||||||
|
state.channels[chan] = {name: chan, mode: "", members: {}, topic: ""}
|
||||||
|
state.channels[chan].members[nick] = mode
|
||||||
|
|
||||||
|
["PART"]: (state, sender, params) =>
|
||||||
|
chan = params[1]
|
||||||
|
nick = string.lower sender[1]
|
||||||
|
state.channels[chan].members[nick] = nil
|
||||||
|
if #state.channels[chan].members == 0
|
||||||
|
state.channels[chan] = nil
|
||||||
|
|
||||||
|
["QUIT"]: (state, sender, params) =>
|
||||||
|
nick = string.lower sender[1]
|
||||||
|
state.clients[nick] = nil
|
||||||
|
|
||||||
|
for k, v in pairs state.channels
|
||||||
|
v.members[nick] = nil
|
||||||
|
|
||||||
["NICK"]: (state, sender, params) =>
|
["NICK"]: (state, sender, params) =>
|
||||||
if #params == 1
|
if #params == 1
|
||||||
oldnick = sender[1]
|
oldnick = sender[1]
|
||||||
|
@ -114,6 +153,13 @@ moon = require "moon"
|
||||||
chan = params[1]
|
chan = params[1]
|
||||||
whose = stringx.split tostring(params[2]), ","
|
whose = stringx.split tostring(params[2]), ","
|
||||||
|
|
||||||
|
if state.channels[chan] == nil
|
||||||
|
state.channels[chan] =
|
||||||
|
name: chan
|
||||||
|
mode: ""
|
||||||
|
topic: ""
|
||||||
|
members: {}
|
||||||
|
|
||||||
for k, v in pairs whose
|
for k, v in pairs whose
|
||||||
pfxlen = string.find v, "%a+"
|
pfxlen = string.find v, "%a+"
|
||||||
nick = string.lower string.sub v, pfxlen
|
nick = string.lower string.sub v, pfxlen
|
||||||
|
|
Loading…
Reference in New Issue