feat: added the As() method to the context.

This commit is contained in:
Andrey Parhomenko 2023-12-20 19:58:10 +03:00
parent cc8f7e82e2
commit 23a34b0ed3
2 changed files with 18 additions and 0 deletions

View file

@ -106,6 +106,9 @@ func (btn *Button) ToTelegramInline() apix.InlineKeyboardButton {
// Return the key of the button to identify it by messages and callbacks.
func (btn *Button) Key() string {
if btn == nil {
return ""
}
if btn.Data != "" {
return btn.Data
}

View file

@ -63,6 +63,21 @@ type Context struct {
input *UpdateChan
}
// Run commands as other user. Was implemented to
// make other user to leave the bot at first but
// maybe you will find another usage for this.
// Returns users context by specified session ID
// or nil if the user is not logged in.
func (c *Context) As(sid SessionId) *Context {
n, ok := c.Bot.contexts[sid]
if !ok {
return nil
}
return &Context{
context: n,
}
}
func (c *Context) GetContext() *Context {
return c
}