-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathplug.go
52 lines (44 loc) · 1.05 KB
/
plug.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
package main
import "math/rand"
import "time"
const DEFAULT_AD_CHANCE = 95
type Plug struct {
ID int
S3ID string
Owner string
ViewsRemaining int
Approved bool
PresignedURL string
}
type PlugList struct {
Data []string `form:"plugs[]"`
}
func (p Plug) IsDefault() bool {
return p.ViewsRemaining < 0
}
func ChoosePlug(plugs []Plug) Plug {
rand.Seed(time.Now().Unix())
// Split plugs into default and custom ads
var defaults []Plug
var customs []Plug
for i := 0; i < len(plugs); i++ {
if plugs[i].IsDefault() {
defaults = append(defaults, plugs[i])
} else {
customs = append(customs, plugs[i])
}
}
// Decide whether to chose default ad or user submitted ad
var pickDefault int = rand.Intn(100)
if pickDefault >= DEFAULT_AD_CHANCE || len(customs) == 0 {
return defaults[rand.Intn(len(defaults))]
} else {
return customs[rand.Intn(len(customs))]
}
}
func PlugValueInDrinkCredits(ldap LDAPConnection, username string) int {
if ldap.CheckIfIntroMember(username) {
return 1000
}
return 100
}