add last flush to /info command

new-sql-view v0.5.0
William Perron 11 months ago
parent 5cbaff0820
commit c1d5e472f2
Signed by: wperron
GPG Key ID: BFDB4EF72D73C5F2

@ -81,10 +81,10 @@ func (s *Store) Audit(ev *AuditableEvent) {
}
type AuditEvent struct {
id int
userId string
eventType EventType
timestamp time.Time
Id int
UserId string
EventType EventType
Timestamp time.Time
}
func (s *Store) LastOf(ctx context.Context, t EventType) (AuditEvent, error) {
@ -98,15 +98,15 @@ func (s *Store) LastOf(ctx context.Context, t EventType) (AuditEvent, error) {
ev := AuditEvent{}
var rawEventType string
err = row.Scan(&ev.id, &ev.userId, &rawEventType, &ev.timestamp)
err = row.Scan(&ev.Id, &ev.UserId, &rawEventType, &ev.Timestamp)
if err == sql.ErrNoRows {
return AuditEvent{}, errors.New("no rows found")
return AuditEvent{}, ErrNever
}
if err != nil {
return AuditEvent{}, fmt.Errorf("failed to scan row: %w", err)
}
ev.eventType, err = EventTypeFromString(rawEventType)
ev.EventType, err = EventTypeFromString(rawEventType)
if err != nil {
return AuditEvent{}, fmt.Errorf("failed to parse event type %s: %w", rawEventType, err)
}

@ -231,10 +231,30 @@ func main() {
}
}
ev, err := store.LastOf(ctx, themis.EventFlush)
var lastFlush string
if err != nil {
if err != themis.ErrNever {
log.Error().Err(err).Msg("failed get last flush event")
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Oops, something went wrong! :(",
},
})
if err != nil {
log.Error().Err(err).Msg("failed to respond to interaction")
}
}
lastFlush = "never"
} else {
lastFlush = ev.Timestamp.Format(time.DateTime)
}
err = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf("Server has been up for %s, has %d claims from %d unique players", uptime, claimCount, uniquePlayers),
Content: fmt.Sprintf("Server has been up for %s, has %d claims from %d unique players.\nThe last time claims were flushed was: %s.", uptime, claimCount, uniquePlayers, lastFlush),
},
})
if err != nil {

@ -6,6 +6,7 @@ import (
)
var ErrNoSuchClaim = errors.New("no such claim")
var ErrNever = errors.New("event never occured")
type ErrConflict struct {
Conflicts []Conflict

@ -99,8 +99,8 @@ func TestStore_Claim(t *testing.T) {
ae, err := store.LastOf(context.TODO(), EventClaim)
require.NoError(t, err)
assert.Greater(t, ae.id, lastAudit)
lastAudit = ae.id
assert.Greater(t, ae.Id, lastAudit)
lastAudit = ae.Id
})
}
}
@ -173,7 +173,7 @@ func TestDeleteClaim(t *testing.T) {
ae, err := store.LastOf(context.TODO(), EventUnclaim)
require.NoError(t, err)
last := ae.id
last := ae.Id
err = store.DeleteClaim(context.TODO(), barId, "000000000000000001")
assert.Error(t, err)
@ -181,7 +181,7 @@ func TestDeleteClaim(t *testing.T) {
ae, err = store.LastOf(context.TODO(), EventUnclaim)
require.NoError(t, err)
assert.Equal(t, last, ae.id) // no new audit log was added
assert.Equal(t, last, ae.Id) // no new audit log was added
}
func TestDescribeClaim(t *testing.T) {

Loading…
Cancel
Save