mirror of
https://git.sr.ht/~ashkeel/strimertul
synced 2024-09-18 01:50:50 +00:00
fix: clarify no contribution to goals
This commit is contained in:
parent
cf8fec3f4f
commit
d38b982733
3 changed files with 22 additions and 17 deletions
|
@ -313,7 +313,7 @@ func (m *Manager) ContributeGoal(goal Goal, user string, points int64) error {
|
|||
return ErrGoalNotFound
|
||||
}
|
||||
|
||||
func (m *Manager) PerformContribution(goal Goal, user string, points int64) error {
|
||||
func (m *Manager) PerformContribution(goal Goal, user string, points int64) (int64, error) {
|
||||
// Get user balance
|
||||
balance := m.GetPoints(user)
|
||||
|
||||
|
@ -324,7 +324,7 @@ func (m *Manager) PerformContribution(goal Goal, user string, points int64) erro
|
|||
|
||||
// Check if goal was reached already
|
||||
if goal.Contributed >= goal.TotalGoal {
|
||||
return ErrGoalAlreadyReached
|
||||
return 0, ErrGoalAlreadyReached
|
||||
}
|
||||
|
||||
// If remaining points are lower than what user is contributing, only take what's needed
|
||||
|
@ -335,11 +335,11 @@ func (m *Manager) PerformContribution(goal Goal, user string, points int64) erro
|
|||
|
||||
// Remove points from user
|
||||
if err := m.TakePoints(map[string]int64{user: points}); err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// Add points to goal
|
||||
return m.ContributeGoal(goal, user, points)
|
||||
return points, m.ContributeGoal(goal, user, points)
|
||||
}
|
||||
|
||||
func (m *Manager) GetReward(id string) Reward {
|
||||
|
|
|
@ -280,7 +280,7 @@ func (m *Manager) cmdContributeGoal(bot *twitch.Bot, message irc.PrivateMessage)
|
|||
// Do we not have any goal we can contribute to? Hooray I guess?
|
||||
if goalIndex < 0 {
|
||||
if hasGoals {
|
||||
bot.Client.Say(message.Channel, fmt.Sprintf("%s: All active community goals have been reached already! ShowOfHands", message.User.DisplayName))
|
||||
bot.Client.Say(message.Channel, fmt.Sprintf("%s: All active community goals have been reached already! NewRecord", message.User.DisplayName))
|
||||
} else {
|
||||
bot.Client.Say(message.Channel, fmt.Sprintf("%s: There are no active community goals right now :(!", message.User.DisplayName))
|
||||
}
|
||||
|
@ -290,13 +290,13 @@ func (m *Manager) cmdContributeGoal(bot *twitch.Bot, message irc.PrivateMessage)
|
|||
// Parse parameters if provided
|
||||
parts := strings.Fields(message.Message)
|
||||
if len(parts) > 1 {
|
||||
newpoints, err := strconv.ParseInt(parts[1], 10, 64)
|
||||
newPoints, err := strconv.ParseInt(parts[1], 10, 64)
|
||||
if err == nil {
|
||||
if newpoints <= 0 {
|
||||
if newPoints <= 0 {
|
||||
bot.Client.Say(message.Channel, fmt.Sprintf("Nice try %s SoBayed", message.User.DisplayName))
|
||||
return
|
||||
}
|
||||
points = newpoints
|
||||
points = newPoints
|
||||
}
|
||||
if len(parts) > 2 {
|
||||
found := false
|
||||
|
@ -330,18 +330,24 @@ func (m *Manager) cmdContributeGoal(bot *twitch.Bot, message irc.PrivateMessage)
|
|||
}
|
||||
|
||||
// Add points to goal
|
||||
if err := m.PerformContribution(selectedGoal, message.User.Name, points); err != nil {
|
||||
points, err := m.PerformContribution(selectedGoal, message.User.Name, points)
|
||||
if err != nil {
|
||||
m.logger.Error("error while contributing to goal", zap.Error(err))
|
||||
return
|
||||
}
|
||||
if points == 0 {
|
||||
bot.Client.Say(message.Channel, fmt.Sprintf("%s: Sorry but you're broke", message.User.DisplayName))
|
||||
return
|
||||
}
|
||||
|
||||
selectedGoal = m.Goals.Get()[goalIndex]
|
||||
config := m.Config.Get()
|
||||
newRemaining := selectedGoal.TotalGoal - selectedGoal.Contributed
|
||||
bot.Client.Say(message.Channel, fmt.Sprintf("ShowOfHands %s contributed %d %s to \"%s\"!! Only %d %s left!", message.User.DisplayName, points, config.Currency, selectedGoal.Name, newRemaining, config.Currency))
|
||||
bot.Client.Say(message.Channel, fmt.Sprintf("NewRecord %s contributed %d %s to \"%s\"!! Only %d %s left!", message.User.DisplayName, points, config.Currency, selectedGoal.Name, newRemaining, config.Currency))
|
||||
|
||||
// Check if goal was reached!
|
||||
// TODO Replace this with sub from loyalty system or something?
|
||||
if newRemaining <= 0 {
|
||||
bot.Client.Say(message.Channel, fmt.Sprintf("ShowOfHands The community goal \"%s\" was reached! ShowOfHands", selectedGoal.Name))
|
||||
bot.Client.Say(message.Channel, fmt.Sprintf("FallWinning The community goal \"%s\" was reached! FallWinning", selectedGoal.Name))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -212,13 +212,12 @@ func newClient(config Config, db *database.LocalDBClient, server *http.Server, l
|
|||
users, err := userClient.GetUsers(&helix.UsersParams{})
|
||||
if err != nil {
|
||||
client.logger.Error("failed looking up user", zap.Error(err))
|
||||
} else if len(users.Data.Users) < 1 {
|
||||
client.logger.Error("no users found, please authenticate in Twitch configuration -> Events")
|
||||
} else {
|
||||
client.User = users.Data.Users[0]
|
||||
go client.connectWebsocket(userClient)
|
||||
}
|
||||
if len(users.Data.Users) < 1 {
|
||||
client.logger.Error("no users found")
|
||||
}
|
||||
client.User = users.Data.Users[0]
|
||||
|
||||
go client.connectWebsocket(userClient)
|
||||
} else {
|
||||
client.logger.Warn("twitch user not identified, this will break most features")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue