diff --git a/levelup_model.go b/levelup_model.go index 4d431d7..f382658 100644 --- a/levelup_model.go +++ b/levelup_model.go @@ -67,7 +67,7 @@ func getAllNonLevelUpStats(user string) map[string]int { return ret } -func getAllUserAcheivements(user string) map[string]int { +func getAllUserAchievements(user string) map[string]bool { openDatabase() ret := make(map[string]bool) db.Update(func(tx *bolt.Tx) error { diff --git a/processor_general.go b/processor_general.go index f3f6172..e91965c 100644 --- a/processor_general.go +++ b/processor_general.go @@ -101,6 +101,8 @@ func (p *generalStatProcessor) GetStatKeys() []string { } } +func (p *generalStatProcessor) Initialize() {} + func (p *generalStatProcessor) ProcessMessage(m *Message) { if m.Type == "message" { 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), }) 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 } } @@ -245,7 +247,7 @@ func (wm *generalWebModule) handleStats(w http.ResponseWriter, req *http.Request chanMsg = 0 } 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 } else { usrHourStats[i] = 0 diff --git a/processor_levelupachieve.go b/processor_levelupachieve.go index 36be6b6..e89d758 100644 --- a/processor_levelupachieve.go +++ b/processor_levelupachieve.go @@ -7,12 +7,13 @@ type levelUpAchievement struct { GetText func() string GetKeyName func() string // 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 { - val, ok := ustat.Achievements[achieve.GetKeyName()] - if ustat.Achievements + //val, ok := ustat.Achievements[achieve.GetKeyName()] + //if ustat.Achievements + return false } type levelUpAchieveStatProcessor struct { @@ -60,9 +61,9 @@ func (p *levelUpAchieveStatProcessor) ProcessMessage(m *Message) { } 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 - 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 * of it's achievements and such. */ -func (p *levelUpAcheiveStatProcessor) Initialize() { +func (p *levelUpAchieveStatProcessor) Initialize() { // TODO: Set up achievements p.Achievements = append(p.Achievements, // Early Bird Achievement @@ -130,13 +131,13 @@ func (p *levelUpAcheiveStatProcessor) Initialize() { GetKeyName: func() string { return "levelup-achieve-earlybird" }, - ProcessMessage: func(u *userStat) bool { + ProcessMessage: func(u *UserLevelUpStats, m *Message) bool { // TODO: What condition makes this happen? if m.Time.Hour() > 3 && m.Time.Hour() < 7 { numMsgs := 0 - numMsgs = numMsgs + userStat.OtherStats["message-hour-04"] - numMsgs = numMsgs + userStat.OtherStats["message-hour-05"] - numMsgs = numMsgs + userStat.OtherStats["message-hour-06"] + numMsgs = numMsgs + u.OtherStats["message-hour-04"] + numMsgs = numMsgs + u.OtherStats["message-hour-05"] + numMsgs = numMsgs + u.OtherStats["message-hour-06"] /* if chnl.Name == "random" { addUserStat(m.User, "levelup-xp", 1) @@ -165,8 +166,9 @@ func (p *levelUpAcheiveStatProcessor) Initialize() { GetKeyName: func() string { return "levelup-achieve-nightowl" }, - ProcessMessage: func(u *userStat) bool { + ProcessMessage: func(u *UserLevelUpStats, m *Message) bool { // TODO: What condition makes this happen? + return false }, }, ) @@ -183,8 +185,9 @@ func (p *levelUpAcheiveStatProcessor) Initialize() { GetKeyName: func() string { return "levelup-achieve-aroundtheclock" }, - ProcessMessage: func(u *userStat) bool { + ProcessMessage: func(u *UserLevelUpStats, m *Message) bool { // TODO: What condition makes this happen? + return false }, }, ) @@ -201,8 +204,9 @@ func (p *levelUpAcheiveStatProcessor) Initialize() { GetKeyName: func() string { return "levelup-achieve-beginner" }, - ProcessMessage: func(u *userStat) bool { + ProcessMessage: func(u *UserLevelUpStats, m *Message) bool { // TODO: What condition makes this happen? + return false }, }, ) @@ -219,8 +223,9 @@ func (p *levelUpAcheiveStatProcessor) Initialize() { GetKeyName: func() string { return "levelup-achieve-experienced" }, - ProcessMessage: func(u *userStat) bool { + ProcessMessage: func(u *UserLevelUpStats, m *Message) bool { // TODO: What condition makes this happen? + return false }, }, ) @@ -237,8 +242,9 @@ func (p *levelUpAcheiveStatProcessor) Initialize() { GetKeyName: func() string { return "levelup-achieve-superadvanced" }, - ProcessMessage: func(u *userStat) bool { + ProcessMessage: func(u *UserLevelUpStats, m *Message) bool { // TODO: What condition makes this happen? + return false }, }, ) diff --git a/statbot.go b/statbot.go index 31ec042..16e6277 100644 --- a/statbot.go +++ b/statbot.go @@ -30,7 +30,7 @@ var messageProcessors []messageProcessor type statProcessor interface { GetName() string GetStatKeys() []string - Initialize() []string + Initialize() ProcessMessage(m *Message) ProcessBotMessage(m *Message) ProcessUserMessage(m *Message)