add ping command and uptime time helper

This commit is contained in:
lyx0 2022-08-07 16:36:06 +02:00
parent 47e7091a09
commit d7e38bb17c
6 changed files with 38 additions and 2 deletions

View file

@ -65,5 +65,7 @@ func handleCommand(message twitch.PrivateMessage, tc *twitch.Client) {
} else {
commands.Tweet(target, cmdParams[1], tc)
}
case "ping":
commands.Ping(target, tc)
}
}

View file

@ -19,6 +19,8 @@ func main() {
sugar := zap.NewExample().Sugar()
defer sugar.Sync()
common.StartTime()
app := &Application{
TwitchClient: tc,
Logger: sugar,

1
go.mod
View file

@ -3,6 +3,7 @@ module github.com/lyx0/nourybot
go 1.19
require (
github.com/dustin/go-humanize v1.0.0
github.com/gempir/go-twitch-irc/v3 v3.2.0
github.com/joho/godotenv v1.4.0
go.uber.org/zap v1.21.0

4
go.sum
View file

@ -3,8 +3,8 @@ github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZx
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gempir/go-twitch-irc/v3 v3.1.0 h1:bUVZ5mADhH7KidJVcl+z79kgLJ7sjdAk4b/ylAvaLy0=
github.com/gempir/go-twitch-irc/v3 v3.1.0/go.mod h1:/W9KZIiyizVecp4PEb7kc4AlIyXKiCmvlXrzlpPUytU=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/gempir/go-twitch-irc/v3 v3.2.0 h1:ENhsa7RgBE1GMmDqe0iMkvcSYfgw6ZsXilt+sAg32/U=
github.com/gempir/go-twitch-irc/v3 v3.2.0/go.mod h1:/W9KZIiyizVecp4PEb7kc4AlIyXKiCmvlXrzlpPUytU=
github.com/joho/godotenv v1.4.0 h1:3l4+N6zfMWnkbPEXKng2o2/MR5mSwTrBih4ZEkkz1lg=

16
pkg/commands/ping.go Normal file
View file

@ -0,0 +1,16 @@
package commands
import (
"fmt"
"github.com/gempir/go-twitch-irc/v3"
"github.com/lyx0/nourybot/pkg/common"
"github.com/lyx0/nourybot/pkg/humanize"
)
func Ping(target string, tc *twitch.Client) {
botUptime := humanize.Time(common.GetUptime())
reply := fmt.Sprintf("Pong! :) Last restart: %v", botUptime)
common.Send(target, reply, tc)
}

15
pkg/common/uptime.go Normal file
View file

@ -0,0 +1,15 @@
package common
import "time"
var (
uptime time.Time
)
func StartTime() {
uptime = time.Now()
}
func GetUptime() time.Time {
return uptime
}