Skip to content

Commit d8f15ff

Browse files
added the iana whois command. added the new genelirc option
1 parent 5fc1795 commit d8f15ff

File tree

4 files changed

+104
-1
lines changed

4 files changed

+104
-1
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,14 @@ Determines which proxy to use to connect to the LLM endpoint:
219219
llmProxy = "socks5://127.0.0.1:9050"
220220
```
221221

222+
#### generalProxy
223+
224+
Determines which proxy to use for other things:
225+
226+
```
227+
llmProxy = "socks5://127.0.0.1:9050"
228+
```
229+
222230
#### ircdName
223231

224232
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`
471479

472480
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`
473481

482+
#### whois
483+
484+
IANA whois endpoint query: `milla: /whois xyz`
485+
474486
## Deploy
475487

476488
### Docker

iana_whois.go

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net"
6+
"net/http"
7+
"net/url"
8+
"time"
9+
10+
"golang.org/x/net/html"
11+
"golang.org/x/net/proxy"
12+
)
13+
14+
func IANAWhoisGet(query string, appConfig *TomlConfig) string {
15+
var httpClient http.Client
16+
17+
var dialer proxy.Dialer
18+
19+
if appConfig.GeneralProxy != "" {
20+
proxyURL, err := url.Parse(appConfig.GeneralProxy)
21+
if err != nil {
22+
log.Fatal(err.Error())
23+
24+
return ""
25+
}
26+
27+
dialer, err = proxy.FromURL(proxyURL, &net.Dialer{Timeout: time.Duration(appConfig.RequestTimeout) * time.Second})
28+
if err != nil {
29+
log.Fatal(err.Error())
30+
31+
return ""
32+
}
33+
34+
httpClient = http.Client{
35+
Transport: &http.Transport{
36+
Dial: dialer.Dial,
37+
},
38+
}
39+
}
40+
41+
resp, err := httpClient.Get("https://www.iana.org/whois?q=" + query)
42+
if err != nil {
43+
log.Println(err)
44+
45+
return ""
46+
}
47+
48+
defer resp.Body.Close()
49+
50+
doc, err := html.Parse(resp.Body)
51+
if err != nil {
52+
log.Println(err)
53+
54+
return ""
55+
}
56+
57+
var getContent func(*html.Node) string
58+
59+
getContent = func(n *html.Node) string {
60+
if n.Type == html.ElementNode && n.Data == "pre" {
61+
var content string
62+
for c := n.FirstChild; c != nil; c = c.NextSibling {
63+
if c.Type == html.TextNode {
64+
content += c.Data
65+
}
66+
}
67+
return content
68+
}
69+
for c := n.FirstChild; c != nil; c = c.NextSibling {
70+
result := getContent(c)
71+
if result != "" {
72+
return result
73+
}
74+
}
75+
return ""
76+
}
77+
78+
preContent := getContent(doc)
79+
log.Println(preContent)
80+
81+
return preContent
82+
}

main.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,15 @@ func runCommand(
594594
case "forget":
595595

596596
client.Cmd.Reply(event, "I no longer even know whether you're supposed to wear or drink a camel.'")
597+
case "whois":
598+
if len(args) < 2 {
599+
client.Cmd.Reply(event, errNotEnoughArgs.Error())
600+
601+
break
602+
}
603+
604+
ianaResponse := IANAWhoisGet(args[1], appConfig)
605+
client.Cmd.Reply(event, ianaResponse)
597606
case "roll":
598607
lowerLimit := 1
599608
upperLimit := 6
@@ -1227,7 +1236,6 @@ func populateWatchListWords(appConfig *TomlConfig) {
12271236
}
12281237
}
12291238

1230-
// log.Print(appConfig.WatchLists["security"].Words)
12311239
}
12321240

12331241
func WatchListHandler(irc *girc.Client, appConfig TomlConfig) {

types.go

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type TomlConfig struct {
7373
DatabaseName string `toml:"databaseName"`
7474
LLMProxy string `toml:"llmProxy"`
7575
IRCProxy string `toml:"ircProxy"`
76+
GeneralProxy string `toml:"generalProxy"`
7677
IRCDName string `toml:"ircdName"`
7778
WebIRCPassword string `toml:"webIRCPassword"`
7879
WebIRCGateway string `toml:"webIRCGateway"`

0 commit comments

Comments
 (0)