-
Notifications
You must be signed in to change notification settings - Fork 2
/
bits.go
67 lines (59 loc) · 1.75 KB
/
bits.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
package repos
import (
"github.com/khades/servbot/models"
"gopkg.in/mgo.v2/bson"
)
var bitsCollection = "bits"
func AddBitsToUser(channelID *string, userID *string, user *string, amount int, reason string) {
Db.C(bitsCollection).Upsert(bson.M{
"channelid": *channelID,
"userid": *userID},
bson.M{
"$inc": bson.M{"amount": amount},
"$set": bson.M{"user": *user},
"$push": bson.M{
"history": bson.M{
"$each": []models.UserBitsHistory{models.UserBitsHistory{Reason: reason, Change: amount}},
"$sort": bson.M{"date": -1},
"$slice": 100}}})
}
func GetBitsForChannel(channelID *string, pattern *string) (*[]models.UserBits, error) {
var result []models.UserBits
if *pattern == "" {
error := Db.C(bitsCollection).Find(models.ChannelSelector{ChannelID: *channelID}).Sort("change.date").Limit(100).All(&result)
return &result, error
}
error := Db.C(bitsCollection).Find(bson.M{
"channelid": *channelID,
"user": bson.M{
"$regex": *pattern,
"$options": "i"}}).Sort("change.date").Limit(100).All(&result)
return &result, error
}
func GetBitsForChannelUser(channelID *string, userID *string) (*models.UserBitsWithHistory, error) {
var result models.UserBitsWithHistory
error := Db.C(bitsCollection).Find(bson.M{
"channelid": *channelID,
"userid": *userID}).One(&result)
return &result, error
}
func PutSubscriptionBits(channelID *string, userID *string, user *string, subPlan *string) {
switch *subPlan {
case "Prime":
{
AddBitsToUser(channelID, userID, user, 499, "subprime")
}
case "1000":
{
AddBitsToUser(channelID, userID, user, 499, "sub")
}
case "2000":
{
AddBitsToUser(channelID, userID, user, 999, "sub")
}
case "3000":
{
AddBitsToUser(channelID, userID, user, 2499, "sub")
}
}
}