fluid-telegram/internal/tg/live.go

51 lines
1.1 KiB
Go
Raw Normal View History

package tg
import (
"context"
"github.com/tegwick/fluid-telegram/internal/state"
)
// Live implements plan.Live over a connected client, so that a plan is computed
// against what is actually there rather than against the state file's memory of
// it. Everything it reports is observed; nothing is assumed.
type Live struct {
Ctx context.Context
Client *Client
Resolved *state.Resolved
}
func (l Live) BotExists(username string) (bool, error) {
if username == "" {
return false, nil
}
_, err := l.Client.API().ContactsResolveUsername(l.Ctx, resolveReq(username))
if err != nil {
if isNotFound(err) {
return false, nil
}
return false, err
}
return true, nil
}
func (l Live) ChannelAdminRights(chatID int64) ([]string, error) {
ch, err := l.channel(chatID)
if err != nil {
return nil, err
}
return l.Client.AdminRights(l.Ctx, ch, l.Resolved.Bot.ID)
}
func (l Live) ChannelUsername(chatID int64) (string, error) {
ch, err := l.channel(chatID)
if err != nil {
return "", err
}
return l.Client.ChannelUsername(l.Ctx, ch)
}
func (l Live) channel(chatID int64) (Channel, error) {
return l.Client.ResolveChannel(l.Ctx, chatID)
}