+21
-8
@@ -31,7 +31,9 @@ import (
|
||||
// reply helpers need Msg, while inline callback edit helpers can work through
|
||||
// InlineMsgID when there is no chat message.
|
||||
type MessageContext struct {
|
||||
API *tgapi.API
|
||||
// API is the Telegram API client used by context helpers.
|
||||
API *tgapi.API
|
||||
// Update is the Telegram update being handled.
|
||||
Update tgapi.Update
|
||||
|
||||
// Msg is the normalized Telegram message for message-backed update kinds.
|
||||
@@ -81,6 +83,7 @@ type MessageContext struct {
|
||||
payloadType BotPayloadType
|
||||
sceneRuntime sceneRuntime
|
||||
observer Observer
|
||||
eventEmitter func(context.Context, Event)
|
||||
botID int64
|
||||
|
||||
ctx context.Context
|
||||
@@ -89,10 +92,13 @@ type MessageContext struct {
|
||||
// AnswerMessage represents a message sent or edited via MessageContext.
|
||||
// It holds metadata to allow further editing or deletion.
|
||||
type AnswerMessage struct {
|
||||
// MessageID identifies the sent Telegram message.
|
||||
MessageID int
|
||||
Text string
|
||||
IsMedia bool
|
||||
ctx *MessageContext // internal back-reference
|
||||
// Text contains the text or caption sent with the message.
|
||||
Text string
|
||||
// IsMedia reports whether the answer contains media.
|
||||
IsMedia bool
|
||||
ctx *MessageContext // internal back-reference
|
||||
}
|
||||
|
||||
func (ctx *MessageContext) edit(messageID int, text string, keyboard *InlineKeyboard, parseMode tgapi.ParseMode) *AnswerMessage {
|
||||
@@ -631,19 +637,19 @@ func bindPositional(args []string, dst any) error {
|
||||
case reflect.String:
|
||||
field.SetString(raw)
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
n, err := strconv.ParseInt(raw, 10, 64)
|
||||
n, err := strconv.ParseInt(raw, 10, field.Type().Bits())
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: field %s: %v", ErrBindArgsConversion, fieldType.Name, err)
|
||||
}
|
||||
field.SetInt(n)
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
n, err := strconv.ParseUint(raw, 10, 64)
|
||||
n, err := strconv.ParseUint(raw, 10, field.Type().Bits())
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: field %s: %v", ErrBindArgsConversion, fieldType.Name, err)
|
||||
}
|
||||
field.SetUint(n)
|
||||
case reflect.Float32, reflect.Float64:
|
||||
f, err := strconv.ParseFloat(raw, 64)
|
||||
f, err := strconv.ParseFloat(raw, field.Type().Bits())
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: field %s: %v", ErrBindArgsConversion, fieldType.Name, err)
|
||||
}
|
||||
@@ -686,7 +692,14 @@ func (ctx *MessageContext) Context() context.Context {
|
||||
}
|
||||
|
||||
func (ctx *MessageContext) emitPolicyChecked(event PolicyCheckedEvent) {
|
||||
if ctx == nil || ctx.observer == nil {
|
||||
if ctx == nil {
|
||||
return
|
||||
}
|
||||
if ctx.eventEmitter != nil {
|
||||
ctx.eventEmitter(ctx.Context(), event)
|
||||
return
|
||||
}
|
||||
if ctx.observer == nil {
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
|
||||
Reference in New Issue
Block a user