This repository has been archived by the owner on Jun 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
IgnoreAnimeDifference.go
88 lines (65 loc) · 2.34 KB
/
IgnoreAnimeDifference.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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 {
// The ID is built like this: arn:323|mal:356|JapaneseTitle
ID string `json:"id"`
ValueHash uint64 `json:"valueHash"`
hasCreator
}
// GetIgnoreAnimeDifference ...
func GetIgnoreAnimeDifference(id string) (*IgnoreAnimeDifference, error) {
obj, err := DB.Get("IgnoreAnimeDifference", id)
if err != nil {
return nil, err
}
return obj.(*IgnoreAnimeDifference), nil
}
// CreateDifferenceID ...
func CreateDifferenceID(animeID string, dataProvider string, malAnimeID string, typeName string) string {
return fmt.Sprintf("arn:%s|%s:%s|%s", animeID, dataProvider, malAnimeID, typeName)
}
// IsAnimeDifferenceIgnored tells you whether the given difference is being ignored.
func IsAnimeDifferenceIgnored(animeID string, dataProvider string, malAnimeID string, typeName string, hash uint64) bool {
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
}