start to track modes

This commit is contained in:
Cadey Ratio 2019-12-26 03:28:28 +00:00
parent aa777a6ab6
commit ac061dff7d
6 changed files with 80 additions and 19 deletions

View File

@ -21,7 +21,12 @@ dependencies = {
build = {
type = "builtin",
modules = {
["ketracel"] = "src/ketracel.lua",
["ketracel.bot.commands"] = "src/ketracel/bot/commands.lua",
["ketracel.bot.ketracel"] = "src/ketracel/bot/ketracel.lua",
["ketracel.main"] = "src/ketracel/main.lua",
["ketracel.server"] = "src/ketracel/server.lua",
["irce.modules.ngircd"] = "src/irce/modules/ngircd/init.lua",
["irce.modules.ngircd.modes"] = "src/irce/modules/ngircd/modes.lua",
["irce.modules.oper"] = "src/irce/modules/oper.lua",
},
install = {

View File

@ -1,4 +1,4 @@
#!/bin/sh
moonc `find -type f | grep -v spec | grep 'moon$'`
busted --defer-print
busted

View File

@ -0,0 +1,20 @@
modes = require "irce.modules.ngircd.modes"
describe "mode conversion", ->
it "has modes2prefix", ->
assert.truthy modes.mode2prefix
it "has prefix2modes", ->
assert.truthy modes.prefix2mode
it "has convert", ->
assert.truthy modes.convert
describe "convert", ->
for k, v in pairs modes.mode2prefix
msg = string.format "%s: %s", k, v
it msg, ->
assert.equal(modes.convert(k), v)
msg = string.format "%s: %s", v, k
it msg, ->
assert.equal(modes.convert(v), k)

View File

@ -3,6 +3,7 @@ util = require "irce.util"
stringx = require "pl.stringx"
moon = require "moon"
ln = require "ln"
modeconv = require "irce.modules.ngircd.modes"
{
init: (state) =>
@ -12,10 +13,10 @@ ln = require "ln"
senders:
["REGISTER"]: (state, password, software, version, sname, real, nicklen) =>
assert self\PASS password, software, version
assert self\SERVER sname, real
assert self\NICKLEN nicklen
assert self\EMOTD!
assert @PASS password, software, version
assert @SERVER sname, real
assert @NICKLEN nicklen
assert @EMOTD!
string.format ":%s PING :%s", sname, sname
["PASS"]: (state, password, software, version) =>
@ -44,18 +45,30 @@ ln = require "ln"
["NICK"]: (state, nick, user, host, modes, real) =>
state.clients[string.lower nick] =
:nick, :user, :host, :modes, :real, metadata: {}
:nick, :user, :host, modes: string.sub(modes, 2), :real, metadata: {}
string.format ":%s NICK %s 1 %s %s 1 %s :%s", state.sname, nick, user, host, modes, real
["NJOIN"]: (state, channame, who) =>
string.format ":%s NJOIN %s :%s", state.sname, channame, who
["NJOIN"]: (state, channame, who, prefix) =>
if state.channels[channame] == nil
state.channels[channame] =
name: channame,
mode: ""
topic: ""
members: {}
pfxarr = {}
if prefix
for i = 1, #prefix
pfxarr[i] = string.sub prefix, i, i
state.channels[channame].members[string.lower who] = pfxarr
string.format ":%s NJOIN %s :%s%s", state.sname, channame, prefix or "", who
["METADATA"]: (state, nick, key, val) =>
state.clients[string.lower nick].metadata[key] = val
string.format ":%s METADATA %s %s :%s", state.sname, nick, key, val
["VHOST"]: (state, nick, vhost) =>
self\METADATA nick, "cloakhost", vhost
@METADATA nick, "cloakhost", vhost
string.format ":%s MODE %s +x", state.sname, nick
["PRIVMSG"]: (state, nick, target, message) =>
@ -73,13 +86,13 @@ ln = require "ln"
handlers:
["461"]: (state, sender, params) =>
self\handle "DIE", string.format("%s: %s", sender[1], params[1])
@handle "DIE", string.format("%s: %s", sender[1], params[1])
["ERROR"]: (state, sender, params) =>
error string.format "%s: %s", sender[1], params[1]
["PING"]: (state, sender, params) =>
self\send "PONG", params[1]
@send "PONG", params[1]
sender, params[1]
["PONG"]: (state, sender, params) =>
@ -92,8 +105,7 @@ ln = require "ln"
if bell
sp = {string.sub(chan, 1, bell - 1), string.sub(chan, bell + 1)}
chan = sp[1]
mode = if sp[2] == "o"
{"@"}
mode = {modeconv.convert sp[2]}
nick = string.lower sender[1]
if not state.channels[chan]
@ -179,7 +191,7 @@ ln = require "ln"
pfxarr = {}
for i = 1, #prefix
pfxarr[i] = string.sub prefix, i, i
pfxarr[i] = modes.convert string.sub prefix, i, i
state.channels[chan].members[nick] = pfxarr
@ -214,13 +226,13 @@ ln = require "ln"
code = string.sub(params[2], 7)
print string.format "%s %s %s - evaling", params[1], sender[1], code
fun, err = load(code, sender[1].."-"..params[1], "t", {
state: state, :string,
state: state, :string, irc: @, :_VERSION
})
if err ~= nil
error err
result = fun!
if result ~= nil
self\PRIVMSG state.sname, params[1], tostring result
@PRIVMSG state.sname, params[1], tostring result
sender, params

View File

@ -0,0 +1,22 @@
mode2prefix =
q: "~"
a: "&"
o: "@"
h: "%"
v: "+"
prefix2mode =
["~"]: "q"
["&"]: "a"
["@"]: "o"
["%"]: "h"
["+"]: "v"
convert = (mode_or_prefix) ->
mode2prefix[mode_or_prefix] or prefix2mode[mode_or_prefix]
{
:mode2prefix
:prefix2mode
:convert
}

View File

@ -11,11 +11,13 @@ class Ketracel
router = CommandRouter self
router\register "DIE", (sender, target, verb, args) -> @die sender, target, verb, args
router\register "VHOST", (...) -> @set_vhost ...
self.router = router
router\register "STATE", ->
router\register "EVAL", ->
@router = router
burst: =>
@irc\NICK "Ketracel", "white", "the.dominion", "+io", "Ketracel White"
@irc\NJOIN "#ketracel", "&@Ketracel"
@irc\NJOIN "#ketracel", "Ketracel", "&@"
njoin: (chan) =>
@irc\NJOIN chan, "Ketracel"