REPOSITORY / ScuroNeko/Laniakea
Compare commits
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d04c91342b
|
||
|
|
2e14d8b5df
|
@@ -1,5 +1,7 @@
|
||||
# Laniakea
|
||||
|
||||

|
||||
|
||||
[](https://go.dev/)
|
||||
[](LICENSE)
|
||||

|
||||
|
||||
+3
-1
@@ -1,10 +1,12 @@
|
||||
# Laniakea
|
||||
|
||||

|
||||
|
||||
[](https://go.dev/)
|
||||
[](LICENSE)
|
||||

|
||||
|
||||
Легковесная, простая в использовании и производительная обёртка для Telegram Bot API на Go. Она упрощает разработку ботов благодаря чистой системе плагинов, поддержке中间件, автоматической генерации команд и встроенному ограничителю скорости запросов.
|
||||
Легковесная, простая в использовании и производительная обёртка для Telegram Bot API на Go. Она упрощает разработку ботов благодаря чистой системе плагинов, поддержке Middleware, автоматической генерации команд и встроенному рейтлимитеру.
|
||||
|
||||
[English](README.md)
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 297 KiB |
@@ -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")
|
||||
|
||||
+2
-2
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user