mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add uptime
This commit is contained in:
parent
b9d7dcbeea
commit
dbaa4ed180
4 changed files with 18 additions and 7 deletions
|
@ -1,6 +1,8 @@
|
|||
package bot
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
twitch "github.com/gempir/go-twitch-irc/v2"
|
||||
cfg "github.com/lyx0/nourybot/pkg/config"
|
||||
"github.com/lyx0/nourybot/pkg/handlers"
|
||||
|
@ -10,6 +12,7 @@ import (
|
|||
type Bot struct {
|
||||
twitchClient *twitch.Client
|
||||
cfg *cfg.Config
|
||||
Uptime time.Time
|
||||
}
|
||||
|
||||
func NewBot(cfg *cfg.Config) *Bot {
|
||||
|
@ -20,6 +23,7 @@ func NewBot(cfg *cfg.Config) *Bot {
|
|||
return &Bot{
|
||||
cfg: cfg,
|
||||
twitchClient: twitchClient,
|
||||
Uptime: time.Now(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +32,7 @@ func (b *Bot) Connect() error {
|
|||
cfg := cfg.LoadConfig()
|
||||
|
||||
b.twitchClient.OnPrivateMessage(func(message twitch.PrivateMessage) {
|
||||
handlers.HandlePrivateMessage(message, b.twitchClient, cfg)
|
||||
handlers.HandlePrivateMessage(message, b.twitchClient, cfg, b.Uptime)
|
||||
})
|
||||
|
||||
b.twitchClient.OnWhisperMessage(func(message twitch.WhisperMessage) {
|
||||
|
|
|
@ -2,13 +2,17 @@ package commands
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
"github.com/lyx0/nourybot/pkg/humanize"
|
||||
"github.com/lyx0/nourybot/pkg/utils"
|
||||
)
|
||||
|
||||
func Ping(channel string, client *twitch.Client) {
|
||||
func Ping(channel string, client *twitch.Client, uptime time.Time) {
|
||||
commandCount := fmt.Sprint(utils.GetCommandsUsed())
|
||||
s := fmt.Sprintf("Pong! :) Commands used: %v", commandCount)
|
||||
botUptime := humanize.HumanizeTime(uptime)
|
||||
|
||||
s := fmt.Sprintf("Pong! :) Commands used: %v, Last restart: %v", commandCount, botUptime)
|
||||
client.Say(channel, s)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package handlers
|
|||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
"github.com/lyx0/nourybot/pkg/commands"
|
||||
|
@ -13,7 +14,7 @@ import (
|
|||
// HandlePrivateMessage where it found a command in it.
|
||||
// HandleCommand passes on the message to the specific
|
||||
// command handler for further action.
|
||||
func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client) {
|
||||
func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client, uptime time.Time) {
|
||||
log.Info("fn HandleCommand")
|
||||
|
||||
// Counter that increments on every command call.
|
||||
|
@ -46,6 +47,6 @@ func HandleCommand(message twitch.PrivateMessage, twitchClient *twitch.Client) {
|
|||
twitchClient.Say(message.Channel, cmdParams[1])
|
||||
return
|
||||
case "ping":
|
||||
commands.Ping(message.Channel, twitchClient)
|
||||
commands.Ping(message.Channel, twitchClient, uptime)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v2"
|
||||
"github.com/lyx0/nourybot/pkg/config"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
@ -10,7 +12,7 @@ import (
|
|||
// *twitch.Client and *config.Config and has the logic to decide if the provided
|
||||
// PrivateMessage is a command or not and passes it on accordingly.
|
||||
// Typical twitch message tags https://paste.ivr.fi/nopiradodo.lua
|
||||
func HandlePrivateMessage(message twitch.PrivateMessage, client *twitch.Client, cfg *config.Config) {
|
||||
func HandlePrivateMessage(message twitch.PrivateMessage, client *twitch.Client, cfg *config.Config, uptime time.Time) {
|
||||
log.Info("fn HandlePrivateMessage")
|
||||
// log.Info(message)
|
||||
|
||||
|
@ -38,7 +40,7 @@ func HandlePrivateMessage(message twitch.PrivateMessage, client *twitch.Client,
|
|||
// Message starts with (), pass it on to
|
||||
// the command handler.
|
||||
if message.Message[:2] == "()" {
|
||||
HandleCommand(message, client)
|
||||
HandleCommand(message, client, uptime)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue