Documentation
¶
Index ¶
- func AddMessageToCache(escarbot *EscarBot, message *tgbotapi.Message)
- func BotPoll(escarbot *EscarBot)
- func HandleCaptchaCallback(escarbot *EscarBot, callback *tgbotapi.CallbackQuery)
- func HandleStatsMessage(bot *EscarBot, msg *tgbotapi.Message)
- func SendCaptcha(escarbot *EscarBot, chatID int64, user tgbotapi.User, joinMsgID int, ...)
- func UpdateMessageInCache(escarbot *EscarBot, message *tgbotapi.Message)
- type Cache
- func (c *Cache) AddMessage(chatID int64, msg CachedMessage, maxSize int) bool
- func (c *Cache) CleanupJoinEntries()
- func (c *Cache) DeleteCaptcha(userID int64)
- func (c *Cache) GetAllChats() []ChatInfo
- func (c *Cache) GetAllMessages() map[int64][]CachedMessage
- func (c *Cache) GetCaptcha(userID int64) (*PendingCaptcha, bool)
- func (c *Cache) GetChatInfo(chatID int64) (ChatInfo, bool)
- func (c *Cache) GetJoinEntry(userID int64) (*JoinProcessedEntry, bool)
- func (c *Cache) GetMessages(chatID int64) []CachedMessage
- func (c *Cache) GetReactions(chatID int64) ([]string, bool)
- func (c *Cache) HasCaptcha(userID int64) bool
- func (c *Cache) SetBotReaction(chatID int64, msgID int, emoji string) (CachedMessage, bool)
- func (c *Cache) SetCaptcha(userID int64, captcha *PendingCaptcha, ttl time.Duration)
- func (c *Cache) SetChatInfo(chatID int64, info ChatInfo)
- func (c *Cache) SetJoinEntry(userID int64, entry *JoinProcessedEntry)
- func (c *Cache) SetReactions(chatID int64, reactions []string)
- func (c *Cache) UpdateCaptchaJoinMsgID(userID int64, joinMsgID int)
- func (c *Cache) UpdateIndividualReaction(chatID int64, msgID int, userName string, newReactions []tgbotapi.ReactionType) (CachedMessage, bool)
- func (c *Cache) UpdateJoinEntryBanned(userID int64)
- func (c *Cache) UpdateJoinEntryMsgID(userID int64, joinMsgID int) (*JoinProcessedEntry, bool)
- func (c *Cache) UpdateMessage(chatID int64, updated *tgbotapi.Message) (CachedMessage, bool)
- func (c *Cache) UpdateReactions(chatID int64, msgID int, reactions []tgbotapi.ReactionCount) (CachedMessage, bool)
- type CachedMessage
- type CachedPoll
- type CachedPollOption
- type ChatInfo
- type EscarBot
- type FallbackHandler
- func (h FallbackHandler) Box(txt string, fnt plotfont.Font) (vg.Length, vg.Length, vg.Length)
- func (h FallbackHandler) Cache() *plotfont.Cache
- func (h FallbackHandler) Draw(c vg.Canvas, txt string, sty text.Style, pt vg.Point)
- func (h FallbackHandler) Extents(fnt plotfont.Font) plotfont.Extents
- func (h FallbackHandler) Lines(s string) []string
- type JoinProcessedEntry
- type MessageHistory
- type PendingCaptcha
- type ReactionDetail
- type Replacer
- type StatsRow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddMessageToCache ¶
AddMessageToCache adds a message to the recent messages cache
func HandleCaptchaCallback ¶
func HandleCaptchaCallback(escarbot *EscarBot, callback *tgbotapi.CallbackQuery)
func HandleStatsMessage ¶
func SendCaptcha ¶
func UpdateMessageInCache ¶
UpdateMessageInCache updates a message in the recent messages cache
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache handles all bot caching, backed by Valkey/Redis when an address is provided, or falling back to in-memory storage when addr is empty.
func (*Cache) AddMessage ¶
func (c *Cache) AddMessage(chatID int64, msg CachedMessage, maxSize int) bool
AddMessage prepends msg to the chat's message list (capped at maxSize). Returns true if the message was actually added (not a duplicate).
func (*Cache) CleanupJoinEntries ¶
func (c *Cache) CleanupJoinEntries()
CleanupJoinEntries removes stale entries in in-memory mode (Redis handles TTL expiry automatically).
func (*Cache) DeleteCaptcha ¶
DeleteCaptcha removes a pending captcha and its associated timer.
func (*Cache) GetAllChats ¶
GetAllChats returns all cached chat metadata.
func (*Cache) GetAllMessages ¶
func (c *Cache) GetAllMessages() map[int64][]CachedMessage
GetAllMessages returns all cached messages keyed by chat ID.
func (*Cache) GetCaptcha ¶
func (c *Cache) GetCaptcha(userID int64) (*PendingCaptcha, bool)
GetCaptcha returns the pending captcha state for a user.
func (*Cache) GetChatInfo ¶
GetChatInfo returns cached chat metadata.
func (*Cache) GetJoinEntry ¶
func (c *Cache) GetJoinEntry(userID int64) (*JoinProcessedEntry, bool)
GetJoinEntry returns the join deduplication record for a user.
func (*Cache) GetMessages ¶
func (c *Cache) GetMessages(chatID int64) []CachedMessage
GetMessages returns all cached messages for the given chat.
func (*Cache) GetReactions ¶
GetReactions returns the allowed emoji reactions for a chat.
func (*Cache) HasCaptcha ¶
HasCaptcha reports whether a captcha is pending for the given user.
func (*Cache) SetBotReaction ¶
SetBotReaction records the bot's own reaction on a cached message.
func (*Cache) SetCaptcha ¶
func (c *Cache) SetCaptcha(userID int64, captcha *PendingCaptcha, ttl time.Duration)
SetCaptcha stores a pending captcha. The ExpirationTimer is kept in-memory; when using Valkey the record is stored with the given TTL.
func (*Cache) SetChatInfo ¶
SetChatInfo stores chat metadata and records the chat ID in the index set.
func (*Cache) SetJoinEntry ¶
func (c *Cache) SetJoinEntry(userID int64, entry *JoinProcessedEntry)
SetJoinEntry stores a join deduplication record with a 1-minute TTL.
func (*Cache) SetReactions ¶
SetReactions stores the allowed emoji reactions for a chat.
func (*Cache) UpdateCaptchaJoinMsgID ¶
UpdateCaptchaJoinMsgID sets JoinMsgID on a pending captcha if it was zero.
func (*Cache) UpdateIndividualReaction ¶
func (c *Cache) UpdateIndividualReaction(chatID int64, msgID int, userName string, newReactions []tgbotapi.ReactionType) (CachedMessage, bool)
UpdateIndividualReaction updates a single user's emoji reaction on a message.
func (*Cache) UpdateJoinEntryBanned ¶
UpdateJoinEntryBanned marks a join record as banned.
func (*Cache) UpdateJoinEntryMsgID ¶
func (c *Cache) UpdateJoinEntryMsgID(userID int64, joinMsgID int) (*JoinProcessedEntry, bool)
UpdateJoinEntryMsgID sets JoinMsgID on an existing join record if it was zero.
func (*Cache) UpdateMessage ¶
UpdateMessage edits an existing cached message's text/caption and saves a history entry. Returns the updated message and true when found.
func (*Cache) UpdateReactions ¶
func (c *Cache) UpdateReactions(chatID int64, msgID int, reactions []tgbotapi.ReactionCount) (CachedMessage, bool)
UpdateReactions updates the aggregate reaction counts for a cached message.
type CachedMessage ¶
type CachedMessage struct {
MessageID int `json:"message_id"`
ChatID int64 `json:"chat_id,string"`
ChatTitle string `json:"chat_title,omitempty"`
ChatPhotoURL string `json:"chat_photo_url,omitempty"`
FromUsername string `json:"from_username"`
FromFirstName string `json:"from_first_name"`
Text string `json:"text"`
Caption string `json:"caption,omitempty"`
MediaURL string `json:"media_url,omitempty"`
MediaType string `json:"media_type,omitempty"`
MediaDuration int `json:"media_duration,omitempty"`
MediaTitle string `json:"media_title,omitempty"`
MediaFilename string `json:"media_filename,omitempty"`
MediaMimeType string `json:"media_mime_type,omitempty"`
MediaFileSize int64 `json:"media_file_size,omitempty"`
Poll *CachedPoll `json:"poll,omitempty"`
Entities []tgbotapi.MessageEntity `json:"entities,omitempty"`
ThreadID int `json:"thread_id,omitempty"`
IsTopicMessage bool `json:"is_topic_message"`
AvailableReactions []string `json:"available_reactions,omitempty"`
Reactions []tgbotapi.ReactionCount `json:"reactions,omitempty"`
RecentReactions []ReactionDetail `json:"recent_reactions,omitempty"`
BotReaction string `json:"bot_reaction,omitempty"`
History []MessageHistory `json:"history,omitempty"`
}
CachedMessage represents a message stored in cache
type CachedPoll ¶
type CachedPoll struct {
Question string `json:"question"`
Options []CachedPollOption `json:"options"`
TotalVoterCount int `json:"total_voter_count"`
IsClosed bool `json:"is_closed"`
IsAnonymous bool `json:"is_anonymous"`
Type string `json:"type"`
AllowsMultipleAnswers bool `json:"allows_multiple_answers"`
}
CachedPoll represents a Telegram poll
type CachedPollOption ¶
CachedPollOption represents a single option in a poll
type ChatInfo ¶
type ChatInfo struct {
ID int64 `json:"id,string"`
Title string `json:"title"`
PhotoURL string `json:"photo_url,omitempty"`
}
ChatInfo represents information about a Telegram chat
type EscarBot ¶
type EscarBot struct {
Bot *tgbotapi.BotAPI
Power bool
LinkDetection bool
ChannelForward bool
AdminForward bool
AutoBan bool
Captcha bool
CaptchaTimeout int
CaptchaMaxRetries int
WelcomeMessage bool
StatsFeature bool
StatsShowNotes bool
ChannelID int64
GroupID int64
AdminID int64
LogChannelID int64
StatsChatID int64
StatsPolynomialDegree int
BannedWords []string
StateMutex sync.RWMutex
MaxCacheSize int
OnMessageCached func(CachedMessage) // Callback for when a message is cached
WelcomeText string
WelcomeLinks string
WelcomePhoto string
CaptchaText string
ChatBlacklist []int64
EnabledReplacers map[string]bool
Cache *Cache
}
type FallbackHandler ¶
type FallbackHandler struct {
// contains filtered or unexported fields
}
func (FallbackHandler) Cache ¶
func (h FallbackHandler) Cache() *plotfont.Cache
func (FallbackHandler) Extents ¶
func (h FallbackHandler) Extents(fnt plotfont.Font) plotfont.Extents
func (FallbackHandler) Lines ¶
func (h FallbackHandler) Lines(s string) []string
type JoinProcessedEntry ¶
type JoinProcessedEntry struct {
Time time.Time `json:"time"`
JoinMsgID int `json:"join_msg_id"`
IsBanned bool `json:"is_banned"`
}
JoinProcessedEntry represents a join event that was already processed
type MessageHistory ¶
type MessageHistory struct {
Text string `json:"text"`
Caption string `json:"caption,omitempty"`
EditDate int64 `json:"edit_date"`
}
MessageHistory represents a previous version of a message
type PendingCaptcha ¶
type ReactionDetail ¶
ReactionDetail represents an individual reaction by a user
type Replacer ¶
func GetReplacers ¶
func GetReplacers() []Replacer