diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | go.mod | 1 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | plugins.go | 30 | ||||
-rw-r--r-- | plugins/ip.lua | 23 | ||||
-rw-r--r-- | plugins/proxy_test.lua | 10 |
6 files changed, 66 insertions, 1 deletions
@@ -713,6 +713,7 @@ The following libraries are loaded by milla by default: - [gluayaml](https://github.com/kohkimakimoto/gluayaml) - [gluasocket](https://gitlab.com/megalithic-llc/gluasocket) - [gluare](https://github.com/yuin/gluare) +- [gopher-json](https://github.com/layeh/gopher-json) ## FAQ @@ -10,6 +10,7 @@ require ( github.com/google/generative-ai-go v0.11.2 github.com/jackc/pgx/v5 v5.5.5 github.com/kohkimakimoto/gluayaml v0.0.0-20160815032708-6fe413d49d73 + github.com/layeh/gopher-json v0.0.0-20201124131017-552bb3c4c3bf github.com/lrstanley/girc v0.0.0-20240125042120-9add3166e52e github.com/sashabaranov/go-openai v1.19.3 github.com/yuin/gluare v0.0.0-20170607022532-d7c94f1a80ed @@ -94,6 +94,8 @@ github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/layeh/gopher-json v0.0.0-20201124131017-552bb3c4c3bf h1:bg6J/5S/AeTz7K9i/luJRj31BJ8f+LgYwKQBSOZxSEM= +github.com/layeh/gopher-json v0.0.0-20201124131017-552bb3c4c3bf/go.mod h1:E/q28EyUVBgBQnONAVPIdwvEsv4Ve0vaCA9JWim4+3I= github.com/lrstanley/girc v0.0.0-20240125042120-9add3166e52e h1:Y86mAFtJjS4P0atZ6QAKH88TV0ASQYJdIGWiOmJKoNY= github.com/lrstanley/girc v0.0.0-20240125042120-9add3166e52e/go.mod h1:lgrnhcF8bg/Bd5HA5DOb4Z+uGqUqGnp4skr+J2GwVgI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -4,6 +4,8 @@ import ( "context" "log" "net/http" + "net/url" + "os" "reflect" "github.com/ailncode/gluaxmlpath" @@ -11,6 +13,7 @@ import ( "github.com/google/generative-ai-go/genai" "github.com/jackc/pgx/v5" "github.com/kohkimakimoto/gluayaml" + gopherjson "github.com/layeh/gopher-json" "github.com/lrstanley/girc" openai "github.com/sashabaranov/go-openai" "github.com/yuin/gluare" @@ -331,9 +334,34 @@ func RunScript(scriptPath string, client *girc.Client, appConfig *TomlConfig) { luaState.PreloadModule("milla", millaModuleLoaderClosure(luaState, client, appConfig)) gluasocket.Preload(luaState) gluaxmlpath.Preload(luaState) - luaState.PreloadModule("http", gluahttp.NewHttpModule(&http.Client{}).Loader) luaState.PreloadModule("yaml", gluayaml.Loader) luaState.PreloadModule("re", gluare.Loader) + luaState.PreloadModule("json", gopherjson.Loader) + + var proxyString string + if os.Getenv("ALL_PROXY") != "" { + proxyString = os.Getenv("ALL_PROXY") + } else if os.Getenv("HTTPS_PROXY") != "" { + proxyString = os.Getenv("HTTPS_PROXY") + } else if os.Getenv("HTTP_PROXY") != "" { + proxyString = os.Getenv("HTTP_PROXY") + } else if os.Getenv("https_proxy") != "" { + proxyString = os.Getenv("https_proxy") + } else if os.Getenv("http_proxy") != "" { + proxyString = os.Getenv("http_proxy") + } + + proxyTransport := &http.Transport{} + + if proxyString != "" { + proxyURL, err := url.Parse(proxyString) + if err != nil { + log.Print(err) + } + proxyTransport.Proxy = http.ProxyURL(proxyURL) + } + + luaState.PreloadModule("http", gluahttp.NewHttpModule(&http.Client{Transport: proxyTransport}).Loader) log.Print("Running script: ", scriptPath) diff --git a/plugins/ip.lua b/plugins/ip.lua new file mode 100644 index 0000000..57cb0f5 --- /dev/null +++ b/plugins/ip.lua @@ -0,0 +1,23 @@ +local milla = require("milla") +local os = require("os") +local json = require("json") + +os.setenv("ALL_PROXY", "socks5://172.17.0.1:9057") + +local http = require("http") + +local function get_ip(arg) + local ip = arg + local response, err = http.request("GET", + "https://getip-api.com/json?" .. ip) + local json_response, err = json.decode(response.body) + + local result = "" + for key, value in ipairs(json_response) do + result = result .. key .. ": " .. value .. "\n" + end + + return result +end + +milla.register_cmd("ip", "get_ip") diff --git a/plugins/proxy_test.lua b/plugins/proxy_test.lua new file mode 100644 index 0000000..841fefa --- /dev/null +++ b/plugins/proxy_test.lua @@ -0,0 +1,10 @@ +local milla = require("milla") +local os = require("os") +local json = require("json") + +os.setenv("ALL_PROXY", "socks5://172.17.0.1:9057") + +local http = require("http") + +local response, err = http.request("GET", "https://icanhazip.com") +print(response.body) |