Compare commits

...

2 Commits

Author SHA1 Message Date
furtidev
2201a35120
ignoring my cloud config 2023-05-26 17:51:07 +06:00
furtidev
cc18c89cd4
added \!weather 2023-05-26 17:50:43 +06:00
2 changed files with 27 additions and 1 deletions

3
.gitignore vendored
View File

@ -1 +1,2 @@
.env .env
hop.yml

25
main.go
View File

@ -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