1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul synced 2024-09-20 02:00:49 +00:00

fix: clarify no contribution to goals

This commit is contained in:
Ash Keel 2023-02-06 10:36:00 +01:00
parent cf8fec3f4f
commit d38b982733
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E
3 changed files with 22 additions and 17 deletions

View file

@ -313,7 +313,7 @@ func (m *Manager) ContributeGoal(goal Goal, user string, points int64) error {
return ErrGoalNotFound 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 // Get user balance
balance := m.GetPoints(user) 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 // Check if goal was reached already
if goal.Contributed >= goal.TotalGoal { 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 // 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 // Remove points from user
if err := m.TakePoints(map[string]int64{user: points}); err != nil { if err := m.TakePoints(map[string]int64{user: points}); err != nil {
return err return 0, err
} }
// Add points to goal // Add points to goal
return m.ContributeGoal(goal, user, points) return points, m.ContributeGoal(goal, user, points)
} }
func (m *Manager) GetReward(id string) Reward { func (m *Manager) GetReward(id string) Reward {

View file

@ -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? // Do we not have any goal we can contribute to? Hooray I guess?
if goalIndex < 0 { if goalIndex < 0 {
if hasGoals { 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 { } else {
bot.Client.Say(message.Channel, fmt.Sprintf("%s: There are no active community goals right now :(!", message.User.DisplayName)) 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 // Parse parameters if provided
parts := strings.Fields(message.Message) parts := strings.Fields(message.Message)
if len(parts) > 1 { if len(parts) > 1 {
newpoints, err := strconv.ParseInt(parts[1], 10, 64) newPoints, err := strconv.ParseInt(parts[1], 10, 64)
if err == nil { if err == nil {
if newpoints <= 0 { if newPoints <= 0 {
bot.Client.Say(message.Channel, fmt.Sprintf("Nice try %s SoBayed", message.User.DisplayName)) bot.Client.Say(message.Channel, fmt.Sprintf("Nice try %s SoBayed", message.User.DisplayName))
return return
} }
points = newpoints points = newPoints
} }
if len(parts) > 2 { if len(parts) > 2 {
found := false found := false
@ -330,18 +330,24 @@ func (m *Manager) cmdContributeGoal(bot *twitch.Bot, message irc.PrivateMessage)
} }
// Add points to goal // 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)) m.logger.Error("error while contributing to goal", zap.Error(err))
return 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() config := m.Config.Get()
newRemaining := selectedGoal.TotalGoal - selectedGoal.Contributed 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! // Check if goal was reached!
// TODO Replace this with sub from loyalty system or something? // TODO Replace this with sub from loyalty system or something?
if newRemaining <= 0 { 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))
} }
} }

View file

@ -212,13 +212,12 @@ func newClient(config Config, db *database.LocalDBClient, server *http.Server, l
users, err := userClient.GetUsers(&helix.UsersParams{}) users, err := userClient.GetUsers(&helix.UsersParams{})
if err != nil { if err != nil {
client.logger.Error("failed looking up user", zap.Error(err)) client.logger.Error("failed looking up user", zap.Error(err))
} } else if len(users.Data.Users) < 1 {
if len(users.Data.Users) < 1 { client.logger.Error("no users found, please authenticate in Twitch configuration -> Events")
client.logger.Error("no users found") } else {
}
client.User = users.Data.Users[0] client.User = users.Data.Users[0]
go client.connectWebsocket(userClient) go client.connectWebsocket(userClient)
}
} else { } else {
client.logger.Warn("twitch user not identified, this will break most features") client.logger.Warn("twitch user not identified, this will break most features")
} }