diff options
author | terminaldweller <devi@terminaldweller.com> | 2024-09-01 16:21:36 +0000 |
---|---|---|
committer | terminaldweller <devi@terminaldweller.com> | 2024-09-01 16:21:36 +0000 |
commit | bcbbf64fb78f3c7248987968cccc4c97a4c5e3a2 (patch) | |
tree | 82fe5fd8fb73ea9e1f90c67593faf683cad3a680 | |
parent | added the url to the rss output. fixed a bug with the rss feeds where differe... (diff) | |
download | milla-bcbbf64fb78f3c7248987968cccc4c97a4c5e3a2.tar.gz milla-bcbbf64fb78f3c7248987968cccc4c97a4c5e3a2.zip |
fixes 8
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | main.go | 45 | ||||
-rw-r--r-- | plugins.go | 20 | ||||
-rw-r--r-- | rss.go | 2 | ||||
-rw-r--r-- | types.go | 6 |
5 files changed, 57 insertions, 28 deletions
@@ -342,7 +342,7 @@ databaseAddress = "postgres:5432" databasePassword = "changeme" databaseUser = "devi" databaseName = "milla" -scrapeChannels = ["#soulhack", "#warroom"] +scrapeChannels = ["#soulhack", "#warroom", "#securityfeeds"] ircProxy = "socks5://127.0.0.1:9050" llmProxy = "http://127.0.0.1:8180" skipTLSVerify = false @@ -353,19 +353,15 @@ plugins = ["/plugins/ip.lua", "/plugins/urban.lua"] watchList = ["#securityfeeds"] watchFiles = ["/watchfiles/voidbox.list"] alertChannel = "#milla_alerts" +eventTypes = ["PRIVMSG"] +fgColor = 0 +bgColor = 28 [ircd.devinet.rss.manga] rssFile = "/rssfeeds/manga.json" channel = "#manga" [ircd.devinet.rss.anime] rssFile = "/rssfeeds/anime.json" channel = "#anime" -[ircd.devinet.watchlist.security] -watchList = ["#securityfeeds"] -watchFiles = ["/watchfiles/voidbox.list"] -alertChannel = "#milla_alerts" -eventTypes = ["PRIVMSG"] -fgColor = 0 -bgColor = 28 [ircd.liberanet] ircServer = "irc.libera.chat" @@ -315,7 +315,7 @@ func handleCustomCommand( logs, err := pgx.CollectRows(rows, pgx.RowToStructByName[LogModel]) if err != nil { - log.Println(err.Error()) + LogError(err) return } @@ -327,7 +327,7 @@ func handleCustomCommand( log.Println(logs) if err != nil { - log.Println(err.Error()) + LogError(err) return } @@ -807,15 +807,44 @@ func OllamaHandler( }) } +func (t *ProxyRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { + transport := http.DefaultTransport.(*http.Transport).Clone() + + if t.ProxyURL != "" { + proxyURL, err := url.Parse(t.ProxyURL) + if err != nil { + return nil, err + } + transport.Proxy = http.ProxyURL(proxyURL) + } + + newReq := req.Clone(req.Context()) + vals := newReq.URL.Query() + vals.Set("key", t.APIKey) + newReq.URL.RawQuery = vals.Encode() + + resp, err := transport.RoundTrip(newReq) + if err != nil { + return nil, err + } + + return resp, nil +} + func DoGeminiRequest( appConfig *TomlConfig, geminiMemory *[]*genai.Content, prompt string, ) (string, error) { + httpProxyClient := &http.Client{Transport: &ProxyRoundTripper{ + APIKey: appConfig.Apikey, + ProxyURL: appConfig.LLMProxy, + }} + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(appConfig.RequestTimeout)*time.Second) defer cancel() - clientGemini, err := genai.NewClient(ctx, option.WithAPIKey(appConfig.Apikey)) + clientGemini, err := genai.NewClient(ctx, option.WithHTTPClient(httpProxyClient)) if err != nil { return "", err @@ -1338,17 +1367,17 @@ func runIRC(appConfig TomlConfig) { if appConfig.IRCProxy != "" { proxyURL, err := url.Parse(appConfig.IRCProxy) if err != nil { - log.Fatal(err.Error()) + LogErrorFatal(err) } dialer, err = proxy.FromURL(proxyURL, &net.Dialer{Timeout: time.Duration(appConfig.RequestTimeout) * time.Second}) if err != nil { - log.Fatal(err.Error()) + LogErrorFatal(err) } } if err := irc.DialerConnect(dialer); err != nil { - log.Println(err) + LogError(err) log.Println("reconnecting in " + strconv.Itoa(appConfig.MillaReconnectDelay)) time.Sleep(time.Duration(appConfig.MillaReconnectDelay) * time.Second) } else { @@ -1367,14 +1396,14 @@ func main() { data, err := os.ReadFile(*configPath) if err != nil { - log.Fatal(err) + LogErrorFatal(err) } var config AppConfig _, err = toml.Decode(string(data), &config) if err != nil { - log.Fatal(err) + LogErrorFatal(err) } for key, value := range config.Ircd { @@ -244,7 +244,7 @@ func ollamaRequestClosure(luaState *lua.LState, appConfig *TomlConfig) func(*lua result, err := DoOllamaRequest(appConfig, &[]MemoryElement{}, prompt) if err != nil { - log.Print(err) + LogError(err) } luaState.Push(lua.LString(result)) @@ -259,7 +259,7 @@ func geminiRequestClosure(luaState *lua.LState, appConfig *TomlConfig) func(*lua result, err := DoGeminiRequest(appConfig, &[]*genai.Content{}, prompt) if err != nil { - log.Print(err) + LogError(err) } luaState.Push(lua.LString(result)) @@ -274,7 +274,7 @@ func chatGPTRequestClosure(luaState *lua.LState, appConfig *TomlConfig) func(*lu result, err := DoChatGPTRequest(appConfig, &[]openai.ChatCompletionMessage{}, prompt) if err != nil { - log.Print(err) + LogError(err) } luaState.Push(lua.LString(result)) @@ -295,13 +295,13 @@ func dbQueryClosure(luaState *lua.LState, appConfig *TomlConfig) func(*lua.LStat rows, err := appConfig.pool.Query(context.Background(), query) if err != nil { - log.Println(err.Error()) + LogError(err) } defer rows.Close() logs, err := pgx.CollectRows(rows, pgx.RowToStructByName[LogModel]) if err != nil { - log.Println(err.Error()) + LogError(err) } table := luaState.CreateTable(0, len(logs)) @@ -388,7 +388,7 @@ func RunScript(scriptPath string, client *girc.Client, appConfig *TomlConfig) { if proxyString != "" { proxyURL, err := url.Parse(proxyString) if err != nil { - log.Print(err) + LogError(err) } proxyTransport.Proxy = http.ProxyURL(proxyURL) } @@ -399,7 +399,7 @@ func RunScript(scriptPath string, client *girc.Client, appConfig *TomlConfig) { err := luaState.DoFile(scriptPath) if err != nil { - log.Print(err) + LogError(err) } } @@ -454,7 +454,7 @@ func RunLuaFunc( if proxyString != "" { proxyURL, err := url.Parse(proxyString) if err != nil { - log.Print(err) + LogError(err) } proxyTransport.Proxy = http.ProxyURL(proxyURL) } @@ -464,7 +464,7 @@ func RunLuaFunc( log.Print("Running lua command script: ", scriptPath) if err := luaState.DoFile(scriptPath); err != nil { - log.Print(err) + LogError(err) return "" } @@ -479,7 +479,7 @@ func RunLuaFunc( log.Print(args) if err := luaState.CallByParam(funcLValue, lua.LString(args)); err != nil { log.Print("failed running lua command ...") - log.Print(err) + LogError(err) return "" } @@ -41,8 +41,6 @@ func GetFeed(feed FeedConfig, pool.Exec(ctx, fmt.Sprintf("insert into rss (name, newest_unix_time) values ('%s',0)", rowName)) } - log.Print("Newset from DB: ", newestFromDB) - sortFunc := func(a, b *gofeed.Item) int { if a.PublishedParsed.Before(*b.PublishedParsed) { return -1 @@ -211,3 +211,9 @@ func LogErrorFatal(err error) { log.Fatal(err) } } + +type ProxyRoundTripper struct { + APIKey string + + ProxyURL string +} |