diff --git a/main.go b/main.go index 03e6458..066bda5 100644 --- a/main.go +++ b/main.go @@ -79,9 +79,11 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { 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 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])) + 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])) + } } -} \ No newline at end of file +}