From c1196f3d1e9dbe03dfdd793c97d1ce9578f5c90d Mon Sep 17 00:00:00 2001 From: Cadey Dodrill Date: Mon, 11 Apr 2016 19:18:15 -0700 Subject: [PATCH] Add initial code --- .gitignore | 1 + cmd/worm/main.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ modules/test.lua | 4 ++++ script/script.go | 27 +++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 cmd/worm/main.go create mode 100644 modules/test.lua create mode 100644 script/script.go diff --git a/.gitignore b/.gitignore index e504bcb..c6ff4b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor bin pkg +./worm diff --git a/cmd/worm/main.go b/cmd/worm/main.go new file mode 100644 index 0000000..52566a5 --- /dev/null +++ b/cmd/worm/main.go @@ -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() +} diff --git a/modules/test.lua b/modules/test.lua new file mode 100644 index 0000000..c9558b3 --- /dev/null +++ b/modules/test.lua @@ -0,0 +1,4 @@ +function handleMessage(event) + print("hi from lua!") + print(event.connection.server, event.raw) +end diff --git a/script/script.go b/script/script.go new file mode 100644 index 0000000..a74fdac --- /dev/null +++ b/script/script.go @@ -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 +}