Fixed bug with general processor
It wasn't pulling stats for single digit hours correctly The other files were changed to get it to compile
This commit is contained in:
parent
cc9bfd43b5
commit
9760208632
@ -67,7 +67,7 @@ func getAllNonLevelUpStats(user string) map[string]int {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAllUserAcheivements(user string) map[string]int {
|
func getAllUserAchievements(user string) map[string]bool {
|
||||||
openDatabase()
|
openDatabase()
|
||||||
ret := make(map[string]bool)
|
ret := make(map[string]bool)
|
||||||
db.Update(func(tx *bolt.Tx) error {
|
db.Update(func(tx *bolt.Tx) error {
|
||||||
|
@ -101,6 +101,8 @@ func (p *generalStatProcessor) GetStatKeys() []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *generalStatProcessor) Initialize() {}
|
||||||
|
|
||||||
func (p *generalStatProcessor) ProcessMessage(m *Message) {
|
func (p *generalStatProcessor) ProcessMessage(m *Message) {
|
||||||
if m.Type == "message" {
|
if m.Type == "message" {
|
||||||
incrementUserStat(m.User, "message-hour-"+m.Time.Format("15"))
|
incrementUserStat(m.User, "message-hour-"+m.Time.Format("15"))
|
||||||
@ -222,7 +224,7 @@ func (wm *generalWebModule) handleStats(w http.ResponseWriter, req *http.Request
|
|||||||
MessageCount: getChannelMessageCount(k),
|
MessageCount: getChannelMessageCount(k),
|
||||||
})
|
})
|
||||||
for i := 0; i < 24; i++ {
|
for i := 0; i < 24; i++ {
|
||||||
if hrI, err := getChannelStat(k, fmt.Sprintf("message-hour-%0d", i)); err == nil {
|
if hrI, err := getChannelStat(k, fmt.Sprintf("message-hour-%02d", i)); err == nil {
|
||||||
s.MessageStats.Hours[i] = s.MessageStats.Hours[i] + hrI
|
s.MessageStats.Hours[i] = s.MessageStats.Hours[i] + hrI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -245,7 +247,7 @@ func (wm *generalWebModule) handleStats(w http.ResponseWriter, req *http.Request
|
|||||||
chanMsg = 0
|
chanMsg = 0
|
||||||
}
|
}
|
||||||
for i := 0; i < 24; i++ {
|
for i := 0; i < 24; i++ {
|
||||||
if hrI, err := getUserStat(k, fmt.Sprintf("message-hour-%0d", i)); err == nil {
|
if hrI, err := getUserStat(k, fmt.Sprintf("message-hour-%02d", i)); err == nil {
|
||||||
usrHourStats[i] = hrI
|
usrHourStats[i] = hrI
|
||||||
} else {
|
} else {
|
||||||
usrHourStats[i] = 0
|
usrHourStats[i] = 0
|
||||||
|
@ -7,12 +7,13 @@ type levelUpAchievement struct {
|
|||||||
GetText func() string
|
GetText func() string
|
||||||
GetKeyName func() string
|
GetKeyName func() string
|
||||||
// Processes the message, returns true if the achievement was triggered
|
// Processes the message, returns true if the achievement was triggered
|
||||||
ProcessMessage func(ustat *UserLevelUpStats) bool
|
ProcessMessage func(ustat *UserLevelUpStats, m *Message) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (achieve *levelUpAchievement) DoesUserHave(ustat *UserLevelUpStats) bool {
|
func (achieve *levelUpAchievement) DoesUserHave(ustat *UserLevelUpStats) bool {
|
||||||
val, ok := ustat.Achievements[achieve.GetKeyName()]
|
//val, ok := ustat.Achievements[achieve.GetKeyName()]
|
||||||
if ustat.Achievements
|
//if ustat.Achievements
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
type levelUpAchieveStatProcessor struct {
|
type levelUpAchieveStatProcessor struct {
|
||||||
@ -60,9 +61,9 @@ func (p *levelUpAchieveStatProcessor) ProcessMessage(m *Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, achieve := range p.Achievements {
|
for _, achieve := range p.Achievements {
|
||||||
if !achieve.DoesUserHave(userStat) {
|
if !achieve.DoesUserHave(&userStat) {
|
||||||
// User doesn't already have this achieve, let it process the message
|
// User doesn't already have this achieve, let it process the message
|
||||||
achieve.ProcessMessage(userStat)
|
achieve.ProcessMessage(&userStat, m)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,7 +117,7 @@ func (wm *levelUpAchieveWebModule) handleLevelUpAchieveGeneral(w http.ResponseWr
|
|||||||
* It's down here because it's so long what with all
|
* It's down here because it's so long what with all
|
||||||
* of it's achievements and such.
|
* of it's achievements and such.
|
||||||
*/
|
*/
|
||||||
func (p *levelUpAcheiveStatProcessor) Initialize() {
|
func (p *levelUpAchieveStatProcessor) Initialize() {
|
||||||
// TODO: Set up achievements
|
// TODO: Set up achievements
|
||||||
p.Achievements = append(p.Achievements,
|
p.Achievements = append(p.Achievements,
|
||||||
// Early Bird Achievement
|
// Early Bird Achievement
|
||||||
@ -130,13 +131,13 @@ func (p *levelUpAcheiveStatProcessor) Initialize() {
|
|||||||
GetKeyName: func() string {
|
GetKeyName: func() string {
|
||||||
return "levelup-achieve-earlybird"
|
return "levelup-achieve-earlybird"
|
||||||
},
|
},
|
||||||
ProcessMessage: func(u *userStat) bool {
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
||||||
// TODO: What condition makes this happen?
|
// TODO: What condition makes this happen?
|
||||||
if m.Time.Hour() > 3 && m.Time.Hour() < 7 {
|
if m.Time.Hour() > 3 && m.Time.Hour() < 7 {
|
||||||
numMsgs := 0
|
numMsgs := 0
|
||||||
numMsgs = numMsgs + userStat.OtherStats["message-hour-04"]
|
numMsgs = numMsgs + u.OtherStats["message-hour-04"]
|
||||||
numMsgs = numMsgs + userStat.OtherStats["message-hour-05"]
|
numMsgs = numMsgs + u.OtherStats["message-hour-05"]
|
||||||
numMsgs = numMsgs + userStat.OtherStats["message-hour-06"]
|
numMsgs = numMsgs + u.OtherStats["message-hour-06"]
|
||||||
/*
|
/*
|
||||||
if chnl.Name == "random" {
|
if chnl.Name == "random" {
|
||||||
addUserStat(m.User, "levelup-xp", 1)
|
addUserStat(m.User, "levelup-xp", 1)
|
||||||
@ -165,8 +166,9 @@ func (p *levelUpAcheiveStatProcessor) Initialize() {
|
|||||||
GetKeyName: func() string {
|
GetKeyName: func() string {
|
||||||
return "levelup-achieve-nightowl"
|
return "levelup-achieve-nightowl"
|
||||||
},
|
},
|
||||||
ProcessMessage: func(u *userStat) bool {
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
||||||
// TODO: What condition makes this happen?
|
// TODO: What condition makes this happen?
|
||||||
|
return false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -183,8 +185,9 @@ func (p *levelUpAcheiveStatProcessor) Initialize() {
|
|||||||
GetKeyName: func() string {
|
GetKeyName: func() string {
|
||||||
return "levelup-achieve-aroundtheclock"
|
return "levelup-achieve-aroundtheclock"
|
||||||
},
|
},
|
||||||
ProcessMessage: func(u *userStat) bool {
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
||||||
// TODO: What condition makes this happen?
|
// TODO: What condition makes this happen?
|
||||||
|
return false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -201,8 +204,9 @@ func (p *levelUpAcheiveStatProcessor) Initialize() {
|
|||||||
GetKeyName: func() string {
|
GetKeyName: func() string {
|
||||||
return "levelup-achieve-beginner"
|
return "levelup-achieve-beginner"
|
||||||
},
|
},
|
||||||
ProcessMessage: func(u *userStat) bool {
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
||||||
// TODO: What condition makes this happen?
|
// TODO: What condition makes this happen?
|
||||||
|
return false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -219,8 +223,9 @@ func (p *levelUpAcheiveStatProcessor) Initialize() {
|
|||||||
GetKeyName: func() string {
|
GetKeyName: func() string {
|
||||||
return "levelup-achieve-experienced"
|
return "levelup-achieve-experienced"
|
||||||
},
|
},
|
||||||
ProcessMessage: func(u *userStat) bool {
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
||||||
// TODO: What condition makes this happen?
|
// TODO: What condition makes this happen?
|
||||||
|
return false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -237,8 +242,9 @@ func (p *levelUpAcheiveStatProcessor) Initialize() {
|
|||||||
GetKeyName: func() string {
|
GetKeyName: func() string {
|
||||||
return "levelup-achieve-superadvanced"
|
return "levelup-achieve-superadvanced"
|
||||||
},
|
},
|
||||||
ProcessMessage: func(u *userStat) bool {
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
||||||
// TODO: What condition makes this happen?
|
// TODO: What condition makes this happen?
|
||||||
|
return false
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -30,7 +30,7 @@ var messageProcessors []messageProcessor
|
|||||||
type statProcessor interface {
|
type statProcessor interface {
|
||||||
GetName() string
|
GetName() string
|
||||||
GetStatKeys() []string
|
GetStatKeys() []string
|
||||||
Initialize() []string
|
Initialize()
|
||||||
ProcessMessage(m *Message)
|
ProcessMessage(m *Message)
|
||||||
ProcessBotMessage(m *Message)
|
ProcessBotMessage(m *Message)
|
||||||
ProcessUserMessage(m *Message)
|
ProcessUserMessage(m *Message)
|
||||||
|
Loading…
Reference in New Issue
Block a user