Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/boost/boost_reactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ func ReactionAdd(s *discordgo.Session, r *discordgo.MessageReaction) string {
if r.UserID != b.UserID {
// Record the Tokens as received
b.TokenReceivedTime = append(b.TokenReceivedTime, time.Now())
track.ContractTokenMessage(s, r.ChannelID, b.UserID, track.TokenReceived)
track.ContractTokenMessage(s, r.ChannelID, b.UserID, track.TokenReceived, r.UserID)

// Record who sent the token
track.ContractTokenMessage(s, r.ChannelID, r.UserID, track.TokenSent)
track.ContractTokenMessage(s, r.ChannelID, r.UserID, track.TokenSent, b.UserID)
contract.Boosters[r.UserID].TokenSentTime = append(contract.Boosters[r.UserID].TokenSentTime, time.Now())
} else {
track.FarmedToken(s, r.ChannelID, r.UserID)
Expand Down
20 changes: 14 additions & 6 deletions src/track/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ type tokenValue struct {
DurationTime time.Duration // Duration of Token Value time
TokenSentTime []time.Time // time of each token sent
TokenSentValues []float64 // time of each token sent
TokenSentUserID []string // User ID of where each token was sent to
TokenReceivedTime []time.Time // time of each received token
TokenReceivedValues []float64 // time of each token sent
TokenReceivedUserID []string // User ID of where each token came from
FarmedTokenTime []time.Time // time a self farmed token was received
SumValueSent float64 // sum of all token values sent
SumValueReceived float64 // sum of all token values received
Expand Down Expand Up @@ -72,6 +74,8 @@ func resetTokenTracking(tv *tokenValue) {
tv.LinkRecieved = true
tv.TokenSentTime = nil
tv.TokenReceivedTime = nil
tv.TokenReceivedUserID = nil
tv.TokenSentUserID = nil
tv.TokenSentValues = nil
tv.TokenReceivedValues = nil
tv.SumValueSent = 0.0
Expand Down Expand Up @@ -183,9 +187,9 @@ func getTokenTrackingString(td *tokenValue, finalDisplay bool) string {
if td.Details {
for i, t := range td.TokenSentTime {
if !finalDisplay {
fmt.Fprintf(&builder, "> %d: <t:%d:R> %6.3f\n", i+1, t.Unix(), td.TokenSentValues[i])
fmt.Fprintf(&builder, "> %d: <t:%d:R> %6.3f <@%s>\n", i+1, t.Unix(), td.TokenSentValues[i], td.TokenSentUserID[i])
} else {
fmt.Fprintf(&builder, "> %d: %s %6.3f\n", i+1, t.Sub(td.StartTime).Round(time.Second), td.TokenSentValues[i])
fmt.Fprintf(&builder, "> %d: %s %6.3f <@%s>\n", i+1, t.Sub(td.StartTime).Round(time.Second), td.TokenSentValues[i], td.TokenSentUserID[i])
}
if builder.Len() > 1750 {
fmt.Fprint(&builder, "> ...\n")
Expand All @@ -197,16 +201,16 @@ func getTokenTrackingString(td *tokenValue, finalDisplay bool) string {
if td.Details {
for i, t := range td.TokenReceivedTime {
if !finalDisplay {
fmt.Fprintf(&builder, "> %d: <t:%d:R> %6.3f\n", i+1, t.Unix(), td.TokenReceivedValues[i])
fmt.Fprintf(&builder, "> %d: <t:%d:R> %6.3f <@%s>\n", i+1, t.Unix(), td.TokenReceivedValues[i], td.TokenReceivedUserID[i])
} else {
fmt.Fprintf(&builder, "> %d: %s %6.3f\n", i+1, t.Sub(td.StartTime).Round(time.Second), td.TokenReceivedValues[i])
fmt.Fprintf(&builder, "> %d: %s %6.3f <@%s>\n", i+1, t.Sub(td.StartTime).Round(time.Second), td.TokenReceivedValues[i], td.TokenReceivedUserID[i])
}
if builder.Len() > 1750 {
fmt.Fprint(&builder, "> ...\n")
break
}
}
if td.LinkRecieved {
if td.LinkRecieved && !finalDisplay {
fmt.Fprint(&builder, "React with 1️⃣..🔟 to remove errant received tokens at that index.\n")
}
}
Expand Down Expand Up @@ -290,11 +294,13 @@ func tokenTrackingTrack(userID string, name string, tokenSent int, tokenReceived
if tokenSent > 0 {
td.TokenSentTime = append(td.TokenSentTime, now)
td.TokenSentValues = append(td.TokenSentValues, tokenValue)
td.TokenSentUserID = append(td.TokenSentUserID, userID) // Self reported
td.SumValueSent += tokenValue
}
if tokenReceived > 0 {
td.TokenReceivedTime = append(td.TokenReceivedTime, now)
td.TokenReceivedValues = append(td.TokenReceivedValues, tokenValue)
td.TokenReceivedUserID = append(td.TokenReceivedUserID, userID) // Self reported
td.SumValueReceived += tokenValue
}
td.TokenDelta = td.SumValueSent - td.SumValueReceived
Expand Down Expand Up @@ -375,7 +381,7 @@ func FarmedToken(s *discordgo.Session, channelID string, userID string) {
}

// ContractTokenMessage will track the token sent from the contract Token reaction
func ContractTokenMessage(s *discordgo.Session, channelID string, userID string, kind int) {
func ContractTokenMessage(s *discordgo.Session, channelID string, userID string, kind int, actorUserID string) {
if Tokens[userID] == nil {
return
}
Expand All @@ -388,11 +394,13 @@ func ContractTokenMessage(s *discordgo.Session, channelID string, userID string,
if kind == TokenSent {
v.TokenSentTime = append(v.TokenSentTime, now)
v.TokenSentValues = append(v.TokenSentValues, tokenValue)
v.TokenSentUserID = append(v.TokenSentUserID, actorUserID) // Token sent to...
v.SumValueSent += tokenValue
redraw = true
} else if v.LinkRecieved && kind == TokenReceived {
v.TokenReceivedTime = append(v.TokenReceivedTime, now)
v.TokenReceivedValues = append(v.TokenReceivedValues, tokenValue)
v.TokenReceivedUserID = append(v.TokenReceivedUserID, actorUserID) // Token received from...
v.SumValueReceived += tokenValue
redraw = true
}
Expand Down
7 changes: 6 additions & 1 deletion src/track/track_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,18 @@ func HandleTokenCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
linkReceived := false
var duration time.Duration
if opt, ok := optionMap["duration"]; ok {
var err error
// Timespan of the contract duration
contractTimespan := strings.TrimSpace(opt.StringValue())
contractTimespan = strings.Replace(contractTimespan, "day", "d", -1)
contractTimespan = strings.Replace(contractTimespan, "hr", "h", -1)
contractTimespan = strings.Replace(contractTimespan, "min", "m", -1)
contractTimespan = strings.Replace(contractTimespan, "sec", "s", -1)
duration, _ = str2duration.ParseDuration(contractTimespan)
duration, err = str2duration.ParseDuration(contractTimespan)
if err != nil {
// Invalid duration, just assigning a 12h
duration = 12 * time.Hour
}
}
var trackingName = ""
if opt, ok := optionMap["name"]; ok {
Expand Down