fix: changed implementation of interface Sendable for the file type.
This commit is contained in:
parent
daeede9315
commit
dd549d5350
3 changed files with 39 additions and 39 deletions
|
@ -30,7 +30,7 @@ func NewMutateMessageWidget(fn func(string) string) *MutateMessageWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *MutateMessageWidget) Serve(c *tg.Context) {
|
func (w *MutateMessageWidget) Serve(c *tg.Context) {
|
||||||
args, ok := c.Arg.([]any)
|
args, ok := c.Arg().([]any)
|
||||||
if ok {
|
if ok {
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
c.Sendf("%v", arg)
|
c.Sendf("%v", arg)
|
||||||
|
|
|
@ -7,6 +7,36 @@ import (
|
||||||
//"path"
|
//"path"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// General context for a specific user.
|
||||||
|
// Is always the same and is not reached
|
||||||
|
// inside end function-handlers.
|
||||||
|
type context struct {
|
||||||
|
Session *Session
|
||||||
|
// To reach the bot abilities inside callbacks.
|
||||||
|
Bot *Bot
|
||||||
|
// Costum status for currently running context.
|
||||||
|
Status any
|
||||||
|
Type ContextType
|
||||||
|
updates *UpdateChan
|
||||||
|
skippedUpdates *UpdateChan
|
||||||
|
// Current screen ID.
|
||||||
|
pathHistory []Path
|
||||||
|
//path, prevPath Path
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interface to interact with the user.
|
||||||
|
type Context struct {
|
||||||
|
*context
|
||||||
|
// The update that called the Context usage.
|
||||||
|
*Update
|
||||||
|
// Used as way to provide outer values redirection
|
||||||
|
// into widgets and actions. It is like arguments
|
||||||
|
// for REST API request etc.
|
||||||
|
arg any
|
||||||
|
// Instead of updates as argument.
|
||||||
|
input *UpdateChan
|
||||||
|
}
|
||||||
|
|
||||||
// General type function to define actions, single component widgets
|
// General type function to define actions, single component widgets
|
||||||
// and components themselves.
|
// and components themselves.
|
||||||
type Func func(*Context)
|
type Func func(*Context)
|
||||||
|
@ -32,23 +62,6 @@ const (
|
||||||
ActionContextType
|
ActionContextType
|
||||||
)
|
)
|
||||||
|
|
||||||
// General context for a specific user.
|
|
||||||
// Is always the same and is not reached
|
|
||||||
// inside end function-handlers.
|
|
||||||
type context struct {
|
|
||||||
Session *Session
|
|
||||||
// To reach the bot abilities inside callbacks.
|
|
||||||
Bot *Bot
|
|
||||||
// Costum status for currently running context.
|
|
||||||
Status any
|
|
||||||
Type ContextType
|
|
||||||
updates *UpdateChan
|
|
||||||
skippedUpdates *UpdateChan
|
|
||||||
// Current screen ID.
|
|
||||||
pathHistory []Path
|
|
||||||
//path, prevPath Path
|
|
||||||
}
|
|
||||||
|
|
||||||
// Goroutie function to handle each user.
|
// Goroutie function to handle each user.
|
||||||
func (c *Context) serve() {
|
func (c *Context) serve() {
|
||||||
beh := c.Bot.behaviour
|
beh := c.Bot.behaviour
|
||||||
|
@ -56,11 +69,6 @@ func (c *Context) serve() {
|
||||||
beh.Root.Serve(c)
|
beh.Root.Serve(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c *context) run(a Action, u *Update) {
|
|
||||||
a.Act(&Context{context: c, Update: u})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Context) Path() Path {
|
func (c *Context) Path() Path {
|
||||||
ln := len(c.pathHistory)
|
ln := len(c.pathHistory)
|
||||||
if ln == 0 {
|
if ln == 0 {
|
||||||
|
@ -69,6 +77,10 @@ func (c *Context) Path() Path {
|
||||||
return c.pathHistory[ln-1]
|
return c.pathHistory[ln-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Context) Arg() any {
|
||||||
|
return c.arg
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Context) Run(a Action) {
|
func (c *Context) Run(a Action) {
|
||||||
if a != nil {
|
if a != nil {
|
||||||
a.Act(c)
|
a.Act(c)
|
||||||
|
@ -112,18 +124,6 @@ func (c *Context) SendfHTML(format string, v ...any) (*Message, error) {
|
||||||
return c.Send(NewMessage(fmt.Sprintf(format, v...)).HTML())
|
return c.Send(NewMessage(fmt.Sprintf(format, v...)).HTML())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface to interact with the user.
|
|
||||||
type Context struct {
|
|
||||||
*context
|
|
||||||
// The update that called the Context usage.
|
|
||||||
*Update
|
|
||||||
// Used as way to provide outer values redirection
|
|
||||||
// into widgets and actions. It is like arguments
|
|
||||||
// for REST API request etc.
|
|
||||||
Arg any
|
|
||||||
// Instead of updates as argument.
|
|
||||||
input *UpdateChan
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the input for current widget.
|
// Get the input for current widget.
|
||||||
// Should be used inside handlers (aka "Serve").
|
// Should be used inside handlers (aka "Serve").
|
||||||
|
@ -143,7 +143,7 @@ func (c *Context) Copy() *Context {
|
||||||
|
|
||||||
func (c *Context) WithArg(v any) *Context {
|
func (c *Context) WithArg(v any) *Context {
|
||||||
c = c.Copy()
|
c = c.Copy()
|
||||||
c.Arg = v
|
c.arg = v
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,14 +77,14 @@ func (f *File) SendData() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
func (f *File) SendConfig(
|
func (f *File) SendConfig(
|
||||||
c *Context,
|
sid SessionId, bot *Bot,
|
||||||
) (*SendConfig) {
|
) (*SendConfig) {
|
||||||
var config SendConfig
|
var config SendConfig
|
||||||
sid := c.Session.Id.ToApi()
|
cid := sid.ToApi()
|
||||||
|
|
||||||
switch f.Type() {
|
switch f.Type() {
|
||||||
case ImageFileType:
|
case ImageFileType:
|
||||||
photo := tgbotapi.NewPhoto(sid, f)
|
photo := tgbotapi.NewPhoto(cid, f)
|
||||||
photo.Caption = f.caption
|
photo.Caption = f.caption
|
||||||
|
|
||||||
config.Image = &photo
|
config.Image = &photo
|
||||||
|
|
Loading…
Reference in a new issue