fixed crashes

This commit is contained in:
furtidev 2023-05-04 17:36:48 +06:00
parent 83963f5994
commit cd46c4944f
No known key found for this signature in database

10
main.go
View File

@ -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("<https://tedd.it%s>", result[4]))
} else if result[2] == "https://www.twitter.com" || result[2] == "https://twitter.com" {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("<https://nitter.fly.dev%s>", result[4]))
if len(result) >= 3 {
if result[2] == "https://www.reddit.com" || result[2] == "https://reddit.com"{
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("<https://tedd.it%s>", result[4]))
} else if result[2] == "https://www.twitter.com" || result[2] == "https://twitter.com" {
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf("<https://nitter.it%s>", result[4]))
}
}
}