Documentation
¶
Index ¶
- Constants
- func DebugHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func HelpText() string
- func MeHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func TelegramCommands() []models.BotCommand
- type BotContext
- type ClaimHandle
- type CommandSpec
- type CommandsHandler
- func (c *CommandsHandler) AddAlarmKeywordHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) AddKeywordHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) AlarmRecordHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) ConvertURLToIMGHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) ConvertURLToPDFHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) DeleteKeywordHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) EditKeywordHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) HandleCallbackQuery(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) ListTodayHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) SearchAlarmRecordHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) SearchHistoryHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- func (c *CommandsHandler) StaticHandler(ctx context.Context, b *bot.Bot, update *models.Update)
- type Crawler
- type GotenbergClient
- type InfoProcessor
- type KeyedLock
- type ManagerHandler
- type ProcessData
- type Project
- type Projects
- type PushPipeline
- type Store
Constants ¶
const DefaultCacheDuration = 10 * time.Minute
Variables ¶
This section is empty.
Functions ¶
func DebugHandler ¶ added in v1.4.2
func HelpText ¶ added in v1.4.9
func HelpText() string
HelpText generates the /start help message from the command registry.
func TelegramCommands ¶ added in v1.4.9
func TelegramCommands() []models.BotCommand
TelegramCommands returns the command list for SetMyCommands. Admin-only commands are still exposed in the Telegram command menu (the handlers enforce the permission), matching the previous behaviour.
Types ¶
type BotContext ¶ added in v1.4.1
type BotContext struct {
Bot *bot.Bot
Store *Store
Logger *utils.Logger
Config *config.ServiceConfig
Gotenberg *GotenbergClient
// contains filtered or unexported fields
}
func NewBotContext ¶ added in v1.4.1
func NewBotContext() (*BotContext, error)
func (*BotContext) Start ¶ added in v1.4.1
func (ctx *BotContext) Start()
func (*BotContext) Stop ¶ added in v1.4.1
func (ctx *BotContext) Stop()
type ClaimHandle ¶ added in v1.4.9
type ClaimHandle struct {
// Key 是进程内锁(KeyedLock)的键;为空表示调用方已自行管理并发
//(例如 projects 的预筛锁已覆盖整个渲染+发送生命周期)。
Key string
// Claim 执行 DB 原子抢占(InsertIfAbsent),返回是否抢到。
// 只有真正抢到的调用才允许发送。
Claim func() (bool, error)
// Send 执行发送;返回 error 表示发送失败,会触发 Rollback 回滚。
Send func() error
// Rollback 在发送失败时回滚抢占(Remove),供下一轮重试。
Rollback func() error
}
ClaimHandle 定义一条可抢占推送的最小单元。
处理骨架固定为:内存锁 → DB 抢占 → 发送 → 失败回滚。 管线只关心骨架,具体业务(唯一键组成、发送内容、回滚语义)由回调提供。
type CommandSpec ¶ added in v1.4.9
type CommandSpec struct {
Command string
Description string
// Usage is the argument placeholder shown in help, e.g. "<k1,k2>".
// Leave empty for commands without arguments.
Usage string
AdminOnly bool
}
CommandSpec describes a bot command. It is the single source of truth for both SetMyCommands registration and the /start help text, so adding a command requires touching exactly one place.
type CommandsHandler ¶
type CommandsHandler struct {
// contains filtered or unexported fields
}
func NewCommandsHandler ¶
func NewCommandsHandler(ctx *BotContext) *CommandsHandler
func (*CommandsHandler) AddAlarmKeywordHandler ¶ added in v1.2.0
func (*CommandsHandler) AddKeywordHandler ¶
func (*CommandsHandler) AlarmRecordHandler ¶ added in v1.4.2
func (*CommandsHandler) ConvertURLToIMGHandler ¶ added in v1.4.1
func (*CommandsHandler) ConvertURLToPDFHandler ¶ added in v1.3.0
func (*CommandsHandler) DeleteKeywordHandler ¶
func (*CommandsHandler) EditKeywordHandler ¶ added in v1.4.0
func (*CommandsHandler) HandleCallbackQuery ¶ added in v1.3.0
func (*CommandsHandler) ListTodayHandler ¶ added in v1.4.7
func (*CommandsHandler) SearchAlarmRecordHandler ¶ added in v1.4.2
func (*CommandsHandler) SearchHistoryHandler ¶ added in v1.3.0
func (*CommandsHandler) StaticHandler ¶ added in v1.4.0
type Crawler ¶ added in v1.4.1
type Crawler struct {
// contains filtered or unexported fields
}
func NewCrawler ¶ added in v1.4.1
func NewCrawler(ctx *BotContext) *Crawler
type GotenbergClient ¶ added in v1.4.1
type GotenbergClient struct {
// contains filtered or unexported fields
}
func NewGotenbergClient ¶ added in v1.4.1
func NewGotenbergClient(host string, hookURL string, token string) (*GotenbergClient, error)
func (*GotenbergClient) HtmlToImage ¶ added in v1.4.1
func (g *GotenbergClient) HtmlToImage(content string) (string, error)
func (*GotenbergClient) URLToImage ¶ added in v1.4.1
func (g *GotenbergClient) URLToImage(u string) (string, error)
type InfoProcessor ¶ added in v1.4.1
type InfoProcessor struct {
// contains filtered or unexported fields
}
func NewInfoProcessor ¶ added in v1.4.1
func NewInfoProcessor(ctx *BotContext) (*InfoProcessor, error)
func (*InfoProcessor) Get ¶ added in v1.4.1
func (r *InfoProcessor) Get(userId int64)
func (*InfoProcessor) Handler ¶ added in v1.4.2
func (r *InfoProcessor) Handler(i interface{})
func (*InfoProcessor) Process ¶ added in v1.4.1
func (r *InfoProcessor) Process()
func (*InfoProcessor) Release ¶ added in v1.4.1
func (r *InfoProcessor) Release()
type KeyedLock ¶ added in v1.4.9
type KeyedLock struct {
// contains filtered or unexported fields
}
KeyedLock is a keyed in-process lock. Callers mark a resource (a project URL, an alarm credit code, ...) as being handled with TryLock, so a concurrent invocation in the same process skips it instead of duplicating the work. Unlock releases the key once the work is done.
KeyedLock is process-local by design. For cross-instance safety (multiple bot processes sharing the same DB), pair it with a DB-backed claim such as dal.InsertIfAbsent, where the table's unique constraint is the authority.
func NewKeyedLock ¶ added in v1.4.9
func NewKeyedLock() *KeyedLock
NewKeyedLock returns an empty KeyedLock.
type ManagerHandler ¶
type ManagerHandler struct {
// contains filtered or unexported fields
}
func NewManagerHandler ¶
func NewManagerHandler(ctx *BotContext) *ManagerHandler
type ProcessData ¶ added in v1.4.1
type ProcessData struct {
UserId int64
ProjectRules []*rule.ComplexRule
AlarmKeyword []string
Projects []*Project
Alarms []*model.Alarm
IsForced bool
}
ProcessData holds the data for processing
type Project ¶ added in v1.4.1
type Project struct {
NoticeTime string `json:"noticeTime,omitempty"`
OpenTenderCode string `json:"openTenderCode,omitempty"`
Title string `json:"title,omitempty"`
ShortTitle string `json:"-"`
Content string `json:"content,omitempty"`
Pageurl string `json:"pageurl,omitempty"`
Keyword string `json:"keyword,omitempty"`
HasTenderCode bool `json:"-"`
}
func (*Project) SplitMessage ¶ added in v1.4.2
type Projects ¶ added in v1.4.1
type Projects struct {
Projects []*Project
// contains filtered or unexported fields
}
func NewProjects ¶ added in v1.4.1
func NewProjects(ctx *BotContext, projects []*Project, rules []*rule.ComplexRule) *Projects
type PushPipeline ¶ added in v1.4.9
type PushPipeline struct {
// contains filtered or unexported fields
}
PushPipeline 串行处理一批可抢占推送。同一进程内相同 Key 的 handle 只会 被处理一次;跨实例的互斥由 Claim 背后的 DB 唯一约束保证。
func NewPushPipeline ¶ added in v1.4.9
func NewPushPipeline() *PushPipeline
NewPushPipeline 返回一个空的 PushPipeline。
func (*PushPipeline) Run ¶ added in v1.4.9
func (p *PushPipeline) Run(handles []ClaimHandle)
Run 依次处理 handles。单个 handle 的失败不影响其余 handle。