Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
terminaldweller committed Jun 26, 2024
1 parent 20f8357 commit 2d45235
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
30 changes: 29 additions & 1 deletion plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import (
"context"
"log"
"net/http"
"net/url"
"os"
"reflect"

"github.com/ailncode/gluaxmlpath"
"github.com/cjoudrey/gluahttp"
"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"
Expand Down Expand Up @@ -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)

Expand Down
23 changes: 23 additions & 0 deletions plugins/ip.lua
Original file line number Diff line number Diff line change
@@ -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")
10 changes: 10 additions & 0 deletions plugins/proxy_test.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2d45235

Please sign in to comment.