Add counters

This commit is contained in:
Daniel Mason 2025-05-30 14:01:57 +12:00
parent 04a260f96c
commit cbcfa51004
Signed by: idanoo
GPG key ID: 387387CDBC02F132
2 changed files with 16 additions and 1 deletions

View file

@ -1,6 +1,9 @@
package database package database
import "time" import (
"fmt"
"time"
)
// GetLastUsedPic // GetLastUsedPic
func (db *Database) GetCounterFor(key string) (time.Time, error) { func (db *Database) GetCounterFor(key string) (time.Time, error) {
@ -17,6 +20,10 @@ func (db *Database) GetCounterFor(key string) (time.Time, error) {
row.Scan(&id, &timestamp) row.Scan(&id, &timestamp)
} }
if id == 0 {
return timestamp, fmt.Errorf("%s not found", key)
}
return timestamp, nil return timestamp, nil
} }

View file

@ -134,6 +134,14 @@ func (mtrx *MtrxClient) handleCommand(ctx context.Context, evt *event.Event) {
mtrx.getCounterFor(ctx, evt.RoomID, args[1]) mtrx.getCounterFor(ctx, evt.RoomID, args[1])
return return
} }
case ".counterreset":
if len(args) < 2 {
mtrx.sendMessage(ctx, evt.RoomID, "Usage: .counterreset <key>")
return
} else {
mtrx.updateCounterFor(ctx, evt.RoomID, args[1])
return
}
case ".reloadallpics": case ".reloadallpics":
mtrx.db.DeleteAllPics() mtrx.db.DeleteAllPics()
mtrx.pics = make(map[int64]string, 0) mtrx.pics = make(map[int64]string, 0)