* JS script folder is now $config/scripts/js
MODIFY
internal/scripting/javascript.go
internal/scripting/javascript.go
@@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
+ "strings"
"github.com/pkg/errors"
"github.com/robertkrimen/otto"
@@ -37,6 +38,11 @@ func (e *JavaScriptEngine) LoadScripts(dirname string) (err error) {
if file.IsDir() {
continue
}
+
+ if !strings.HasSuffix(file.Name(), ".js") {
+ continue
+ }
+
path := filepath.Join(dirname, file.Name())
f, err := os.Open(path)
if err != nil {

MODIFY
internal/scripting/javascript_test.go
internal/scripting/javascript_test.go
@@ -11,9 +11,9 @@ func TestJavaScriptEngine(t *testing.T) {
want string
}{
{
- "test/simple",
- "Replace me",
- "Replace this",
+ dir: "test/simple",
+ input: "Replace me",
+ want: "Replace this",
},
}
for _, tt := range tests {
@@ -23,6 +23,7 @@ func TestJavaScriptEngine(t *testing.T) {
t.Error("LoadScripts failed:", err)
return
}
+
if gotNewText := e.OnMessage(tt.input); gotNewText != tt.want {
t.Errorf("JavaScriptEngine.OnMessage() = %v, want %v", gotNewText, tt.want)
}

MODIFY
internal/ui/window.go
internal/ui/window.go
@@ -3,6 +3,7 @@ package ui
import (
"fmt"
"io"
+ "path/filepath"
"regexp"
"sort"
"strings"
@@ -91,7 +92,7 @@ func NewWindow(discord *discordgo.Session) (*Window, error) {
if err != nil {
return nil, err
}
- if err := window.scripting.LoadScripts(configDir); err != nil {
+ if err := window.scripting.LoadScripts(filepath.Join(configDir, "scripts", "js")); err != nil {
return nil, err
}

* JS script folder is now $config/scripts/js