Add initial code
This commit is contained in:
parent
5296526fcb
commit
c1196f3d1e
|
@ -1,3 +1,4 @@
|
|||
vendor
|
||||
bin
|
||||
pkg
|
||||
./worm
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"git.xeserv.us/xena/worm/script"
|
||||
"github.com/layeh/gopher-luar"
|
||||
"github.com/thoj/go-ircevent"
|
||||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
func main() {
|
||||
l := script.InitLua()
|
||||
i := irc.IRC("Cadey", "love")
|
||||
i.Debug = true
|
||||
|
||||
err := i.Connect(os.Getenv("IRC_SERVER"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
i.AddCallback("001", func(e *irc.Event) {
|
||||
i.Join("#test")
|
||||
})
|
||||
|
||||
i.AddCallback("PRIVMSG", func(e *irc.Event) {
|
||||
levent := luar.New(l, e)
|
||||
|
||||
err := l.CallByParam(lua.P{
|
||||
Fn: l.GetGlobal("handleMessage"),
|
||||
NRet: 0,
|
||||
Protect: true,
|
||||
}, levent)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
|
||||
l.DoFile("./modules/test.lua")
|
||||
|
||||
runtime.Goexit()
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
function handleMessage(event)
|
||||
print("hi from lua!")
|
||||
print(event.connection.server, event.raw)
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
package script
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/cjoudrey/gluahttp"
|
||||
"github.com/cjoudrey/gluaurl"
|
||||
"github.com/kohkimakimoto/gluayaml"
|
||||
ljson "github.com/layeh/gopher-json"
|
||||
"github.com/layeh/gopher-lfs"
|
||||
"github.com/yuin/gluare"
|
||||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
func InitLua() (l *lua.LState) {
|
||||
l = lua.NewState()
|
||||
|
||||
l.PreloadModule("re", gluare.Loader)
|
||||
l.PreloadModule("http", gluahttp.NewHttpModule(&http.Client{}).Loader)
|
||||
l.PreloadModule("json", ljson.Loader)
|
||||
l.PreloadModule("yaml", gluayaml.Loader)
|
||||
l.PreloadModule("url", gluaurl.Loader)
|
||||
|
||||
lfs.Preload(l)
|
||||
|
||||
return
|
||||
}
|
Loading…
Reference in New Issue