(new): expand runtime APIs
Golang lint / lint (push) Successful in 58s
Golang lint / lint (pull_request) Successful in 13m10s

(fix): harden concurrent lifecycle
(tests): add regression coverage
(doc): update v1.2 guidance
This commit is contained in:
2026-08-20 11:08:45 +03:00
parent 29b208eeec
commit 24040fe164
37 changed files with 1129 additions and 157 deletions
+12 -3
View File
@@ -1,8 +1,10 @@
package laniakea
import (
"errors"
"strings"
"time"
"unicode"
"git.scuroneko.dev/scuroneko/laniakea/tgapi"
)
@@ -21,8 +23,9 @@ func (bot *Bot[T]) handleMessage(update *tgapi.Update, ctx *MessageContext) bool
if strings.Contains(cmd, "@") {
botUsername := bot.username
if botUsername != "" && strings.HasSuffix(cmd, "@"+botUsername) {
cmd = cmd[:len(cmd)-len("@"+botUsername)] // remove @botname
at := strings.LastIndexByte(cmd, '@')
if at > 0 && botUsername != "" && strings.EqualFold(cmd[at+1:], botUsername) {
cmd = cmd[:at] // remove @botname
}
}
@@ -52,6 +55,9 @@ func (bot *Bot[T]) handleMessage(update *tgapi.Update, ctx *MessageContext) bool
})
err := plugin.executeCmd(cmd, ctx, bot.appData)
if errors.Is(err, errMiddlewareBlocked) {
err = nil
}
handlerEndEvent := HandlerFinishedEvent{
UpdateID: update.UpdateID,
UpdateType: update.Type,
@@ -227,6 +233,9 @@ func (bot *Bot[T]) handleCallback(update *tgapi.Update, ctx *MessageContext) boo
ChatID: ctx.ChatID,
})
err := plugin.executePayload(data.Command, ctx, bot.appData)
if errors.Is(err, errMiddlewareBlocked) {
err = nil
}
endEvent := HandlerFinishedEvent{
UpdateID: update.UpdateID,
@@ -282,7 +291,7 @@ func (bot *Bot[T]) checkPrefixes(text string) (string, bool) {
func (bot *Bot[T]) parseCommand(text string) (prefix, cmd, args string) {
if prefix, hasPrefix := bot.checkPrefixes(text); hasPrefix {
text = strings.TrimSpace(text[len(prefix):])
spaceIndex := strings.Index(text, " ")
spaceIndex := strings.IndexFunc(text, unicode.IsSpace)
var cmd string
var args string
if spaceIndex == -1 {