1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-01 04:24:19 +00:00
arikawa/api/rate/majors.go

59 lines
1 KiB
Go
Raw Normal View History

2020-01-08 07:10:37 +00:00
package rate
import (
"strconv"
"strings"
)
// TODO: webhook
var MajorRootPaths = []string{"channels", "guilds"}
func ParseBucketKey(path string) string {
path = strings.SplitN(path, "?", 2)[0]
parts := strings.Split(path, "/")
if len(parts) < 1 {
return path
}
parts = parts[1:] // [0] is just "" since URL
var skip int
for _, part := range MajorRootPaths {
if part == parts[0] {
skip = 2
break
}
}
2020-02-07 16:37:01 +00:00
// We add 1, since this is the string path. The path following this would be
// the actual value, which we check.
skip++
2020-01-08 07:10:37 +00:00
// we need to remove IDs from these
2020-02-07 16:37:01 +00:00
for ; skip < len(parts); skip += 2 {
// Check if it's a number:
2020-01-08 07:10:37 +00:00
if _, err := strconv.Atoi(parts[skip]); err == nil {
parts[skip] = ""
continue
}
// Check if it's an emoji:
if StringIsEmojiOnly(parts[skip]) {
parts[skip] = ""
continue
}
// Check if it's a custom emoji:
if StringIsCustomEmoji(parts[skip]) {
parts[skip] = ""
continue
2020-01-08 07:10:37 +00:00
}
}
// rejoin url
path = strings.Join(parts, "/")
return "/" + path
}