From f82a89f9b5a8c416e043258ff8f3a9afddd31609 Mon Sep 17 00:00:00 2001 From: furtidev Date: Thu, 23 Nov 2023 23:22:20 +0600 Subject: [PATCH] removed some stuff --- main.go | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/main.go b/main.go index c9fd60f..3cfbb46 100644 --- a/main.go +++ b/main.go @@ -7,9 +7,6 @@ import ( "os/signal" "syscall" "strings" - "regexp" - "io" - "net/http" "github.com/bwmarrin/discordgo" "github.com/spf13/viper" @@ -75,40 +72,5 @@ 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?0QATm", 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 - re := regexp.MustCompile(`(?i)((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[.\!\/\\w]*))?)`) - result := re.FindStringSubmatch(m.Content) - // hard coded, group 2 contains the base url - if len(result) >= 3 { - if result[2] == "https://www.reddit.com" || result[2] == "https://reddit.com"{ - s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("", result[4])) - } else if result[2] == "https://www.twitter.com" || result[2] == "https://twitter.com" { - s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("", result[4])) - } } }