瀏覽代碼

Merge pull request #5 from mechmind/luap

added luap handler
Пётр 9 年之前
父節點
當前提交
e5dd0ef4ca
共有 2 個文件被更改,包括 11 次插入1 次删除
  1. 2 0
      .gitignore
  2. 9 1
      main.go

+ 2 - 0
.gitignore

@@ -1,3 +1,5 @@
+/xep
+
 # Compiled Object files, Static and Dynamic libs (Shared Objects)
 *.o
 *.a

+ 9 - 1
main.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"flag"
+	"fmt"
 	"github.com/ivpusic/golog"
 	//	"github.com/skratchdot/open-golang/open"
 	"github.com/kpmy/xep/luaexecutor"
@@ -96,7 +97,10 @@ func doLua(script string) func(stream.Stream) error {
 		executor.Run(script)
 		return nil
 	}
-	return nil
+}
+
+func doLuaAndPrint(script string) func(stream.Stream) error {
+	return doLua(fmt.Sprintf("chat.send(%s)", script))
 }
 
 func loadTpl(name string) (ret *template.Template, err error) {
@@ -139,6 +143,10 @@ func bot(st stream.Stream) error {
 							go func(script string) {
 								actors.With(st).Do(doLua(script)).Run()
 							}(strings.TrimPrefix(e.Body, "lua>"))
+						case strings.HasPrefix(e.Body, "luap>"):
+							go func(script string) {
+								actors.With(st).Do(doLua(script)).Run()
+							}(strings.TrimPrefix(e.Body, "luap>"))
 						}
 					}
 				}