mirror of
https://github.com/idanoo/gomatrixbot
synced 2025-07-22 08:29:13 +00:00
Add counters
This commit is contained in:
parent
04a260f96c
commit
cbcfa51004
2 changed files with 16 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <key>")
|
||||
return
|
||||
} else {
|
||||
mtrx.updateCounterFor(ctx, evt.RoomID, args[1])
|
||||
return
|
||||
}
|
||||
case ".reloadallpics":
|
||||
mtrx.db.DeleteAllPics()
|
||||
mtrx.pics = make(map[int64]string, 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue