github.com/diamondburned/arikawa/v2@v2.1.0/api/rate/majors.go (about) 1 package rate 2 3 import ( 4 "strconv" 5 "strings" 6 ) 7 8 // TODO: webhook 9 var MajorRootPaths = []string{"channels", "guilds"} 10 11 func ParseBucketKey(path string) string { 12 path = strings.SplitN(path, "?", 2)[0] 13 14 parts := strings.Split(path, "/") 15 if len(parts) < 1 { 16 return path 17 } 18 19 parts = parts[1:] // [0] is just "" since URL 20 21 var skip int 22 23 for _, part := range MajorRootPaths { 24 if part == parts[0] { 25 skip = 2 26 break 27 } 28 } 29 30 // We add 1, since this is the string path. The path following this would be 31 // the actual value, which we check. 32 skip++ 33 34 // we need to remove IDs from these 35 for ; skip < len(parts); skip += 2 { 36 // Check if it's a number: 37 if _, err := strconv.Atoi(parts[skip]); err == nil { 38 parts[skip] = "" 39 continue 40 } 41 42 // Check if it's an emoji: 43 if StringIsEmojiOnly(parts[skip]) { 44 parts[skip] = "" 45 continue 46 } 47 48 // Check if it's a custom emoji: 49 if StringIsCustomEmoji(parts[skip]) { 50 parts[skip] = "" 51 continue 52 } 53 } 54 55 // rejoin url 56 path = strings.Join(parts, "/") 57 return "/" + path 58 }