aboutsummaryrefslogtreecommitdiffstats
path: root/plugins.go
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-07-30 23:25:59 +0000
committerterminaldweller <devi@terminaldweller.com>2024-07-30 23:25:59 +0000
commit81469bbb1745a835676c3664e75a4a951223da9d (patch)
tree70a53b118c406d5958a8fb8c72e391fb6439f729 /plugins.go
parentwe can now add new commands from lua plugins (diff)
downloadmilla-81469bbb1745a835676c3664e75a4a951223da9d.tar.gz
milla-81469bbb1745a835676c3664e75a4a951223da9d.zip
* fixed a crash when unloading a lua script
* added event types, foreground and background color for watchlists * added a url_encode function to lua to encode urls. Underneath, it just calls the standard library function from golang * updated the README * the urban plugin now can take in the number of entries to return * reverted a bug where setting the http proxy for the lua http module was not working * fixed the url for the ip script so it is actually working. the current provider does not support ipv6 though
Diffstat (limited to 'plugins.go')
-rw-r--r--plugins.go27
1 files changed, 19 insertions, 8 deletions
diff --git a/plugins.go b/plugins.go
index c2775db..8e15976 100644
--- a/plugins.go
+++ b/plugins.go
@@ -197,7 +197,6 @@ func sendMessageClosure(luaState *lua.LState, client *girc.Client) func(*lua.LSt
return 0
}
}
-
func registerLuaCommand(luaState *lua.LState, appConfig *TomlConfig) func(*lua.LState) int {
return func(luaState *lua.LState) int {
path := luaState.CheckString(1)
@@ -317,6 +316,15 @@ func dbQueryClosure(luaState *lua.LState, appConfig *TomlConfig) func(*lua.LStat
}
}
+func urlEncode(luaState *lua.LState) func(*lua.LState) int {
+ return func(luaState *lua.LState) int {
+ URL := luaState.CheckString(1)
+ escapedURL := url.QueryEscape(URL)
+ luaState.Push(lua.LString(escapedURL))
+ return 1
+ }
+}
+
func millaModuleLoaderClosure(luaState *lua.LState, client *girc.Client, appConfig *TomlConfig) func(*lua.LState) int {
return func(luaState *lua.LState) int {
exports := map[string]lua.LGFunction{
@@ -328,6 +336,7 @@ func millaModuleLoaderClosure(luaState *lua.LState, client *girc.Client, appConf
"send_chatgpt_request": lua.LGFunction(chatGPTRequestClosure(luaState, appConfig)),
"query_db": lua.LGFunction(dbQueryClosure(luaState, appConfig)),
"register_cmd": lua.LGFunction(registerLuaCommand(luaState, appConfig)),
+ "url_encode": lua.LGFunction(urlEncode(luaState)),
}
millaModule := luaState.SetFuncs(luaState.NewTable(), exports)
@@ -425,20 +434,20 @@ func RunLuaFunc(
luaState.PreloadModule("json", gopherjson.Loader)
var proxyString string
- switch proxyString {
- case os.Getenv("ALL_PROXY"):
+ if os.Getenv("ALL_PROXY") != "" {
proxyString = os.Getenv("ALL_PROXY")
- case os.Getenv("HTTPS_PROXY"):
+ } else if os.Getenv("HTTPS_PROXY") != "" {
proxyString = os.Getenv("HTTPS_PROXY")
- case os.Getenv("HTTP_PROXY"):
+ } else if os.Getenv("HTTP_PROXY") != "" {
proxyString = os.Getenv("HTTP_PROXY")
- case os.Getenv("https_proxy"):
+ } else if os.Getenv("https_proxy") != "" {
proxyString = os.Getenv("https_proxy")
- case os.Getenv("http_proxy"):
+ } else if os.Getenv("http_proxy") != "" {
proxyString = os.Getenv("http_proxy")
- default:
}
+ log.Print("set proxy env to:", proxyString)
+
proxyTransport := &http.Transport{}
if proxyString != "" {
@@ -465,6 +474,8 @@ func RunLuaFunc(
Protect: true,
}
+ log.Print(cmd)
+ log.Print(args)
if err := luaState.CallByParam(funcLValue, lua.LString(args)); err != nil {
log.Print("failed running lua command ...")
log.Print(err)