utility

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: 48 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	COSSecretID        = os.Getenv("COS_SECRET_ID")
	COSSecretKey       = os.Getenv("COS_SECRET_KEY")
	COSBaseURL         = os.Getenv("COS_BASE_URL")
	COSBucketRegionURL = os.Getenv("COS_BUCKET_REGION_URL")
)

var cosBucket = "kevinmatt-1303917904"

View Source
var MCounter = prometheus.NewHistogramVec(prometheus.HistogramOpts{
	Name:        "func_time_cost_seconds",
	ConstLabels: map[string]string{},
	Buckets:     []float64{},
}, []string{"func_name"})
View Source
var MicrosoftYaHei *truetype.Font

MicrosoftYaHei 字体类型,未来荧黑

Functions

func AddressORNil added in v1.0.2

func AddressORNil[P any, T *P](input T) P

func BuildCardMessage added in v1.0.2

func BuildCardMessage(theme, size, title, quoteID string, span any, modules ...any) (cardMessageStr string, err error)

BuildCardMessage 1

@return string

func BuildCardMessageCols added in v0.0.5

func BuildCardMessageCols(titleK, titleV string, kvMap map[string]any) (res []any, err error)

BuildCardMessageCols 创建卡片消息的列

func BuildURL added in v1.0.2

func BuildURL(jsonURL string) string

func CollectPanic added in v1.0.2

func CollectPanic(ctx context.Context, kookCtx interface{}, TargetID, QuoteID, UserID string)

CollectPanic is the function to collect panic

func EpoMil2DateStr added in v1.0.2

func EpoMil2DateStr(epoMil string) string

func ExtractLyrics added in v1.0.2

func ExtractLyrics(lyric string) (s string, err error)

func ForDebug

func ForDebug(test ...any)

ForDebug 用于测试

func ForceMarshalJSON added in v1.0.2

func ForceMarshalJSON(v interface{}) string

ForceMarshalJSON is the function to force marshal json

@param v
@return string

func GenerateTraceButton added in v1.0.2

func GenerateTraceButton(traceInfo string) (b kook.CardMessageElementButton)

func GenerateTraceButtonSection added in v1.0.2

func GenerateTraceButtonSection(traceInfo string) kook.CardMessageSection

func GetChannnelInfo added in v0.0.5

func GetChannnelInfo(channelID string) (channelInfo *kook.Channel, err error)

GetChannnelInfo 获取频道信息

@param channelID
@return channelInfo
@return err

func GetCommandWithParameters added in v1.0.1

func GetCommandWithParameters(rawCommand string) (command string, params []string)

GetCommandWithParameters 获取命令及参数

@param rawCommand
@return command
@return params

func GetCurrentFunc added in v1.0.2

func GetCurrentFunc() string

GetCurrentFunc 1

@return string

func GetCurrentTime

func GetCurrentTime() (localTime string)

GetCurrentTime 获取当前时间

func GetEnvWithDefault added in v1.0.2

func GetEnvWithDefault(envStr, defaultValue string) string

func GetFileMD5 added in v1.0.2

func GetFileMD5(reader io.Reader) (string, error)

func GetFuncFromInstance added in v1.0.2

func GetFuncFromInstance(ctxFunc any) string

GetFuncFromInstance 1

@return string

func GetGuildIDFromChannelID added in v1.0.2

func GetGuildIDFromChannelID(channelID string) (GuildID string)

GetGuildIDFromChannelID 通过ChannelID获取GuildID

@param channelID
@return GuildID

func GetGuildInfo added in v0.0.5

func GetGuildInfo(guildID string) (guildInfo *kook.Guild, err error)

GetGuildInfo 获取公会信息

@param guildID
@return guildInfo
@return err

func GetIpv4 added in v1.0.2

func GetIpv4() (ip string, err error)

func GetIpv6 added in v1.0.2

func GetIpv6() (ip string, err error)

func GetOutBoundIP

func GetOutBoundIP() (ip string, err error)

GetOutBoundIP 获取机器人部署的当前ip

func GetPubIP added in v1.0.2

func GetPubIP() (ipv4, ipv6 string, err error)

GetPubIP 获取公网ip

@return ip
@return err

func GetReceieverEmailList added in v1.0.2

func GetReceieverEmailList(dbConn *gorm.DB)

GetReceieverEmailList is the function to get recevier email list

func GetTimeCost added in v1.0.2

func GetTimeCost(startTime time.Time, function string)

GetTimeCost 获取耗时

@param startTime

func GetUserInfo added in v0.0.5

func GetUserInfo(userID, guildID string) (userInfo *kook.User, err error)

GetUserInfo 获取用户信息

@param userID
@param guildID
@return userInfo

func InSlice added in v1.0.2

func InSlice[T comparable](slice []T, tgt T) bool

func InitGlowSansSCFontType added in v1.0.1

func InitGlowSansSCFontType()

InitGlowSansSCFontType 初始化字体类型

func IsInSlice

func IsInSlice(target string, slice []string) bool

IsInSlice 判断机器人是否被at到

@param target
@param slice
@return bool

func MustAtoI added in v0.0.5

func MustAtoI(str string) int

MustAtoI 将字符串转换为int

@param str
@return int

func MustMashal added in v1.0.2

func MustMashal(input any) string

func MustUnmarshallString added in v1.0.2

func MustUnmarshallString[T any](s string) *T

func Probability added in v1.0.2

func Probability(p float64) bool

Probability returns true with the given probability p (0.0 to 1.0).

func Reconnect added in v1.0.2

func Reconnect() (err error)

Reconnect 重建链接

func RegexpMatch added in v1.0.2

func RegexpMatch(str, pattern string) bool

func RemovePostStyle added in v1.0.2

func RemovePostStyle(content string) (res string)

func ResizeIMGFromReader added in v1.0.2

func ResizeIMGFromReader(ctx context.Context, r io.ReadCloser) (output []byte)

func RunFuncName added in v1.0.2

func RunFuncName() string

func SampleSlice added in v1.0.2

func SampleSlice[T any](slices []T) T

func SendEmail added in v1.0.2

func SendEmail(Subject string, Body string)

SendEmail is the function to send email

func SendErrorMessageWithTitle added in v1.0.2

func SendErrorMessageWithTitle(targetID, QuoteID, authorID, message, title string, ctx context.Context)

SendErrorMessageWithTitle 发送消息

@param targetID 目标ID
@param QuoteID 引用ID
@param authorID 作者ID
@param message

func SendMessage added in v1.0.1

func SendMessage(targetID, QuoteID, authorID string, message string)

SendMessage 发送消息

@param targetID 目标ID
@param QuoteID 引用ID
@param authorID 作者ID
@param err 错误信息

func SendMessageTemp added in v1.0.1

func SendMessageTemp(targetID, QuoteID, authorID, newMsg string)

SendMessageTemp 发送消息

@param targetID 目标ID
@param QuoteID 引用ID
@param authorID 作者ID
@param err 错误信息

func SendMessageTempAndDelete added in v1.0.2

func SendMessageTempAndDelete(targetID, QuoteID, authorID, newMsg string)

SendMessageTempAndDelete 1

@param targetID
@param QuoteID
@param authorID
@param message

func SendMessageWithTitle added in v1.0.2

func SendMessageWithTitle(targetID, QuoteID, authorID, message, title string, ctx context.Context) (msgID string)

func SendQRCodeMail added in v1.0.2

func SendQRCodeMail(qrimg string) error

SendQRCodeMail is the function to send QRCode mail

@param qrimg
@return error

func Struct2Map added in v0.0.5

func Struct2Map(obj any) map[string]any

Struct2Map 将结构体转换为map

@param obj
@return map

func UnmarshallString added in v1.0.2

func UnmarshallString[T any](s string) (*T, error)

func UnmarshallStringPre added in v1.0.2

func UnmarshallStringPre[T any](s string, val *T) error

func UploadFileToCos added in v1.0.1

func UploadFileToCos(filePath string) (linkURL string, err error)

UploadFileToCos 将文件上传到cos

Types

type ErrorCollector added in v1.0.1

type ErrorCollector []*error

*ErrorCollector is a function that collects errors and returns the collected errors.

func (*ErrorCollector) CheckError added in v1.0.2

func (ec *ErrorCollector) CheckError() error

CheckError is a wrapper for the error type that implements the *ErrorCollector interface.

@receiver ec
@return error

func (*ErrorCollector) Collect added in v1.0.1

func (ec *ErrorCollector) Collect(err error)

Collect adds an error to the collector.

@receiver ec
@param err

func (*ErrorCollector) Error added in v1.0.1

func (ec *ErrorCollector) Error() string

Error is a wrapper for the error type that implements the *ErrorCollector interface.

@receiver ec
@return string

func (*ErrorCollector) Errorf added in v1.0.1

func (ec *ErrorCollector) Errorf(format string, args ...interface{})

Errorf is a wrapper for the error type that implements the *ErrorCollector interface.

@receiver ec
@param format
@param args

func (*ErrorCollector) GenErr added in v1.0.1

func (ec *ErrorCollector) GenErr() error

GenErr is a wrapper for the error type that implements the *ErrorCollector interface.

@receiver ec
@return error

func (*ErrorCollector) NoError added in v1.0.1

func (ec *ErrorCollector) NoError() bool

NoError is a wrapper for the error type that implements the *ErrorCollector interface.

@receiver ec
@return bool

func (*ErrorCollector) String added in v1.0.1

func (ec *ErrorCollector) String() string

String is a wrapper for the string type that implements the *ErrorCollector interface.

@receiver ec
@return string

Jump to

Keyboard shortcuts

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