(new): expand runtime APIs
(fix): harden concurrent lifecycle (tests): add regression coverage (doc): update v1.2 guidance
This commit is contained in:
+12
-3
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user