From c1dcf30d44d72dc435b1b90c51ce944207c03742 Mon Sep 17 00:00:00 2001 From: mohemohe Date: Mon, 21 Mar 2022 05:52:17 +0900 Subject: [PATCH 1/3] v2 --- .gitignore | 2 ++ go.mod | 2 ++ go.sum | 34 +++++++++++++++++++++++++++ script.go | 68 +++++++++++------------------------------------------- 4 files changed, 51 insertions(+), 55 deletions(-) create mode 100644 go.sum diff --git a/.gitignore b/.gitignore index 3a0eb3d..ae49b43 100644 --- a/.gitignore +++ b/.gitignore @@ -110,3 +110,5 @@ modules.xml .idea/sonarlint # End of https://www.gitignore.io/api/go,intellij+all + +script-debug \ No newline at end of file diff --git a/go.mod b/go.mod index dd40064..969c03b 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/lxbot/script-debug go 1.13 + +require github.com/lxbot/lxlib/v2 v2.0.0-alpha.18 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..448c235 --- /dev/null +++ b/go.sum @@ -0,0 +1,34 @@ +github.com/lxbot/lxlib/v2 v2.0.0-alpha.3 h1:3oVkq1eubZsDdvL/9zywiqOPzKg9TzB7RLMCmdFHbd4= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.3/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.4 h1:/kVrEE6K2xyOh1Vujj0nc8sIf6QOjwi/J04j/mYmgvw= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.4/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.5 h1:v9HuEOYTriZ6Vnk8h7WwJS1AZ3Hn4nW7n5rnuuXLeDs= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.5/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.6 h1:dB3pnXZkAVlmVQ+5PjfUEviUdAaSfUcOJy/ohsE04uM= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.6/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.7 h1:FENSsbLYfbqNoGrzvgQSd7gPA7JHert6vrw9lIPvl/k= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.7/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.8 h1:PI7OEetrX9GfiGlqF8NfNjRvoVOT/3b8OQCfaC28Xzo= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.8/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.9 h1:PTKXiSyUyu/Zaf6+oIk+I3CsCFAFjmLwzxVoM5f6Yr4= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.9/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.10 h1:cOzTRIQU4dAGrZw5soY9PNyoB7lMpJ5BTDIxa9rbET4= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.10/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.11 h1:BTHz0+LCXzdSfKtvJeELM4fXRzPoADXvCaF+lg7zgC0= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.11/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.12 h1:ZntDl1mlMP0hFXR6dMniPS61rprgJTOosKOml7uN4xc= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.12/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.13 h1:ZoZCeD+9SK5vB6m+0XW7qpto8wuOiV3x0UWfJUw2Zcc= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.13/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.14 h1:KU+77yzWdm+9TbNkGCeK3OSmYdnm96a/Vp5X/SnUiUI= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.14/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.15 h1:a16xATV/RaU4wjOi27sUuCuhgXbBmyebYuopjRbA0f8= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.15/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.16 h1:QBuwXGX+ILbG6j+oJdg4Lh3tyQd+lbUE25nwiU8Z36A= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.16/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.17 h1:APuNdz2nXmBXMRxQSbiSvAFAqWT418uYAtxC7VslDsI= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.17/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.18 h1:QAgONx8vxbE+04czogxqDd0g6wV6oPeOorJJcz26igE= +github.com/lxbot/lxlib/v2 v2.0.0-alpha.18/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4= +github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= diff --git a/script.go b/script.go index 66fa670..7f26156 100644 --- a/script.go +++ b/script.go @@ -1,62 +1,20 @@ package main import ( - "fmt" - "plugin" - "strings" + "github.com/lxbot/lxlib/v2" + "github.com/lxbot/lxlib/v2/common" ) -type M = map[string]interface{} - -var store *plugin.Plugin - -func Boot(s *plugin.Plugin, c *chan M) { - store = s -} - -func OnMessage() []func(M) M { - return []func(M) M{ - func(msg M) M { - text := msg["message"].(M)["text"].(string) - last := get(msg) - set(msg, text) - if last != "" { - msg["message"].(M)["text"] = "last: "+last+"\n"+text - } - if strings.HasPrefix(text, "reply ") { - msg["mode"] = "reply" - } else { - msg["mode"] = "send" - } - return msg - }, - } -} - -func get(m M) string { - fn, err := store.Lookup("Get") - if err != nil { - _ = fmt.Errorf("%v", err) - return "" - } - result := fn.(func(string) interface{})(key(m)) - if result == nil { - return "" - } - return result.(string) -} - -func set(m M, value string) { - fn, err := store.Lookup("Set") - if err != nil { - _ = fmt.Errorf("%v", err) - return +func main() { + script, messageCh := lxlib.NewScript() + + for { + message := <-*messageCh + response, err := message.Copy() + if err != nil { + common.ErrorLog("message copy error:", err) + continue + } + script.SendMessage(response.Reply().AddContent("script-debug")) } - fn.(func(string, interface{}))(key(m), value) } - -func key(m M) string { - roomID := m["room"].(M)["id"].(string) - userID := m["user"].(M)["id"].(string) - return "last_msg_" + roomID + "_" + userID -} \ No newline at end of file From cf41ec21ddd616f31355c82b8768f6531c0d7d61 Mon Sep 17 00:00:00 2001 From: mohemohe Date: Mon, 16 May 2022 05:03:27 +0900 Subject: [PATCH 2/3] wip --- go.mod | 6 +++++- go.sum | 10 ++++++++++ script.go | 13 ++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 969c03b..7dfd6ca 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,8 @@ module github.com/lxbot/script-debug go 1.13 -require github.com/lxbot/lxlib/v2 v2.0.0-alpha.18 +require ( + github.com/lxbot/lxlib/v2 v2.0.0-beta.9 + github.com/mitchellh/mapstructure v1.4.3 // indirect + github.com/rs/xid v1.4.0 // indirect +) diff --git a/go.sum b/go.sum index 448c235..c0631fb 100644 --- a/go.sum +++ b/go.sum @@ -30,5 +30,15 @@ github.com/lxbot/lxlib/v2 v2.0.0-alpha.17 h1:APuNdz2nXmBXMRxQSbiSvAFAqWT418uYAtx github.com/lxbot/lxlib/v2 v2.0.0-alpha.17/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= github.com/lxbot/lxlib/v2 v2.0.0-alpha.18 h1:QAgONx8vxbE+04czogxqDd0g6wV6oPeOorJJcz26igE= github.com/lxbot/lxlib/v2 v2.0.0-alpha.18/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-beta.7 h1:xTOpNg9L1gsoUhHHdALj5kfW9N9pxvWwhMkW1hWG1Eo= +github.com/lxbot/lxlib/v2 v2.0.0-beta.7/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-beta.8 h1:r6I8YgdfoXa0lbmf2oorxtyycYTJW7QpL597rYRfsts= +github.com/lxbot/lxlib/v2 v2.0.0-beta.8/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/lxbot/lxlib/v2 v2.0.0-beta.9 h1:dUv1TmqtT+1WZS9CHhCgaGLp7fcH8OS1RdCw8l6LvTw= +github.com/lxbot/lxlib/v2 v2.0.0-beta.9/go.mod h1:otQkZ+zWIdaJUuYk3QSgONBkDP3ur1IGbChtIhONO9w= +github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs= +github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/rs/xid v1.3.0 h1:6NjYksEUlhurdVehpc7S7dk6DAmcKv8V9gG0FsVN2U4= github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY= +github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= diff --git a/script.go b/script.go index 7f26156..e3b9c01 100644 --- a/script.go +++ b/script.go @@ -5,6 +5,8 @@ import ( "github.com/lxbot/lxlib/v2/common" ) +type M = map[string]interface{} + func main() { script, messageCh := lxlib.NewScript() @@ -15,6 +17,15 @@ func main() { common.ErrorLog("message copy error:", err) continue } - script.SendMessage(response.Reply().AddContent("script-debug")) + + key := "last_msg_" + message.User.ID + + lastMessage := script.GetStorage(key) + if lastMessage == nil { + lastMessage = "" + } + script.SetStorage(key, message.Contents[0].Text) + + script.SendMessage(response.Reply().ResetContents().AddContent("last message: '" + lastMessage.(string) + "'")) } } From cdcfd571e736e043988a41994d688767c5d178b6 Mon Sep 17 00:00:00 2001 From: mohemohe Date: Tue, 16 Jul 2024 02:36:08 +0900 Subject: [PATCH 3/3] v2 ready --- script.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/script.go b/script.go index e3b9c01..41a2917 100644 --- a/script.go +++ b/script.go @@ -12,6 +12,9 @@ func main() { for { message := <-*messageCh + + common.TraceLog("(script)", "lxlib.listen()", "event received", "message:", message) + response, err := message.Copy() if err != nil { common.ErrorLog("message copy error:", err)