handler

package
v1.4.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCacheDuration = 10 * time.Minute

Variables

This section is empty.

Functions

func DebugHandler added in v1.4.2

func DebugHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func HelpText added in v1.4.9

func HelpText() string

HelpText generates the /start help message from the command registry.

func MeHandler

func MeHandler(ctx context.Context, b *bot.Bot, update *models.Update)

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 (c *CommandsHandler) AddAlarmKeywordHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) AddKeywordHandler

func (c *CommandsHandler) AddKeywordHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) AlarmRecordHandler added in v1.4.2

func (c *CommandsHandler) AlarmRecordHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) ConvertURLToIMGHandler added in v1.4.1

func (c *CommandsHandler) ConvertURLToIMGHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) ConvertURLToPDFHandler added in v1.3.0

func (c *CommandsHandler) ConvertURLToPDFHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) DeleteKeywordHandler

func (c *CommandsHandler) DeleteKeywordHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) EditKeywordHandler added in v1.4.0

func (c *CommandsHandler) EditKeywordHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) HandleCallbackQuery added in v1.3.0

func (c *CommandsHandler) HandleCallbackQuery(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) ListTodayHandler added in v1.4.7

func (c *CommandsHandler) ListTodayHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) SearchAlarmRecordHandler added in v1.4.2

func (c *CommandsHandler) SearchAlarmRecordHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) SearchHistoryHandler added in v1.3.0

func (c *CommandsHandler) SearchHistoryHandler(ctx context.Context, b *bot.Bot, update *models.Update)

func (*CommandsHandler) StaticHandler added in v1.4.0

func (c *CommandsHandler) StaticHandler(ctx context.Context, b *bot.Bot, update *models.Update)

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

func (*Crawler) Alarms added in v1.4.1

func (c *Crawler) Alarms(keywords []string, userId int64) []*model.Alarm

func (*Crawler) Projects added in v1.4.1

func (c *Crawler) Projects() []*Project

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)

func (*GotenbergClient) URLToPDF added in v1.4.1

func (g *GotenbergClient) URLToPDF(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()

func (*InfoProcessor) ToMessage added in v1.4.2

func (r *InfoProcessor) ToMessage(project *Project) ([]string, int)

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.

func (*KeyedLock) TryLock added in v1.4.9

func (l *KeyedLock) TryLock(key string) bool

TryLock marks key as held and reports whether the caller acquired it. A second concurrent TryLock for the same key returns false.

func (*KeyedLock) Unlock added in v1.4.9

func (l *KeyedLock) Unlock(key string)

Unlock releases a previously acquired key. It is safe to call for a key that is not held (no-op).

type ManagerHandler

type ManagerHandler struct {
	// contains filtered or unexported fields
}

func NewManagerHandler

func NewManagerHandler(ctx *BotContext) *ManagerHandler

func (*ManagerHandler) Clean added in v1.1.0

func (h *ManagerHandler) Clean(ctx context.Context, b *bot.Bot, update *models.Update)

func (*ManagerHandler) Retry

func (h *ManagerHandler) Retry(ctx context.Context, b *bot.Bot, update *models.Update)

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

func (p *Project) SplitMessage() ([]string, int)

func (*Project) ToMessage added in v1.4.2

func (p *Project) ToMessage() string

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

func (*Projects) Filter added in v1.4.2

func (r *Projects) Filter() []*Project

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。

type Store added in v1.4.1

type Store struct {
	// contains filtered or unexported fields
}

func NewStore added in v1.4.1

func NewStore() *Store

func (*Store) Delete added in v1.4.1

func (s *Store) Delete(key string)

func (*Store) Get added in v1.4.1

func (s *Store) Get(key string) (interface{}, bool)

func (*Store) Set added in v1.4.1

func (s *Store) Set(key string, value interface{}, duration time.Duration)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL