Skip to content

Commit 2d45235

Browse files
WIP
1 parent 20f8357 commit 2d45235

File tree

6 files changed

+66
-1
lines changed

6 files changed

+66
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ The following libraries are loaded by milla by default:
713713
- [gluayaml](https://github.com/kohkimakimoto/gluayaml)
714714
- [gluasocket](https://gitlab.com/megalithic-llc/gluasocket)
715715
- [gluare](https://github.com/yuin/gluare)
716+
- [gopher-json](https://github.com/layeh/gopher-json)
716717

717718
## FAQ
718719

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/google/generative-ai-go v0.11.2
1111
github.com/jackc/pgx/v5 v5.5.5
1212
github.com/kohkimakimoto/gluayaml v0.0.0-20160815032708-6fe413d49d73
13+
github.com/layeh/gopher-json v0.0.0-20201124131017-552bb3c4c3bf
1314
github.com/lrstanley/girc v0.0.0-20240125042120-9add3166e52e
1415
github.com/sashabaranov/go-openai v1.19.3
1516
github.com/yuin/gluare v0.0.0-20170607022532-d7c94f1a80ed

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
9494
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
9595
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
9696
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
97+
github.com/layeh/gopher-json v0.0.0-20201124131017-552bb3c4c3bf h1:bg6J/5S/AeTz7K9i/luJRj31BJ8f+LgYwKQBSOZxSEM=
98+
github.com/layeh/gopher-json v0.0.0-20201124131017-552bb3c4c3bf/go.mod h1:E/q28EyUVBgBQnONAVPIdwvEsv4Ve0vaCA9JWim4+3I=
9799
github.com/lrstanley/girc v0.0.0-20240125042120-9add3166e52e h1:Y86mAFtJjS4P0atZ6QAKH88TV0ASQYJdIGWiOmJKoNY=
98100
github.com/lrstanley/girc v0.0.0-20240125042120-9add3166e52e/go.mod h1:lgrnhcF8bg/Bd5HA5DOb4Z+uGqUqGnp4skr+J2GwVgI=
99101
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

plugins.go

+29-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import (
44
"context"
55
"log"
66
"net/http"
7+
"net/url"
8+
"os"
79
"reflect"
810

911
"github.com/ailncode/gluaxmlpath"
1012
"github.com/cjoudrey/gluahttp"
1113
"github.com/google/generative-ai-go/genai"
1214
"github.com/jackc/pgx/v5"
1315
"github.com/kohkimakimoto/gluayaml"
16+
gopherjson "github.com/layeh/gopher-json"
1417
"github.com/lrstanley/girc"
1518
openai "github.com/sashabaranov/go-openai"
1619
"github.com/yuin/gluare"
@@ -331,9 +334,34 @@ func RunScript(scriptPath string, client *girc.Client, appConfig *TomlConfig) {
331334
luaState.PreloadModule("milla", millaModuleLoaderClosure(luaState, client, appConfig))
332335
gluasocket.Preload(luaState)
333336
gluaxmlpath.Preload(luaState)
334-
luaState.PreloadModule("http", gluahttp.NewHttpModule(&http.Client{}).Loader)
335337
luaState.PreloadModule("yaml", gluayaml.Loader)
336338
luaState.PreloadModule("re", gluare.Loader)
339+
luaState.PreloadModule("json", gopherjson.Loader)
340+
341+
var proxyString string
342+
if os.Getenv("ALL_PROXY") != "" {
343+
proxyString = os.Getenv("ALL_PROXY")
344+
} else if os.Getenv("HTTPS_PROXY") != "" {
345+
proxyString = os.Getenv("HTTPS_PROXY")
346+
} else if os.Getenv("HTTP_PROXY") != "" {
347+
proxyString = os.Getenv("HTTP_PROXY")
348+
} else if os.Getenv("https_proxy") != "" {
349+
proxyString = os.Getenv("https_proxy")
350+
} else if os.Getenv("http_proxy") != "" {
351+
proxyString = os.Getenv("http_proxy")
352+
}
353+
354+
proxyTransport := &http.Transport{}
355+
356+
if proxyString != "" {
357+
proxyURL, err := url.Parse(proxyString)
358+
if err != nil {
359+
log.Print(err)
360+
}
361+
proxyTransport.Proxy = http.ProxyURL(proxyURL)
362+
}
363+
364+
luaState.PreloadModule("http", gluahttp.NewHttpModule(&http.Client{Transport: proxyTransport}).Loader)
337365

338366
log.Print("Running script: ", scriptPath)
339367

plugins/ip.lua

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
local milla = require("milla")
2+
local os = require("os")
3+
local json = require("json")
4+
5+
os.setenv("ALL_PROXY", "socks5://172.17.0.1:9057")
6+
7+
local http = require("http")
8+
9+
local function get_ip(arg)
10+
local ip = arg
11+
local response, err = http.request("GET",
12+
"https://getip-api.com/json?" .. ip)
13+
local json_response, err = json.decode(response.body)
14+
15+
local result = ""
16+
for key, value in ipairs(json_response) do
17+
result = result .. key .. ": " .. value .. "\n"
18+
end
19+
20+
return result
21+
end
22+
23+
milla.register_cmd("ip", "get_ip")

plugins/proxy_test.lua

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
local milla = require("milla")
2+
local os = require("os")
3+
local json = require("json")
4+
5+
os.setenv("ALL_PROXY", "socks5://172.17.0.1:9057")
6+
7+
local http = require("http")
8+
9+
local response, err = http.request("GET", "https://icanhazip.com")
10+
print(response.body)

0 commit comments

Comments
 (0)