From e9130b3cd2564b94d1e715b8b04a0275486356f3 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Tue, 24 Dec 2019 15:47:29 +0000 Subject: [PATCH] oper module --- scripts/run.sh | 3 ++- set_paths.lua | 4 ---- src/irce/modules/Tupfile | 3 +++ src/irce/modules/oper.moon | 18 ++++++++++++++++++ src/ketracel.moon | 21 +++++++++++++++------ src/set_paths.lua | 4 ++++ 6 files changed, 42 insertions(+), 11 deletions(-) delete mode 100644 set_paths.lua create mode 100644 src/irce/modules/Tupfile create mode 100644 src/irce/modules/oper.moon create mode 100644 src/set_paths.lua diff --git a/scripts/run.sh b/scripts/run.sh index e251972..d8f3b8d 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -1,4 +1,5 @@ #!/bin/bash tup -lua5.3 -l set_paths ./src/ketracel.lua +cd src +lua5.3 -l set_paths ketracel.lua diff --git a/set_paths.lua b/set_paths.lua deleted file mode 100644 index 425f2d7..0000000 --- a/set_paths.lua +++ /dev/null @@ -1,4 +0,0 @@ --- set_paths.lua -local version = _VERSION:match("%d+%.%d+") -package.path = 'lua_modules/share/lua/' .. version .. '/?.lua;lua_modules/share/lua/' .. version .. '/?/init.lua;' .. package.path -package.cpath = 'lua_modules/lib/lua/' .. version .. '/?.so;' .. package.cpath diff --git a/src/irce/modules/Tupfile b/src/irce/modules/Tupfile new file mode 100644 index 0000000..591db9c --- /dev/null +++ b/src/irce/modules/Tupfile @@ -0,0 +1,3 @@ +include_rules +.gitignore + diff --git a/src/irce/modules/oper.moon b/src/irce/modules/oper.moon new file mode 100644 index 0000000..fbfa05e --- /dev/null +++ b/src/irce/modules/oper.moon @@ -0,0 +1,18 @@ +irce = require "irce" +util = require "irce.util" + +{ + init: (state) => + state.nick = "" + + senders: + ["OPER"]: (state, nick, pass) => + state.nick = nick + return string.format "OPER %s %s", nick, pass + + handlers: + ["381"]: (state, sender, params) => + print string.format "granted ircop status by %s as oper %s", sender[1], state.nick + state.nick = nil + return sender, params +} diff --git a/src/ketracel.moon b/src/ketracel.moon index bfae132..90a8d9a 100644 --- a/src/ketracel.moon +++ b/src/ketracel.moon @@ -1,6 +1,5 @@ irce = require "irce" socket = require "socket" -print irce._VERSION .. " running on " .. _VERSION config = server: "127.0.0.1" @@ -9,22 +8,28 @@ config = real: os.getenv("IRC_REAL") or "The favorite of the Jem'Hadar" oper: os.getenv("IRC_OPER") channels: { "#ketracel", "#opers" } + debug: os.getenv("KETRACEL_DEBUG") irc = irce.new! running = true +-- load IRC modules assert irc\load_module require "irce.modules.base" assert irc\load_module require "irce.modules.message" assert irc\load_module require "irce.modules.channel" assert irc\load_module require "irce.modules.motd" +assert irc\load_module require "irce.modules.oper" client = socket.tcp! -irc\set_send_func (message) => - client\send message client\settimeout 1 -irc\set_callback irce.RAW, (send, message) => - print string.format "%s %s", (send and ">" or "<"), message +-- irc engine callbacks +irc\set_send_func (message) => + client\send message + +if config.debug + irc\set_callback irce.RAW, (send, message) => + print string.format "%s %s", (send and ">" or "<"), message irc\set_callback "CTCP", (sender, origin, command, params, pm) => if command == "VERSION" @@ -39,13 +44,17 @@ irc\set_callback "PRIVMSG", (sender, origin, message, pm) => assert self\QUIT "Ran out of white" running = false +-- connect to irc server assert client\connect config.server, 6667 assert irc\NICK config.nick assert irc\USER config.user, config.real +print "Ketracel loaded using " .. irce._VERSION .. " running on " .. _VERSION + if config.oper - client\send "OPER " .. config.nick .. " " .. config.oper .. "\r\n" + irc\OPER config.nick, config.oper + print "IRC operator status requested for " .. config.nick while running irc\process client\receive! diff --git a/src/set_paths.lua b/src/set_paths.lua new file mode 100644 index 0000000..c931b9d --- /dev/null +++ b/src/set_paths.lua @@ -0,0 +1,4 @@ +-- set_paths.lua +local version = _VERSION:match("%d+%.%d+") +package.path = '../lua_modules/share/lua/' .. version .. '/?.lua;../lua_modules/share/lua/' .. version .. '/?/init.lua;' .. package.path +package.cpath = '../lua_modules/lib/lua/' .. version .. '/?.so;' .. package.cpath