mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add ping command and uptime time helper
This commit is contained in:
parent
47e7091a09
commit
d7e38bb17c
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ func main() {
|
|||
sugar := zap.NewExample().Sugar()
|
||||
defer sugar.Sync()
|
||||
|
||||
common.StartTime()
|
||||
|
||||
app := &Application{
|
||||
TwitchClient: tc,
|
||||
Logger: sugar,
|
||||
|
|
1
go.mod
1
go.mod
|
@ -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
4
go.sum
|
@ -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
16
pkg/commands/ping.go
Normal 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
15
pkg/common/uptime.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package common
|
||||
|
||||
import "time"
|
||||
|
||||
var (
|
||||
uptime time.Time
|
||||
)
|
||||
|
||||
func StartTime() {
|
||||
uptime = time.Now()
|
||||
}
|
||||
|
||||
func GetUptime() time.Time {
|
||||
return uptime
|
||||
}
|
Loading…
Reference in a new issue