Documentation
¶
Overview ¶
Package cmdlib contains utlities mostly for bot
Index ¶
- Constants
- Variables
- func CanonicalStreamerID(name string) string
- func CheckErr(err error)
- func CloseBody(body io.Closer)
- func Ldbg(format string, v ...interface{})
- func Lerr(format string, v ...interface{})
- func Linf(format string, v ...interface{})
- func LoadAllAds(files map[string][]string) (trMap map[string]map[string]*Translation, tpl map[string]*template.Template)
- func LoadAllTranslations(files map[string][]string) (trMap map[string]*Translations, tpl map[string]*template.Template)
- func LoadEndpointTranslations(files []string) (*Translations, AllTranslations)
- func NoRedirect(_ *http.Request, _ []*http.Request) error
- func OnlineQuery(usersOnlineEndpoint string, client *Client, headers [][2]string) (*http.Response, *bytes.Buffer, error)
- func OnlineRequest(req *http.Request, client *Client) (*http.Response, *bytes.Buffer, error)
- func StartCheckerDaemon(checker Checker)
- type AllTranslations
- type CheckMode
- type Checker
- type CheckerCommon
- func (c *CheckerCommon) Debug() bool
- func (c *CheckerCommon) DoGetRequest(url string) (net.Addr, *http.Response)
- func (c *CheckerCommon) Init(config CheckerConfig)
- func (c *CheckerCommon) PushStatusRequest(request StatusRequest) error
- func (c *CheckerCommon) QueryFixedListStatuses(_ []string, _ CheckMode) (map[string]StreamerInfoWithStatus, error)
- func (c *CheckerCommon) QueryStatusCode(url string) int
- func (c *CheckerCommon) RequestInterval() time.Duration
- func (c *CheckerCommon) StatusRequestsQueue() chan StatusRequest
- func (c *CheckerCommon) SubjectSupported() bool
- type CheckerConfig
- type CheckerResults
- type Client
- type ExistenceListResults
- type FixedListOnlineRequest
- type FixedListOnlineResults
- type FixedListStatusRequest
- type OnlineListRequest
- type OnlineListResults
- type ParseKind
- type Secret
- type ShowKind
- type StatusKind
- type StatusRequest
- type StatusUpdate
- type StreamerInfo
- type StreamerInfoWithStatus
- type StringSetFlag
- type Translation
- type Translations
- type VerbosityKind
Constants ¶
const ( SilentVerbosity = 0 ErrVerbosity = 1 InfVerbosity = 2 DbgVerbosity = 3 )
Verbosity constants
Variables ¶
var CommonStreamerIDRegexp = regexp.MustCompile(`^[a-z0-9\-_@]+$`)
CommonStreamerIDRegexp is a regular expression to check streamer IDs
var ErrFullQueue = errors.New("queue is full")
ErrFullQueue emerges whenever we unable to add a request because the queue is full
var ErrNotImplemented = errors.New("not implemented")
ErrNotImplemented emerges when a method is not implemented
var Version = "(devel)"
Version is the version of the current code state
Functions ¶
func CanonicalStreamerID ¶ added in v2.6.0
CanonicalStreamerID preprocesses streamer ID string to canonical form
func LoadAllAds ¶
func LoadAllAds(files map[string][]string) (trMap map[string]map[string]*Translation, tpl map[string]*template.Template)
LoadAllAds loads all ads
func LoadAllTranslations ¶
func LoadAllTranslations(files map[string][]string) (trMap map[string]*Translations, tpl map[string]*template.Template)
LoadAllTranslations loads all translations
func LoadEndpointTranslations ¶
func LoadEndpointTranslations(files []string) (*Translations, AllTranslations)
LoadEndpointTranslations loads translations for a specific endpoint
func NoRedirect ¶
NoRedirect tells HTTP client not to redirect
func OnlineQuery ¶
func OnlineQuery( usersOnlineEndpoint string, client *Client, headers [][2]string, ) ( *http.Response, *bytes.Buffer, error, )
OnlineQuery creates and performs online request
func OnlineRequest ¶
OnlineRequest performs online request
func StartCheckerDaemon ¶
func StartCheckerDaemon(checker Checker)
StartCheckerDaemon starts a checker daemon
Types ¶
type AllTranslations ¶
type AllTranslations map[string]*Translation
AllTranslations represents a collection of translated texts in all supported languages
func LoadAds ¶
func LoadAds(files []string) AllTranslations
LoadAds loads ads for a specific endpoint
type Checker ¶
type Checker interface {
CheckStatusSingle(streamerID string) StatusKind
QueryOnlineStreamers() (map[string]StreamerInfo, error)
QueryFixedListOnlineStreamers(streamers []string, checkMode CheckMode) (map[string]StreamerInfo, error)
QueryFixedListStatuses(streamers []string, checkMode CheckMode) (map[string]StreamerInfoWithStatus, error)
Init(config CheckerConfig)
PushStatusRequest(request StatusRequest) error
UsesFixedList() bool
StatusRequestsQueue() chan StatusRequest
RequestInterval() time.Duration
Debug() bool
SubjectSupported() bool
}
Checker is the interface for a checker for specific site
type CheckerCommon ¶
type CheckerCommon struct {
CheckerConfig
ClientsLoop clientsLoop
// contains filtered or unexported fields
}
CheckerCommon contains common fields for all the checkers
func (*CheckerCommon) Debug ¶
func (c *CheckerCommon) Debug() bool
Debug returns whether debug mode is enabled
func (*CheckerCommon) DoGetRequest ¶
DoGetRequest performs a GET request respecting the configuration
func (*CheckerCommon) Init ¶
func (c *CheckerCommon) Init(config CheckerConfig)
Init initializes checker common fields
func (*CheckerCommon) PushStatusRequest ¶
func (c *CheckerCommon) PushStatusRequest(request StatusRequest) error
PushStatusRequest adds a status request to the queue
func (*CheckerCommon) QueryFixedListStatuses ¶
func (c *CheckerCommon) QueryFixedListStatuses(_ []string, _ CheckMode) (map[string]StreamerInfoWithStatus, error)
QueryFixedListStatuses returns ErrNotImplemented by default. Checkers that support querying streamer existence should override this.
func (*CheckerCommon) QueryStatusCode ¶
func (c *CheckerCommon) QueryStatusCode(url string) int
QueryStatusCode performs a GET request and returns only the status code
func (*CheckerCommon) RequestInterval ¶
func (c *CheckerCommon) RequestInterval() time.Duration
RequestInterval returns the interval between requests
func (*CheckerCommon) StatusRequestsQueue ¶
func (c *CheckerCommon) StatusRequestsQueue() chan StatusRequest
StatusRequestsQueue returns the channel for status requests
func (*CheckerCommon) SubjectSupported ¶
func (c *CheckerCommon) SubjectSupported() bool
SubjectSupported returns whether the checker supports room subjects
type CheckerConfig ¶
type CheckerConfig struct {
UsersOnlineEndpoints []string
Clients []*Client
Headers [][2]string
Dbg bool
SpecificConfig map[string]Secret
QueueSize int
IntervalMs int
}
CheckerConfig represents checker config
type CheckerResults ¶
type CheckerResults interface {
Duration() time.Duration
Failed() bool
Count() int
// contains filtered or unexported methods
}
CheckerResults is the interface for status results
type Client ¶
type Client struct {
// Client is HTTP client
Client *http.Client
// Addr is source IP address
Addr net.Addr
}
Client wraps HTTP client and source IP address
type ExistenceListResults ¶
type ExistenceListResults struct {
Streamers map[string]StreamerInfoWithStatus
// contains filtered or unexported fields
}
ExistenceListResults contains results for ExistenceListRequest
func NewExistenceListResults ¶
func NewExistenceListResults( streamers map[string]StreamerInfoWithStatus, duration time.Duration, ) *ExistenceListResults
NewExistenceListResults creates a successful ExistenceListResults.
func NewExistenceListResultsFailed ¶
func NewExistenceListResultsFailed() *ExistenceListResults
NewExistenceListResultsFailed creates a failed ExistenceListResults.
func (*ExistenceListResults) Count ¶
func (r *ExistenceListResults) Count() int
Count returns the number of streamers in the result.
func (*ExistenceListResults) Duration ¶
func (r *ExistenceListResults) Duration() time.Duration
Duration returns the elapsed time for the request.
func (*ExistenceListResults) Failed ¶
func (r *ExistenceListResults) Failed() bool
Failed returns whether the request failed.
type FixedListOnlineRequest ¶
type FixedListOnlineRequest struct {
Streamers map[string]bool
ResultsCh chan<- CheckerResults
}
FixedListOnlineRequest requests statuses for specific streamers
type FixedListOnlineResults ¶
type FixedListOnlineResults struct {
RequestedStreamers map[string]bool
Streamers map[string]StreamerInfo
// contains filtered or unexported fields
}
FixedListOnlineResults contains results for FixedListOnlineRequest
func NewFixedListOnlineResults ¶
func NewFixedListOnlineResults( requestedStreamers map[string]bool, streamers map[string]StreamerInfo, duration time.Duration, ) *FixedListOnlineResults
NewFixedListOnlineResults creates a successful FixedListOnlineResults.
func NewFixedListOnlineResultsFailed ¶
func NewFixedListOnlineResultsFailed() *FixedListOnlineResults
NewFixedListOnlineResultsFailed creates a failed FixedListOnlineResults.
func (*FixedListOnlineResults) Count ¶
func (r *FixedListOnlineResults) Count() int
Count returns the number of streamers in the result.
func (*FixedListOnlineResults) Duration ¶
func (r *FixedListOnlineResults) Duration() time.Duration
Duration returns the elapsed time for the request.
func (*FixedListOnlineResults) Failed ¶
func (r *FixedListOnlineResults) Failed() bool
Failed returns whether the request failed.
type FixedListStatusRequest ¶
type FixedListStatusRequest struct {
Streamers map[string]bool
ResultsCh chan<- *ExistenceListResults
}
FixedListStatusRequest checks if specific streamers exist
type OnlineListRequest ¶
type OnlineListRequest struct {
ResultsCh chan<- CheckerResults
}
OnlineListRequest requests statuses for all online streamers
type OnlineListResults ¶
type OnlineListResults struct {
Streamers map[string]StreamerInfo
// contains filtered or unexported fields
}
OnlineListResults contains results for OnlineListRequest
func NewOnlineListResults ¶
func NewOnlineListResults(streamers map[string]StreamerInfo, duration time.Duration) *OnlineListResults
NewOnlineListResults creates a successful OnlineListResults.
func NewOnlineListResultsFailed ¶
func NewOnlineListResultsFailed() *OnlineListResults
NewOnlineListResultsFailed creates a failed OnlineListResults.
func (*OnlineListResults) Count ¶
func (r *OnlineListResults) Count() int
Count returns the number of streamers in the result.
func (*OnlineListResults) Duration ¶
func (r *OnlineListResults) Duration() time.Duration
Duration returns the elapsed time for the request.
func (*OnlineListResults) Failed ¶
func (r *OnlineListResults) Failed() bool
Failed returns whether the request failed.
type ParseKind ¶
type ParseKind int
ParseKind specifies Telegram message parsing method
func (ParseKind) MarshalYAML ¶
MarshalYAML is generated so ParseKind satisfies yaml.Marshaler.
func (*ParseKind) UnmarshalYAML ¶
UnmarshalYAML is generated so ParseKind satisfies yaml.Unmarshaler.
type Secret ¶ added in v2.7.0
type Secret string
Secret is a string type that redacts its value in JSON and logs.
func (Secret) MarshalJSON ¶ added in v2.7.0
MarshalJSON redacts the secret value.
type ShowKind ¶
type ShowKind int
ShowKind represents the kind of show
const ( // ShowUnknown means the show kind is unknown ShowUnknown ShowKind = 0 // ShowPublic means the show is public ShowPublic ShowKind = 1 // ShowGroup means the show is a group show ShowGroup ShowKind = 2 // ShowTicket means the show is a ticket show ShowTicket ShowKind = 3 // ShowHidden means the show is hidden ShowHidden ShowKind = 4 // ShowPrivate means the show is private ShowPrivate ShowKind = 5 // ShowAway means the model is away ShowAway ShowKind = 6 )
type StatusKind ¶
type StatusKind int
StatusKind represents a status of a streamer
const ( StatusUnknown StatusKind = 0 StatusOffline StatusKind = 1 StatusOnline StatusKind = 2 StatusNotFound StatusKind = 4 StatusDenied StatusKind = 8 )
Streamer statuses
func (StatusKind) String ¶
func (s StatusKind) String() string
type StatusRequest ¶
type StatusRequest interface {
// contains filtered or unexported methods
}
StatusRequest is the interface for status requests
type StatusUpdate ¶
type StatusUpdate struct {
StreamerID string
Status StatusKind
}
StatusUpdate represents an update of streamer status
type StreamerInfo ¶ added in v2.6.0
StreamerInfo contains image URL for a streamer
type StreamerInfoWithStatus ¶ added in v2.6.0
type StreamerInfoWithStatus struct {
Status StatusKind
ImageURL string
}
StreamerInfoWithStatus contains status and image URL for a streamer
type StringSetFlag ¶
StringSetFlag is a flag representing a set of strings
func (*StringSetFlag) Set ¶
func (s *StringSetFlag) Set(value string) error
Set implements flag.Value interface
func (*StringSetFlag) String ¶
func (s *StringSetFlag) String() string
String implements flag.Value interface
type Translation ¶
type Translation struct {
Key string `yaml:"-"`
Str string `yaml:"str"`
Parse ParseKind `yaml:"parse"`
DisablePreview bool `yaml:"disable_preview"`
Image string `yaml:"image"`
ImageBytes []byte `yaml:"-"`
}
Translation represents a translated text for a Telegram message
type Translations ¶
type Translations struct {
Start *Translation `yaml:"start"`
Help *Translation `yaml:"help"`
Online *Translation `yaml:"online"`
List *Translation `yaml:"list"`
Offline *Translation `yaml:"offline"`
Denied *Translation `yaml:"denied"`
SyntaxAdd *Translation `yaml:"syntax_add"`
SyntaxRemove *Translation `yaml:"syntax_remove"`
SyntaxFeedback *Translation `yaml:"syntax_feedback"`
InvalidSymbols *Translation `yaml:"invalid_symbols"`
AlreadyAdded *Translation `yaml:"already_added"`
AddError *Translation `yaml:"add_error"`
StreamerAdded *Translation `yaml:"streamer_added"`
StreamerNotInList *Translation `yaml:"streamer_not_in_list"`
StreamerRemoved *Translation `yaml:"streamer_removed"`
CheckingStreamer *Translation `yaml:"checking_streamer"`
Feedback *Translation `yaml:"feedback"`
Social *Translation `yaml:"social"`
UnknownCommand *Translation `yaml:"unknown_command"`
InvalidCommand *Translation `yaml:"invalid_command"`
Languages *Translation `yaml:"languages"`
Version *Translation `yaml:"version"`
ProfileRemoved *Translation `yaml:"profile_removed"`
NoOnlineStreamers *Translation `yaml:"no_online_streamers"`
RemoveAll *Translation `yaml:"remove_all"`
AllStreamersRemoved *Translation `yaml:"all_streamers_removed"`
ReferralLink *Translation `yaml:"referral_link"`
InvalidReferralLink *Translation `yaml:"invalid_referral_link"`
FollowerExists *Translation `yaml:"follower_exists"`
ReferralApplied *Translation `yaml:"referral_applied"`
OwnReferralLinkHit *Translation `yaml:"own_referral_link_hit"`
SubscriptionUsage *Translation `yaml:"subscription_usage"`
SubscriptionUsageAd *Translation `yaml:"subscription_usage_ad"`
NotEnoughSubscriptions *Translation `yaml:"not_enough_subscriptions"`
Week *Translation `yaml:"week"`
WeekRetrieving *Translation `yaml:"week_retrieving"`
ZeroSubscriptions *Translation `yaml:"zero_subscriptions"`
FAQ *Translation `yaml:"faq"`
RawCommands *Translation `yaml:"raw_commands"`
Settings *Translation `yaml:"settings"`
OK *Translation `yaml:"ok"`
TooManySubscriptionsForPics *Translation `yaml:"too_many_subscriptions_for_pics"`
WeAreUp *Translation `yaml:"we_are_up"`
FieldsCustomizationHint *Translation `yaml:"fields_customization_hint"`
}
Translations represents a collection of translated texts for Telegram messages
func (*Translations) ToMap ¶
func (x *Translations) ToMap() map[string]*Translation
ToMap returns translations as a map
type VerbosityKind ¶
type VerbosityKind int
VerbosityKind represents logging verbosity
var Verbosity VerbosityKind = DbgVerbosity
Verbosity is the current logging verbosity