~badt/telebot

e9781d5a63b4fac09cc2f1ec0c7b6becf9393882 — Demian 3 months ago 061d8ab
context: implement helper EditOrSend and EditOrReply functions
1 files changed, 22 insertions(+), 0 deletions(-)

M context.go
M context.go => context.go +22 -0
@@ 97,6 97,14 @@ type Context interface {
	// See EditCaption from bot.go.
	EditCaption(caption string, opts ...interface{}) error

	// EditOrSend edits the current message if the update is callback,
	// otherwise the content is sent to the chat as a separate message.
	EditOrSend(what interface{}, opts ...interface{}) error

	// EditOrReply edits the current message if the update is callback,
	// otherwise the content is replied as a separate message.
	EditOrReply(what interface{}, opts ...interface{}) error

	// Delete removes the current message.
	// See Delete from bot.go.
	Delete() error


@@ 324,6 332,20 @@ func (c *nativeContext) EditCaption(caption string, opts ...interface{}) error {
	return err
}

func (c *nativeContext) EditOrSend(what interface{}, opts ...interface{}) error {
	if c.callback != nil {
		return c.Edit(what, opts...)
	}
	return c.Send(what, opts...)
}

func (c *nativeContext) EditOrReply(what interface{}, opts ...interface{}) error {
	if c.callback != nil {
		return c.Edit(what, opts...)
	}
	return c.Reply(what, opts...)
}

func (c *nativeContext) Delete() error {
	msg := c.Message()
	if msg == nil {