oper module

This commit is contained in:
Cadey Ratio 2019-12-24 15:47:29 +00:00
parent a2e649bb34
commit e9130b3cd2
6 changed files with 42 additions and 11 deletions

View File

@ -1,4 +1,5 @@
#!/bin/bash
tup
lua5.3 -l set_paths ./src/ketracel.lua
cd src
lua5.3 -l set_paths ketracel.lua

View File

@ -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

3
src/irce/modules/Tupfile Normal file
View File

@ -0,0 +1,3 @@
include_rules
.gitignore

View File

@ -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
}

View File

@ -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!

4
src/set_paths.lua Normal file
View File

@ -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