utils

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 License: AGPL-3.0 Imports: 30 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToUInt32 added in v0.3.0

func BytesToUInt32(b []byte) uint32

BytesToUInt32 bytes转换为uint32

func CallerPackageName

func CallerPackageName(skipPkgName string) string

func DeleteStringInSlice added in v0.1.0

func DeleteStringInSlice(slice []string, str ...string) []string

DeleteStringInSlice 删除字符串切片中的str元素,并去重

func DirExists

func DirExists(path string) bool

DirExists 判断文件夹是否存在(若为文件,仍返回false)

func FileExists

func FileExists(path string) bool

FileExists 判断文件是否存在(若为文件夹,仍返回false)

func FormSetByStrings

func FormSetByStrings(slices ...[]string) map[string]struct{}

FormSetByStrings 将字符串切片形成Set

func GetArgs

func GetArgs(ctx *zero.Ctx) string

GetArgs 获取参数

func GetBotConfig

func GetBotConfig() zero.Config

GetBotConfig 获取机器人配置

func GetBotCtx

func GetBotCtx() *zero.Ctx

GetBotCtx 获取一个全局ctx

func GetBotID added in v0.2.2

func GetBotID() int64

GetBotID 获取机器人的登录ID

func GetBotNickname

func GetBotNickname() string

GetBotNickname 获取机器人昵称

func GetCommand added in v0.1.0

func GetCommand(ctx *zero.Ctx) string

GetCommand 获取命令

func GetConfirm added in v0.3.1

func GetConfirm(tip string, ctx *zero.Ctx) bool

GetConfirm 发送tip并获取用户确认消息,为true代表用户确定

func GetImageFileMsg added in v0.1.0

func GetImageFileMsg(file string) (message.MessageSegment, error)

GetImageFileMsg 将本地图片文件自动转换为CQ码消息

func GetImageURL added in v0.1.0

func GetImageURL(msg message.MessageSegment) string

GetImageURL 通过消息获取其中的图片URL

func GetImageURLs added in v0.1.0

func GetImageURLs(e *zero.Event) (urls []string)

GetImageURLs 获取消息全部图片URL

func GetNeedStatistic added in v0.1.2

func GetNeedStatistic(ctx *zero.Ctx) bool

GetNeedStatistic 获取此次调用是否需要统计

func GetPkgNameByFunc

func GetPkgNameByFunc(fn interface{}) string

func GetQQAvatar

func GetQQAvatar(qq int64, size int) (io.ReadCloser, error)

GetQQAvatar 快捷获取QQ头像

func GetQQGroupAvatar

func GetQQGroupAvatar(id int64, size int) (io.ReadCloser, error)

GetQQGroupAvatar 快捷获取QQ群头像

func GetRegexpMatched added in v0.1.0

func GetRegexpMatched(ctx *zero.Ctx) []string

GetRegexpMatched 获取正则匹配字符串切片

func GoAndWait

func GoAndWait(handlers ...func() error) (err error)

func IsGroupAdmin added in v0.3.0

func IsGroupAdmin(ctx *zero.Ctx) bool

IsGroupAdmin 是否为群管消息

func IsGroupAnonymous added in v0.1.0

func IsGroupAnonymous(ctx *zero.Ctx) bool

IsGroupAnonymous 判断是否为群匿名消息

func IsLetter added in v0.1.0

func IsLetter(s string) bool

IsLetter 字符串是否为纯字母

func IsMessage added in v0.1.0

func IsMessage(ctx *zero.Ctx) bool

IsMessage 是否为消息事件

func IsMessageGroup added in v0.1.0

func IsMessageGroup(ctx *zero.Ctx) bool

IsMessageGroup 是否为群聊消息

func IsMessageGuild added in v0.1.0

func IsMessageGuild(ctx *zero.Ctx) bool

IsMessageGuild 是否为频道消息

func IsMessagePrimary

func IsMessagePrimary(ctx *zero.Ctx) bool

IsMessagePrimary 是否为私聊消息

func IsNumber added in v0.1.0

func IsNumber(s string) bool

IsNumber 字符串是否为纯数字

func IsOneBotLocal added in v0.1.0

func IsOneBotLocal() (res bool)

IsOneBotLocal 判断OneBot(消息收发端)是否在本地

func IsSameFunc

func IsSameFunc(fnL, fnR interface{}) bool

func IsSuperUser

func IsSuperUser(userID int64) bool

IsSuperUser userID是否为超级用户

func JsonString added in v0.1.0

func JsonString(v interface{}) string

JsonString 将任意内容转换为Json字符串

func MakeDir

func MakeDir(path string) (string, error)

MakeDir 创建文件夹并返回文件夹绝对路径

func MakeDirWithMode

func MakeDirWithMode(path string, perm os.FileMode) (string, error)

MakeDirWithMode 依据文件夹权限创建文件夹并返回文件夹绝对路径

func MergeStringSlices

func MergeStringSlices(slices ...[]string) (res []string)

MergeStringSlices 合并多个字符串切片并去重、去除空字符串

func NewGormLogger

func NewGormLogger() *loggerGorm

func PathExists

func PathExists(path string) bool

PathExists 判断路径(包括文件与文件夹)是否存在

func PathJoin

func PathJoin(paths ...string) string

PathJoin 文件路径合并(并标准化)

func PathSize

func PathSize(path string) uint64

PathSize 获取指定路径文件大小,若路径为文件夹,可能会导致效率较低

func RemovePath

func RemovePath(path string) error

RemovePath 删除指定路径文件或目录

func SendToSuper

func SendToSuper(message ...message.MessageSegment)

SendToSuper 将消息发送给所有后端的所有超级用户

func SetNotStatistic added in v0.1.2

func SetNotStatistic(ctx *zero.Ctx)

SetNotStatistic 设置此次调用不统计

func SplitOnSpace added in v0.1.3

func SplitOnSpace(x string) []string

SplitOnSpace 按文字、空格、文字...分隔字符串

func StringLimit added in v0.2.4

func StringLimit(s string, limit int) string

StringLimit 限制字符串长度,若超出limit,返回前limit个码点+"..."

func StringRealLength added in v0.1.0

func StringRealLength(s string) int

StringRealLength 计算字符串的真实长度

func StringSliceContain added in v0.1.0

func StringSliceContain(slices []string, substr string) bool

StringSliceContain 字符串切片中是否含有指定字符串

func UInt32ToBytes added in v0.3.0

func UInt32ToBytes(n uint32) []byte

UInt32ToBytes uint32转换为bytes

func WaitNextMessage added in v0.1.0

func WaitNextMessage(ctx *zero.Ctx) *zero.Event

WaitNextMessage 等待相同用户的下一条消息,若返回nil,代表超时(5分钟)

Types

type LoggerCron

type LoggerCron struct{}

func NewCronLogger

func NewCronLogger() *LoggerCron

func (*LoggerCron) Error

func (l *LoggerCron) Error(err error, msg string, keysAndValues ...interface{})

func (*LoggerCron) Info

func (l *LoggerCron) Info(msg string, keysAndValues ...interface{})

type SimpleFormatter added in v0.1.0

type SimpleFormatter struct{}

func (SimpleFormatter) Format added in v0.1.0

func (f SimpleFormatter) Format(entry *log.Entry) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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