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

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

|

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

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

|

|
||||||
|
|
||||||
Легковесная, простая в использовании и производительная обёртка для Telegram Bot API на Go. Она упрощает разработку ботов благодаря чистой системе плагинов, поддержке中间件, автоматической генерации команд и встроенному ограничителю скорости запросов.
|
Легковесная, простая в использовании и производительная обёртка для Telegram Bot API на Go. Она упрощает разработку ботов благодаря чистой системе плагинов, поддержке Middleware, автоматической генерации команд и встроенному рейтлимитеру.
|
||||||
|
|
||||||
[English](README.md)
|
[English](README.md)
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 297 KiB |
@@ -7,6 +7,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.nix13.pw/scuroneko/extypes"
|
"git.nix13.pw/scuroneko/extypes"
|
||||||
"git.nix13.pw/scuroneko/laniakea/tgapi"
|
"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
|
// Fetch bot info to validate token and get username
|
||||||
u, err := api.GetMe()
|
u, err := api.GetMe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = bot.Close()
|
closeCtx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
||||||
|
defer cancel()
|
||||||
|
_ = bot.Close(closeCtx)
|
||||||
bot.logger.Fatal(err)
|
bot.logger.Fatal(err)
|
||||||
}
|
}
|
||||||
bot.username = Val(u.Username, "")
|
bot.username = Val(u.Username, "")
|
||||||
@@ -176,24 +179,28 @@ func NewBot[T any](opts *BotOpts) *Bot[T] {
|
|||||||
|
|
||||||
// Close gracefully shuts down bot-owned resources.
|
// 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)
|
// - Uploader (waits for pending uploads)
|
||||||
// - API client
|
// - API client long-poll request via ctx
|
||||||
|
// - API client internals
|
||||||
// - RequestLogger (if enabled)
|
// - RequestLogger (if enabled)
|
||||||
// - Main logger
|
// - Main logger
|
||||||
//
|
//
|
||||||
// RunWithContext does not call Close automatically. The caller is responsible
|
// RunWithContext does not call Close automatically. The caller is responsible
|
||||||
// for invoking Close after RunWithContext returns to release these resources.
|
// for invoking Close after RunWithContext returns to release these resources.
|
||||||
//
|
//
|
||||||
// Returns a joined error containing all shutdown failures, if any.
|
// Close returns a joined error containing all shutdown failures, if any.
|
||||||
func (bot *Bot[T]) Close() error {
|
func (bot *Bot[T]) Close(ctx context.Context) error {
|
||||||
var e []error
|
var e []error
|
||||||
|
|
||||||
if err := bot.uploader.Close(); err != nil {
|
if err := bot.uploader.Close(); err != nil {
|
||||||
bot.logger.Errorln(err)
|
bot.logger.Errorln(err)
|
||||||
e = append(e, err)
|
e = append(e, err)
|
||||||
}
|
}
|
||||||
if _, err := bot.api.Close(); err != nil {
|
if _, err := bot.api.CloseWithContext(ctx); err != nil {
|
||||||
bot.logger.Errorln(err)
|
bot.logger.Errorln(err)
|
||||||
e = append(e, err)
|
e = append(e, err)
|
||||||
}
|
}
|
||||||
@@ -476,7 +483,7 @@ func (bot *Bot[T]) AddDatabaseLoggerWriter(writer DbLogger[T]) *Bot[T] {
|
|||||||
// go bot.RunWithContext(ctx)
|
// go bot.RunWithContext(ctx)
|
||||||
// // ... later ...
|
// // ... later ...
|
||||||
// cancel() // triggers graceful shutdown
|
// cancel() // triggers graceful shutdown
|
||||||
// _ = bot.Close()
|
// _ = bot.Close(context.Background())
|
||||||
func (bot *Bot[T]) RunWithContext(ctx context.Context) {
|
func (bot *Bot[T]) RunWithContext(ctx context.Context) {
|
||||||
if len(bot.prefixes) == 0 {
|
if len(bot.prefixes) == 0 {
|
||||||
bot.logger.Fatalln("no prefixes defined")
|
bot.logger.Fatalln("no prefixes defined")
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ module git.nix13.pw/scuroneko/laniakea
|
|||||||
|
|
||||||
go 1.26
|
go 1.26
|
||||||
|
|
||||||
|
retract v1.0.0-rc.5
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.nix13.pw/scuroneko/extypes v1.2.2
|
git.nix13.pw/scuroneko/extypes v1.2.2
|
||||||
git.nix13.pw/scuroneko/slog v1.1.2
|
git.nix13.pw/scuroneko/slog v1.1.2
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VersionString = "1.0.0-rc.4"
|
VersionString = "1.0.0-rc.5"
|
||||||
VersionMajor = 1
|
VersionMajor = 1
|
||||||
VersionMinor = 0
|
VersionMinor = 0
|
||||||
VersionPatch = 0
|
VersionPatch = 0
|
||||||
VersionBeta = 4
|
VersionBeta = 5
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user