mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
only call run from the main function so we can have return codes on main
This commit is contained in:
parent
8f685cb3e2
commit
6acc16b6cc
|
@ -183,7 +183,7 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
|
|||
reply, _ = commands.Phonetic(message.Message[11:len(message.Message)])
|
||||
}
|
||||
case "ping":
|
||||
reply = commands.Ping()
|
||||
reply = commands.Ping(app.Environment)
|
||||
// ()bttv <emote name>
|
||||
|
||||
// ()weather <location>
|
||||
|
|
|
@ -322,7 +322,6 @@ func (app *application) GofileDownload(target, link, identifier string, msg twit
|
|||
// time.Sleep(duration)
|
||||
|
||||
go app.NewUpload("gofile", fileName, target, identifier, msg)
|
||||
|
||||
}
|
||||
|
||||
func (app *application) CatboxDownload(target, link, identifier string, msg twitch.PrivateMessage) {
|
||||
|
|
|
@ -4,7 +4,9 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/gempir/go-twitch-irc/v4"
|
||||
|
@ -47,7 +49,20 @@ type application struct {
|
|||
// Rdb *redis.Client
|
||||
}
|
||||
|
||||
// main() only calls the run function so that we can go around the limitation
|
||||
// that main() cannot return anything, like int for error codes in c for example.
|
||||
// https://grafana.com/blog/2024/02/09/how-i-write-http-services-in-go-after-13-years/
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
|
||||
defer cancel()
|
||||
if err := run(ctx, os.Stdout, os.Args); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func run(ctx context.Context, w io.Writer, args []string) error {
|
||||
var cfg config
|
||||
// Initialize a new sugared logger that we'll pass on
|
||||
// down through the application.
|
||||
|
@ -216,6 +231,7 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// openDB returns the sql.DB connection pool.
|
||||
|
@ -249,4 +265,5 @@ func openDB(cfg config) (*sql.DB, error) {
|
|||
}
|
||||
|
||||
return db, nil
|
||||
|
||||
}
|
||||
|
|
|
@ -7,12 +7,10 @@ import (
|
|||
"github.com/lyx0/nourybot/pkg/humanize"
|
||||
)
|
||||
|
||||
func Ping() string {
|
||||
func Ping(env string) string {
|
||||
botUptime := humanize.Time(common.GetUptime())
|
||||
commandsUsed := common.GetCommandsUsed()
|
||||
commit := common.GetVersion()
|
||||
|
||||
reply := fmt.Sprintf("Pong! :) Commands used: %v, Last restart: %v, Running on commit: %v", commandsUsed, botUptime, commit)
|
||||
|
||||
return reply
|
||||
return fmt.Sprintf("Pong! :) Commands used: %v, Last restart: %v, Running on commit: %v, Env: %v", commandsUsed, botUptime, commit, env)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue