diff --git a/src/internal/database/counter.go b/src/internal/database/counter.go index d705b47..1b2c4b0 100644 --- a/src/internal/database/counter.go +++ b/src/internal/database/counter.go @@ -1,6 +1,9 @@ package database -import "time" +import ( + "fmt" + "time" +) // GetLastUsedPic 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, ×tamp) } + if id == 0 { + return timestamp, fmt.Errorf("%s not found", key) + } + return timestamp, nil } diff --git a/src/internal/gomatrixbot/commands.go b/src/internal/gomatrixbot/commands.go index d41075f..5dc04c7 100644 --- a/src/internal/gomatrixbot/commands.go +++ b/src/internal/gomatrixbot/commands.go @@ -134,6 +134,14 @@ func (mtrx *MtrxClient) handleCommand(ctx context.Context, evt *event.Event) { mtrx.getCounterFor(ctx, evt.RoomID, args[1]) return } + case ".counterreset": + if len(args) < 2 { + mtrx.sendMessage(ctx, evt.RoomID, "Usage: .counterreset ") + return + } else { + mtrx.updateCounterFor(ctx, evt.RoomID, args[1]) + return + } case ".reloadallpics": mtrx.db.DeleteAllPics() mtrx.pics = make(map[int64]string, 0)