larkutils

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 30, 2025 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FourColSheetTemplate         = database.TemplateVersion{TemplateID: "AAq0LWXpn9FbS"}
	ThreeColSheetTemplate        = database.TemplateVersion{TemplateID: "AAq0LIyUeFhNX"}
	TwoColSheetTemplate          = database.TemplateVersion{TemplateID: "AAq0LPliGGphg"}
	TwoColPicTemplate            = database.TemplateVersion{TemplateID: "AAq0LPJqOoh3s"}
	AlbumListTemplate            = database.TemplateVersion{TemplateID: "AAqdqaEBaxJaf"}
	SingleSongDetailTemplate     = database.TemplateVersion{TemplateID: "AAqdrtjg8g1s8"}
	FullLyricsTemplate           = database.TemplateVersion{TemplateID: "AAq3mcb9ivduh"}
	StreamingReasonTemplate      = database.TemplateVersion{TemplateID: "ONLY_SRC_STERAMING_CARD"}
	NormalCardReplyTemplate      = database.TemplateVersion{TemplateID: "AAqRQtNPSJbsZ"}
	NormalCardGraphReplyTemplate = database.TemplateVersion{TemplateID: "AAqdmx3wt8mit"}
)
View Source
var (
	BotOpenID             = "ou_8817f540f718affd21718f415b81597f"
	BotAppID              = "cli_a570c2871fe3500e"
	FullLyricsCardPattern = `` /* 4127-byte string literal not displayed */

	MusicCardPattern = `` /* 5460-byte string literal not displayed */

)

Functions

func AddReaction

func AddReaction(ctx context.Context, reactionType, msgID string) (reactionID string, err error)

func AddReaction2DB

func AddReaction2DB(ctx context.Context, msgID string)

func AddReactionAsync

func AddReactionAsync(ctx context.Context, reactionType, msgID string) (err error)

func CheckFunctionEnabling

func CheckFunctionEnabling(chatID string, function consts.LarkFunctionEnum) bool

func CreateMsgText

func CreateMsgText(ctx context.Context, content, msgID, chatID string) (err error)

CreateMsgText 不需要自行BuildText

func CreateMsgTextRaw

func CreateMsgTextRaw(ctx context.Context, content, msgID, chatID string) (err error)

CreateMsgTextRaw 需要自行BuildText

func DownImgFromMsgAsync

func DownImgFromMsgAsync(ctx context.Context, msgID, fileType, fileKey string) (err error)

DownImgFromMsgAsync 从Msg中下载附件

@param ctx context.Context
@param msgID string
@param fileKey string
@param fileType string
@return image []byte
@return err error
@author kevinmatthe
@update 2025-04-27 20:15:38

func DownImgFromMsgSync

func DownImgFromMsgSync(ctx context.Context, msgID, fileType, fileKey string) (url string, err error)

DownImgFromMsgSync 从Msg中下载附件

@param ctx context.Context
@param msgID string
@param fileKey string
@param fileType string
@return image []byte
@return err error
@author kevinmatthe
@update 2025-04-27 20:15:38

func GenFullLyricsCard

func GenFullLyricsCard(ctx context.Context, title, artist, leftLyrics, rightLyrics string) string

func GenUUIDStr

func GenUUIDStr(str string, length int) string

func GenerateMusicCard

func GenerateMusicCard(imgKey, title, artist, playURL, lyrics string) string

func GenerateMusicCardByStruct

func GenerateMusicCardByStruct(ctx context.Context, imgKey, title, artist, playURL, lyrics, musicID string) string

func GetAllImageFromMsgEvent

func GetAllImageFromMsgEvent(ctx context.Context, message *larkim.EventMessage) (imageKeys iter.Seq[string], err error)

GetAllImageFromMsgEvent 从消息事件中获取所有图片

@param event *larkim.P2MessageReceiveV1
@author kevinmatthe
@update 2025-04-28 19:47:21

func GetAllImgTagFromMsg

func GetAllImgTagFromMsg(ctx context.Context, message *larkim.Message) (imageKeys iter.Seq[string], err error)

GetAllImgTagFromMsg 从消息事件中获取所有图片

@param event *larkim.P2MessageReceiveV1
@author kevinmatthe
@update 2025-04-28 19:47:21

func GetAllImgURLFromMsg

func GetAllImgURLFromMsg(ctx context.Context, msgID string) (iter.Seq[string], error)

func GetAllImgURLFromParent

func GetAllImgURLFromParent(ctx context.Context, data *larkim.P2MessageReceiveV1) (iter.Seq[string], error)

func GetAndResizePicFromURL

func GetAndResizePicFromURL(ctx context.Context, imageURL string) (res []byte, err error)

func GetChatIDFromMsgID

func GetChatIDFromMsgID(ctx context.Context, msgID string) (chatID string, err error)

func GetChatName

func GetChatName(ctx context.Context, chatID string) (chatName string)

func GetCommand

func GetCommand(ctx context.Context, content string) (commands []string)

func GetCommandWithMatched

func GetCommandWithMatched(ctx context.Context, content string) (commands []string, isCommand bool)

func GetMsgByID

func GetMsgByID(ctx context.Context, msgID string) string

func GetMsgFullByID

func GetMsgFullByID(ctx context.Context, msgID string) *larkim.GetMessageResp

func GetMsgImages

func GetMsgImages(ctx context.Context, msgID, fileKey, fileType string) (file io.Reader, err error)

func GetRandomEmoji

func GetRandomEmoji() string

func GetTenantAccessToken

func GetTenantAccessToken(ctx context.Context) string

func GetUserMapFromChatID

func GetUserMapFromChatID(ctx context.Context, chatID string) (memberMap map[string]*larkim.ListMember, err error)

func GetUserMemberFromChat

func GetUserMemberFromChat(ctx context.Context, chatID, openID string) (member *larkim.ListMember, err error)

func IsCommand

func IsCommand(ctx context.Context, content string) bool

func IsMentioned

func IsMentioned(mentions []*larkim.MentionEvent) bool

func PreGetTextMsg

func PreGetTextMsg(ctx context.Context, event *larkim.P2MessageReceiveV1) string

PreGetTextMsg 获取消息内容

@param ctx
@param event
@return string

func ReBuildArgs

func ReBuildArgs(argName, argValue string) string

func RecordMessage2Opensearch

func RecordMessage2Opensearch(ctx context.Context, resp *larkim.CreateMessageResp, contents ...string)

func RecordReplyMessage2Opensearch

func RecordReplyMessage2Opensearch(ctx context.Context, resp *larkim.ReplyMessageResp, contents ...string)

func RecoverMsg

func RecoverMsg(ctx context.Context, msgID string)

func RecoverMsgEvent

func RecoverMsgEvent(ctx context.Context, event *larkim.P2MessageReceiveV1)

func RemoveReaction

func RemoveReaction(ctx context.Context, reactionID, msgID string) (err error)

func ReplyCard

func ReplyCard(ctx context.Context, cardContent *TemplateCardContent, msgID, suffix string, replyInThread bool) (err error)

ReplyCard 注意:不要传入已经Build过的文本

@param ctx
@param text
@param msgID

func ReplyCardText

func ReplyCardText(ctx context.Context, text string, msgID, suffix string, replyInThread bool) (err error)

ReplyCardText 123

@param ctx
@param text
@param msgID

func ReplyCardTextGraph

func ReplyCardTextGraph(ctx context.Context, text string, graph any, msgID, suffix string, replyInThread bool) (err error)

ReplyCardTextGraph 123

@param ctx
@param text
@param msgID

func ReplyMsgRawContentType

func ReplyMsgRawContentType(ctx context.Context, msgID, msgType, content, suffix string, replyInThread bool) (resp *larkim.ReplyMessageResp, err error)

func ReplyMsgText

func ReplyMsgText(ctx context.Context, text, msgID, suffix string, replyInThread bool) (resp *larkim.ReplyMessageResp, err error)

ReplyMsgText ReplyMsgText 注意:不要传入已经Build过的文本

@param ctx
@param text
@param msgID

func SendEphemeral

func SendEphemeral(ctx context.Context, chatID, openID, card string)

func SendRecoveredMsg

func SendRecoveredMsg(ctx context.Context, err any, msgID string)

SendRecoveredMsg SendRecoveredMsg

@param ctx
@param msgID
@param err

func TrimAtMsg

func TrimAtMsg(ctx context.Context, msg string) string

TrimAtMsg trim掉at的消息

@param ctx context.Context
@param msg string
@return string
@author heyuhengmatt
@update 2024-07-17 01:39:05

func TrimLyrics

func TrimLyrics(lyrics string) string

func Upload2Lark

func Upload2Lark(ctx context.Context, musicID string, bodyReader io.ReadCloser) (imgKey string, err error)

func UploadPicAllinOne

func UploadPicAllinOne(ctx context.Context, imageURL, musicID string, uploadOSS bool) (key string, ossURL string, err error)

func UploadPicBatch

func UploadPicBatch(ctx context.Context, sourceURLIDs map[string]int) chan [2]string

func UploadPicture2Lark

func UploadPicture2Lark(ctx context.Context, URL string) (imgKey string)

func UploadPicture2LarkReader

func UploadPicture2LarkReader(ctx context.Context, picture io.Reader) (imgKey string)

Types

type CardData

type CardData struct {
	TemplateID          string                 `json:"template_id"`
	TemplateVersionName string                 `json:"template_version_name"`
	TemplateVariable    map[string]interface{} `json:"template_variable"`
	TemplateSrc         string                 `json:"template_src"`
}

type EphemeralCardReqBody

type EphemeralCardReqBody struct {
	ChatID  string      `json:"chat_id"`
	OpenID  string      `json:"open_id"`
	MsgType string      `json:"msg_type"`
	Card    interface{} `json:"card"`
}

type TemplateCardContent

type TemplateCardContent struct {
	Type string   `json:"type"` // must be template
	Data CardData `json:"data"`
}

func NewCardContent

func NewCardContent(ctx context.Context, template database.TemplateVersion) *TemplateCardContent

func (*TemplateCardContent) AddJaegerTraceInfo

func (c *TemplateCardContent) AddJaegerTraceInfo(traceID string) *TemplateCardContent

func (*TemplateCardContent) AddVariable

func (c *TemplateCardContent) AddVariable(key string, value interface{}) *TemplateCardContent

func (*TemplateCardContent) BuildTemplate

func (c *TemplateCardContent) BuildTemplate() string

func (*TemplateCardContent) GetVariables

func (c *TemplateCardContent) GetVariables() []string

func (*TemplateCardContent) String

func (c *TemplateCardContent) String() string

func (*TemplateCardContent) UpdateVariables

func (c *TemplateCardContent) UpdateVariables(m map[string]interface{}) *TemplateCardContent

type TemplateStru

type TemplateStru struct {
	TemplateID      string
	TemplateVersion string
}

type TextBuilder

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

func NewTextMsgBuilder

func NewTextMsgBuilder() *TextBuilder

func (*TextBuilder) AtUser

func (t *TextBuilder) AtUser(userId, name string) *TextBuilder

func (*TextBuilder) Build

func (t *TextBuilder) Build() string

func (*TextBuilder) Text

func (t *TextBuilder) Text(text string) *TextBuilder

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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