aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--README.md12
-rw-r--r--main.go45
-rw-r--r--plugins.go20
-rw-r--r--rss.go2
-rw-r--r--types.go6
5 files changed, 57 insertions, 28 deletions
diff --git a/README.md b/README.md
index 3a41db3..4f213f0 100644
--- a/README.md
+++ b/README.md
@@ -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"
diff --git a/main.go b/main.go
index ba45d85..b4c3301 100644
--- a/main.go
+++ b/main.go
@@ -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 {
diff --git a/plugins.go b/plugins.go
index 2503e3d..3e29570 100644
--- a/plugins.go
+++ b/plugins.go
@@ -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 ""
}
diff --git a/rss.go b/rss.go
index 1546f8a..60a8066 100644
--- a/rss.go
+++ b/rss.go
@@ -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
diff --git a/types.go b/types.go
index 79ef000..78c1337 100644
--- a/types.go
+++ b/types.go
@@ -211,3 +211,9 @@ func LogErrorFatal(err error) {
log.Fatal(err)
}
}
+
+type ProxyRoundTripper struct {
+ APIKey string
+
+ ProxyURL string
+}