2019-06-03 09:32:43 +00:00
|
|
|
package arn
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/aerogo/nano"
|
|
|
|
)
|
|
|
|
|
|
|
|
// IgnoreAnimeDifferenceEditorScore represents how many points you get for a diff ignore.
|
|
|
|
const IgnoreAnimeDifferenceEditorScore = 2
|
|
|
|
|
|
|
|
// IgnoreAnimeDifference saves which differences between anime databases can be ignored.
|
|
|
|
type IgnoreAnimeDifference struct {
|
|
|
|
ValueHash uint64 `json:"valueHash"`
|
|
|
|
|
2019-09-07 10:56:13 +00:00
|
|
|
// The ID is built like this: arn:323|mal:356|JapaneseTitle
|
|
|
|
hasID
|
2019-06-03 09:32:43 +00:00
|
|
|
hasCreator
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetIgnoreAnimeDifference ...
|
2019-11-18 06:13:51 +00:00
|
|
|
func GetIgnoreAnimeDifference(id ID) (*IgnoreAnimeDifference, error) {
|
2019-06-03 09:32:43 +00:00
|
|
|
obj, err := DB.Get("IgnoreAnimeDifference", id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj.(*IgnoreAnimeDifference), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateDifferenceID ...
|
2019-06-07 01:50:38 +00:00
|
|
|
func CreateDifferenceID(animeID AnimeID, dataProvider string, malAnimeID string, typeName string) string {
|
2019-06-03 09:32:43 +00:00
|
|
|
return fmt.Sprintf("arn:%s|%s:%s|%s", animeID, dataProvider, malAnimeID, typeName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// IsAnimeDifferenceIgnored tells you whether the given difference is being ignored.
|
2019-06-07 01:50:38 +00:00
|
|
|
func IsAnimeDifferenceIgnored(animeID AnimeID, dataProvider string, malAnimeID string, typeName string, hash uint64) bool {
|
2019-06-03 09:32:43 +00:00
|
|
|
key := CreateDifferenceID(animeID, dataProvider, malAnimeID, typeName)
|
|
|
|
ignore, err := GetIgnoreAnimeDifference(key)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return ignore.ValueHash == hash
|
|
|
|
}
|
|
|
|
|
|
|
|
// StreamIgnoreAnimeDifferences returns a stream of all ignored differences.
|
|
|
|
func StreamIgnoreAnimeDifferences() <-chan *IgnoreAnimeDifference {
|
|
|
|
channel := make(chan *IgnoreAnimeDifference, nano.ChannelBufferSize)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for obj := range DB.All("IgnoreAnimeDifference") {
|
|
|
|
channel <- obj.(*IgnoreAnimeDifference)
|
|
|
|
}
|
|
|
|
|
|
|
|
close(channel)
|
|
|
|
}()
|
|
|
|
|
|
|
|
return channel
|
|
|
|
}
|
|
|
|
|
|
|
|
// AllIgnoreAnimeDifferences returns a slice of all ignored differences.
|
|
|
|
func AllIgnoreAnimeDifferences() []*IgnoreAnimeDifference {
|
|
|
|
all := make([]*IgnoreAnimeDifference, 0, DB.Collection("IgnoreAnimeDifference").Count())
|
|
|
|
|
|
|
|
stream := StreamIgnoreAnimeDifferences()
|
|
|
|
|
|
|
|
for obj := range stream {
|
|
|
|
all = append(all, obj)
|
|
|
|
}
|
|
|
|
|
|
|
|
return all
|
|
|
|
}
|
|
|
|
|
|
|
|
// FilterIgnoreAnimeDifferences filters all ignored differences by a custom function.
|
|
|
|
func FilterIgnoreAnimeDifferences(filter func(*IgnoreAnimeDifference) bool) []*IgnoreAnimeDifference {
|
|
|
|
var filtered []*IgnoreAnimeDifference
|
|
|
|
|
|
|
|
for obj := range StreamIgnoreAnimeDifferences() {
|
|
|
|
if filter(obj) {
|
|
|
|
filtered = append(filtered, obj)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filtered
|
|
|
|
}
|