diff --git a/README.md b/README.md index 580c99b..8d594fd 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Laniakea +![Laniakea](assets/logo.jpg) + [![Go Version](https://img.shields.io/badge/Go-1.24+-00ADD8?logo=go&style=flat-square)](https://go.dev/) [![License: GPL-3.0](https://img.shields.io/badge/License-GPL%203.0-blue.svg?style=flat-square)](LICENSE) ![Gitea Release](https://img.shields.io/gitea/v/release/ScuroNeko/Laniakea?gitea_url=https%3A%2F%2Fgit.nix13.pw&sort=semver&display_name=release&style=flat-square&color=purple&link=https%3A%2F%2Fgit.nix13.pw%2FScuroNeko%2FLaniakea%2Freleases) diff --git a/README_RU.md b/README_RU.md index 02b10cb..65a3c4a 100644 --- a/README_RU.md +++ b/README_RU.md @@ -1,5 +1,7 @@ # Laniakea +![Laniakea](assets/logo.jpg) + [![Go Version](https://img.shields.io/badge/Go-1.24+-00ADD8?logo=go&style=flat-square)](https://go.dev/) [![License: GPL-3.0](https://img.shields.io/badge/License-GPL%203.0-blue.svg?style=flat-square)](LICENSE) ![Gitea Release](https://img.shields.io/gitea/v/release/ScuroNeko/Laniakea?gitea_url=https%3A%2F%2Fgit.nix13.pw&sort=semver&display_name=release&style=flat-square&color=purple&link=https%3A%2F%2Fgit.nix13.pw%2FScuroNeko%2FLaniakea%2Freleases) diff --git a/assets/logo.jpg b/assets/logo.jpg new file mode 100644 index 0000000..58815eb Binary files /dev/null and b/assets/logo.jpg differ diff --git a/bot.go b/bot.go index 803a0ed..6b677a6 100644 --- a/bot.go +++ b/bot.go @@ -7,6 +7,7 @@ import ( "sort" "strings" "sync" + "time" "git.nix13.pw/scuroneko/extypes" "git.nix13.pw/scuroneko/laniakea/tgapi" @@ -162,7 +163,9 @@ func NewBot[T any](opts *BotOpts) *Bot[T] { // Fetch bot info to validate token and get username u, err := api.GetMe() if err != nil { - _ = bot.Close() + closeCtx, cancel := context.WithTimeout(context.Background(), time.Second*10) + defer cancel() + _ = bot.Close(closeCtx) bot.logger.Fatal(err) } bot.username = Val(u.Username, "") @@ -176,24 +179,28 @@ func NewBot[T any](opts *BotOpts) *Bot[T] { // Close gracefully shuts down bot-owned resources. // -// Closes: +// The provided context is used to close the API client's long-polling request. +// Upload shutdown is not context-aware and still waits for pending uploads. +// +// Close shuts down, in order: // - Uploader (waits for pending uploads) -// - API client +// - API client long-poll request via ctx +// - API client internals // - RequestLogger (if enabled) // - Main logger // // RunWithContext does not call Close automatically. The caller is responsible // for invoking Close after RunWithContext returns to release these resources. // -// Returns a joined error containing all shutdown failures, if any. -func (bot *Bot[T]) Close() error { +// Close returns a joined error containing all shutdown failures, if any. +func (bot *Bot[T]) Close(ctx context.Context) error { var e []error if err := bot.uploader.Close(); err != nil { bot.logger.Errorln(err) e = append(e, err) } - if _, err := bot.api.Close(); err != nil { + if _, err := bot.api.CloseWithContext(ctx); err != nil { bot.logger.Errorln(err) e = append(e, err) } @@ -476,7 +483,7 @@ func (bot *Bot[T]) AddDatabaseLoggerWriter(writer DbLogger[T]) *Bot[T] { // go bot.RunWithContext(ctx) // // ... later ... // cancel() // triggers graceful shutdown -// _ = bot.Close() +// _ = bot.Close(context.Background()) func (bot *Bot[T]) RunWithContext(ctx context.Context) { if len(bot.prefixes) == 0 { bot.logger.Fatalln("no prefixes defined") diff --git a/utils/version.go b/utils/version.go index f335c22..e261a40 100644 --- a/utils/version.go +++ b/utils/version.go @@ -1,9 +1,9 @@ package utils const ( - VersionString = "1.0.0-rc.4" + VersionString = "1.0.0-rc.5" VersionMajor = 1 VersionMinor = 0 VersionPatch = 0 - VersionBeta = 4 + VersionBeta = 5 )