mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-16 20:03:38 +00:00
42 lines
679 B
Go
42 lines
679 B
Go
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
|
|
}
|
|
}
|
|
|
|
// we need to remove IDs from these
|
|
for ; skip < len(parts); skip++ {
|
|
if _, err := strconv.Atoi(parts[skip]); err == nil {
|
|
// is a number, DELET
|
|
parts[skip] = ""
|
|
}
|
|
}
|
|
|
|
// rejoin url
|
|
path = strings.Join(parts, "/")
|
|
return "/" + path
|
|
}
|