aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorterminaldweller <devi@terminaldweller.com>2024-11-04 23:40:55 +0000
committerterminaldweller <devi@terminaldweller.com>2024-11-04 23:40:55 +0000
commitd8f15ff06238dd96c62d96b5bfc4f4c3752fdeee (patch)
tree7da5f61390978b47fedac3b6d68e35f107b05afa
parentfixed the wrong condition (diff)
downloadmilla-d8f15ff06238dd96c62d96b5bfc4f4c3752fdeee.tar.gz
milla-d8f15ff06238dd96c62d96b5bfc4f4c3752fdeee.zip
added the iana whois command. added the new genelirc optionHEADmain
Diffstat (limited to '')
-rw-r--r--README.md12
-rw-r--r--iana_whois.go82
-rw-r--r--main.go10
-rw-r--r--types.go1
4 files changed, 104 insertions, 1 deletions
diff --git a/README.md b/README.md
index 8e67ac1..134be91 100644
--- a/README.md
+++ b/README.md
@@ -219,6 +219,14 @@ Determines which proxy to use to connect to the LLM endpoint:
llmProxy = "socks5://127.0.0.1:9050"
```
+#### generalProxy
+
+Determines which proxy to use for other things:
+
+```
+llmProxy = "socks5://127.0.0.1:9050"
+```
+
#### ircdName
Name of the milla instance, must be unique across all instances.
@@ -471,6 +479,10 @@ Pings the user after the given amount in seconds: `/remind 1200`
Rolls a number between 1 and 6 if no arguments are given. With one argument it rolls a number between 1 and the given number. With two arguments it rolls a number between the two numbers: `/rool 10000 66666`
+#### whois
+
+IANA whois endpoint query: `milla: /whois xyz`
+
## Deploy
### Docker
diff --git a/iana_whois.go b/iana_whois.go
new file mode 100644
index 0000000..ed80c6e
--- /dev/null
+++ b/iana_whois.go
@@ -0,0 +1,82 @@
+package main
+
+import (
+ "log"
+ "net"
+ "net/http"
+ "net/url"
+ "time"
+
+ "golang.org/x/net/html"
+ "golang.org/x/net/proxy"
+)
+
+func IANAWhoisGet(query string, appConfig *TomlConfig) string {
+ var httpClient http.Client
+
+ var dialer proxy.Dialer
+
+ if appConfig.GeneralProxy != "" {
+ proxyURL, err := url.Parse(appConfig.GeneralProxy)
+ if err != nil {
+ log.Fatal(err.Error())
+
+ return ""
+ }
+
+ dialer, err = proxy.FromURL(proxyURL, &net.Dialer{Timeout: time.Duration(appConfig.RequestTimeout) * time.Second})
+ if err != nil {
+ log.Fatal(err.Error())
+
+ return ""
+ }
+
+ httpClient = http.Client{
+ Transport: &http.Transport{
+ Dial: dialer.Dial,
+ },
+ }
+ }
+
+ resp, err := httpClient.Get("https://www.iana.org/whois?q=" + query)
+ if err != nil {
+ log.Println(err)
+
+ return ""
+ }
+
+ defer resp.Body.Close()
+
+ doc, err := html.Parse(resp.Body)
+ if err != nil {
+ log.Println(err)
+
+ return ""
+ }
+
+ var getContent func(*html.Node) string
+
+ getContent = func(n *html.Node) string {
+ if n.Type == html.ElementNode && n.Data == "pre" {
+ var content string
+ for c := n.FirstChild; c != nil; c = c.NextSibling {
+ if c.Type == html.TextNode {
+ content += c.Data
+ }
+ }
+ return content
+ }
+ for c := n.FirstChild; c != nil; c = c.NextSibling {
+ result := getContent(c)
+ if result != "" {
+ return result
+ }
+ }
+ return ""
+ }
+
+ preContent := getContent(doc)
+ log.Println(preContent)
+
+ return preContent
+}
diff --git a/main.go b/main.go
index 6d0d349..31b9c88 100644
--- a/main.go
+++ b/main.go
@@ -594,6 +594,15 @@ func runCommand(
case "forget":
client.Cmd.Reply(event, "I no longer even know whether you're supposed to wear or drink a camel.'")
+ case "whois":
+ if len(args) < 2 {
+ client.Cmd.Reply(event, errNotEnoughArgs.Error())
+
+ break
+ }
+
+ ianaResponse := IANAWhoisGet(args[1], appConfig)
+ client.Cmd.Reply(event, ianaResponse)
case "roll":
lowerLimit := 1
upperLimit := 6
@@ -1227,7 +1236,6 @@ func populateWatchListWords(appConfig *TomlConfig) {
}
}
- // log.Print(appConfig.WatchLists["security"].Words)
}
func WatchListHandler(irc *girc.Client, appConfig TomlConfig) {
diff --git a/types.go b/types.go
index 7f1be93..8533525 100644
--- a/types.go
+++ b/types.go
@@ -73,6 +73,7 @@ type TomlConfig struct {
DatabaseName string `toml:"databaseName"`
LLMProxy string `toml:"llmProxy"`
IRCProxy string `toml:"ircProxy"`
+ GeneralProxy string `toml:"generalProxy"`
IRCDName string `toml:"ircdName"`
WebIRCPassword string `toml:"webIRCPassword"`
WebIRCGateway string `toml:"webIRCGateway"`