258 lines
6.9 KiB
Go
258 lines
6.9 KiB
Go
package main
|
|
|
|
import "net/http"
|
|
|
|
type levelUpAchievement struct {
|
|
GetName func() string
|
|
GetText func() string
|
|
GetKeyName func() string
|
|
// Processes the message, returns true if the achievement was triggered
|
|
ProcessMessage func(ustat *UserLevelUpStats, m *Message) bool
|
|
}
|
|
|
|
func (achieve *levelUpAchievement) DoesUserHave(ustat *UserLevelUpStats) bool {
|
|
//val, ok := ustat.Achievements[achieve.GetKeyName()]
|
|
//if ustat.Achievements
|
|
return false
|
|
}
|
|
|
|
type levelUpAchieveStatProcessor struct {
|
|
Achievements []levelUpAchievement
|
|
}
|
|
|
|
func (p *levelUpAchieveStatProcessor) GetName() string {
|
|
return "LevelUp Achievements"
|
|
}
|
|
|
|
func (p *levelUpAchieveStatProcessor) GetStatKeys() []string {
|
|
return []string{
|
|
"levelupachievement-*",
|
|
}
|
|
}
|
|
|
|
// UserLevelUpStats is just a struct for caching user data...
|
|
// This processor needs to crunch a lot of numbers, this should make
|
|
// it quicker/easier
|
|
type UserLevelUpStats struct {
|
|
Name string
|
|
Xp int
|
|
ChannelStats map[string]int
|
|
OtherStats map[string]int
|
|
Achievements map[string]bool
|
|
CurrentMsg *Message
|
|
CurrentCh *Channel
|
|
}
|
|
|
|
func (p *levelUpAchieveStatProcessor) ProcessMessage(m *Message) {
|
|
var u *User
|
|
var err error
|
|
if u, err = getUserInfo(m.User); err != nil {
|
|
return
|
|
}
|
|
|
|
userStat := UserLevelUpStats{Name: u.Name, CurrentMsg: m}
|
|
userStat.Xp, _ = getUserStat(u.ID, "levelup-xp")
|
|
userStat.ChannelStats = getAllLevelUpChannelXp(u.ID)
|
|
userStat.OtherStats = getAllNonLevelUpStats(u.ID)
|
|
userStat.Achievements = getAllUserAchievements(u.ID)
|
|
chnl, err := getChannelInfo(m.Channel)
|
|
if err == nil {
|
|
userStat.CurrentCh = chnl
|
|
}
|
|
|
|
for _, achieve := range p.Achievements {
|
|
if !achieve.DoesUserHave(&userStat) {
|
|
// User doesn't already have this achieve, let it process the message
|
|
achieve.ProcessMessage(&userStat, m)
|
|
}
|
|
}
|
|
}
|
|
func (p *levelUpAchieveStatProcessor) ProcessAdminMessage(m *Message) {}
|
|
func (p *levelUpAchieveStatProcessor) ProcessBotMessage(m *Message) {}
|
|
|
|
func (p *levelUpAchieveStatProcessor) ProcessUserMessage(m *Message) {}
|
|
func (p *levelUpAchieveStatProcessor) ProcessAdminUserMessage(m *Message) {}
|
|
func (p *levelUpAchieveStatProcessor) ProcessBotUserMessage(m *Message) {}
|
|
|
|
func (p *levelUpAchieveStatProcessor) ProcessChannelMessage(m *Message) {
|
|
}
|
|
func (p *levelUpAchieveStatProcessor) ProcessAdminChannelMessage(m *Message) {}
|
|
func (p *levelUpAchieveStatProcessor) ProcessBotChannelMessage(m *Message) {}
|
|
|
|
/*
|
|
* Web Site Module
|
|
*/
|
|
type levelUpAchieveWebModule struct{}
|
|
|
|
func (wm *levelUpAchieveWebModule) GetName() string {
|
|
return "LevelUp Achievement Web Module"
|
|
}
|
|
func (wm *levelUpAchieveWebModule) GetRoutes() map[string]func(http.ResponseWriter, *http.Request) {
|
|
ret := make(map[string]func(http.ResponseWriter, *http.Request))
|
|
ret["/levelup/achieve"] = wm.handleLevelUpAchieveGeneral
|
|
ret["/levelup/achieve/admin"] = wm.handleLevelUpAchieveAdmin
|
|
return ret
|
|
}
|
|
func (wm *levelUpAchieveWebModule) Register() {
|
|
for k, v := range wm.GetRoutes() {
|
|
r.HandleFunc(k, v)
|
|
}
|
|
}
|
|
func (wm *levelUpAchieveWebModule) GetMenuEntries() []menuItem {
|
|
var ret []menuItem
|
|
//ret = append(ret, menuItem{Text: "Achieve GET!", Link: "/levelup/achieve"})
|
|
return ret
|
|
}
|
|
func (wm *levelUpAchieveWebModule) GetBottomMenuEntries() []menuItem {
|
|
var ret []menuItem
|
|
return ret
|
|
}
|
|
|
|
func (wm *levelUpAchieveWebModule) handleLevelUpAchieveAdmin(w http.ResponseWriter, req *http.Request) {
|
|
// TODO: Test for admin login
|
|
initRequest(w, req)
|
|
}
|
|
|
|
func (wm *levelUpAchieveWebModule) handleLevelUpAchieveGeneral(w http.ResponseWriter, req *http.Request) {
|
|
initRequest(w, req)
|
|
//setMenuItemActive("Achieve GET!")
|
|
}
|
|
|
|
/*
|
|
* Achieve Stat Processor Initialization
|
|
* It's down here because it's so long what with all
|
|
* of it's achievements and such.
|
|
*/
|
|
func (p *levelUpAchieveStatProcessor) Initialize() {
|
|
// TODO: Set up achievements
|
|
p.Achievements = append(p.Achievements,
|
|
// Early Bird Achievement
|
|
levelUpAchievement{
|
|
GetName: func() string {
|
|
return "Early Bird"
|
|
},
|
|
GetText: func() string {
|
|
return "You seem to enjoy chatting before 7 AM"
|
|
},
|
|
GetKeyName: func() string {
|
|
return "levelup-achieve-earlybird"
|
|
},
|
|
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 + 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)
|
|
} else if chnl.Name == "general" {
|
|
addUserStat(m.User, "levelup-xp", 2)
|
|
} else {
|
|
addUserStat(m.User, "levelup-xp", 3)
|
|
addUserStat(m.User, "levelup-xp-"+chnl.Name, 1)
|
|
}
|
|
*/
|
|
}
|
|
return false
|
|
},
|
|
},
|
|
)
|
|
|
|
p.Achievements = append(p.Achievements,
|
|
// Night Owl Achievement
|
|
levelUpAchievement{
|
|
GetName: func() string {
|
|
return "Night Owl"
|
|
},
|
|
GetText: func() string {
|
|
return "You seem to enjoy chatting after 12 AM"
|
|
},
|
|
GetKeyName: func() string {
|
|
return "levelup-achieve-nightowl"
|
|
},
|
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
|
// TODO: What condition makes this happen?
|
|
return false
|
|
},
|
|
},
|
|
)
|
|
|
|
p.Achievements = append(p.Achievements,
|
|
// Around the Clock Achievement
|
|
levelUpAchievement{
|
|
GetName: func() string {
|
|
return "Around the Clock"
|
|
},
|
|
GetText: func() string {
|
|
return "You have sent at least one message in every hour of the day"
|
|
},
|
|
GetKeyName: func() string {
|
|
return "levelup-achieve-aroundtheclock"
|
|
},
|
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
|
// TODO: What condition makes this happen?
|
|
return false
|
|
},
|
|
},
|
|
)
|
|
|
|
p.Achievements = append(p.Achievements,
|
|
// Beginner Achievement
|
|
levelUpAchievement{
|
|
GetName: func() string {
|
|
return "Beginner"
|
|
},
|
|
GetText: func() string {
|
|
return "Get on the XP Chart"
|
|
},
|
|
GetKeyName: func() string {
|
|
return "levelup-achieve-beginner"
|
|
},
|
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
|
// TODO: What condition makes this happen?
|
|
return false
|
|
},
|
|
},
|
|
)
|
|
|
|
p.Achievements = append(p.Achievements,
|
|
// Experienced Achievement
|
|
levelUpAchievement{
|
|
GetName: func() string {
|
|
return "Experienced"
|
|
},
|
|
GetText: func() string {
|
|
return "Reach level 5"
|
|
},
|
|
GetKeyName: func() string {
|
|
return "levelup-achieve-experienced"
|
|
},
|
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
|
// TODO: What condition makes this happen?
|
|
return false
|
|
},
|
|
},
|
|
)
|
|
|
|
p.Achievements = append(p.Achievements,
|
|
// Super Advanced! Achievement
|
|
levelUpAchievement{
|
|
GetName: func() string {
|
|
return "Super Advanced!"
|
|
},
|
|
GetText: func() string {
|
|
return "Reach level 10"
|
|
},
|
|
GetKeyName: func() string {
|
|
return "levelup-achieve-superadvanced"
|
|
},
|
|
ProcessMessage: func(u *UserLevelUpStats, m *Message) bool {
|
|
// TODO: What condition makes this happen?
|
|
return false
|
|
},
|
|
},
|
|
)
|
|
}
|