forked from furtidev/the-farting-whale
added \!weather
This commit is contained in:
parent
feacda166a
commit
cc18c89cd4
25
main.go
25
main.go
@ -8,6 +8,8 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"strings"
|
"strings"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"github.com/spf13/viper"
|
"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]))
|
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf(":whale2: :dash: %s", c[1]))
|
||||||
}
|
}
|
||||||
return
|
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
|
// check for reddit/twitter links and replace them with open source frontends
|
||||||
|
Loading…
Reference in New Issue
Block a user