Compare commits
2 Commits
feacda166a
...
2201a35120
Author | SHA1 | Date | |
---|---|---|---|
|
2201a35120 | ||
|
cc18c89cd4 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
.env
|
||||
hop.yml
|
25
main.go
25
main.go
@ -8,6 +8,8 @@ import (
|
||||
"syscall"
|
||||
"strings"
|
||||
"regexp"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/spf13/viper"
|
||||
@ -73,6 +75,29 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf(":whale2: :dash: %s", c[1]))
|
||||
}
|
||||
return
|
||||
} else if strings.HasPrefix(m.Content, "!weather") {
|
||||
c := strings.Fields(m.Content)
|
||||
if len(c) == 2 {
|
||||
// contact wttr.in
|
||||
url := fmt.Sprintf("https://wttr.in/%s?0QAT", c[1])
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR while running $weather: %s", err)
|
||||
return
|
||||
}
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR while running $weather: %s", err)
|
||||
return
|
||||
}
|
||||
body_string := string(body[:])
|
||||
if strings.Contains(body_string, "404 UNKNOWN") {
|
||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("That's not a city, silly!"))
|
||||
return
|
||||
}
|
||||
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("```%s```", body_string))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// check for reddit/twitter links and replace them with open source frontends
|
||||
|
Loading…
Reference in New Issue
Block a user