global

package
v1.0.0-beta6 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2021 License: AGPL-3.0 Imports: 33 Imported by: 8

Documentation

Overview

Package global 包含文件下载,视频音频编码,本地文件缓存处理,消息过滤器,调用速率限制,gocq主配置等的相关函数与结构体

Index

Constants

View Source
const (
	// ImagePath go-cqhttp使用的图片缓存目录
	ImagePath = "data/images"
	// ImagePathOld 兼容旧版go-cqhttp使用的图片缓存目录
	ImagePathOld = "data/image"
	// VoicePath go-cqhttp使用的语音缓存目录
	VoicePath = "data/voices"
	// VoicePathOld 兼容旧版go-cqhttp使用的语音缓存目录
	VoicePathOld = "data/record"
	// VideoPath go-cqhttp使用的视频缓存目录
	VideoPath = "data/videos"
	// CachePath go-cqhttp使用的缓存目录
	CachePath = "data/cache"
)

Variables

View Source
var (
	// ErrSyntax Path语法错误时返回的错误
	ErrSyntax = errors.New("syntax error")
	// HeaderAmr AMR文件头
	HeaderAmr = []byte("#!AMR")
	// HeaderSilk Silkv3文件头
	HeaderSilk = []byte("\x02#!SILK_V3")
)
View Source
var (

	// Proxy 存储Config.proxy_rewrite,用于设置代理
	Proxy string

	// ErrOverSize 响应主体过大时返回此错误
	ErrOverSize = errors.New("oversize")

	// UserAgent HTTP请求时使用的UA
	UserAgent = "" /* 130-byte string literal not displayed */
)

Functions

func Check

func Check(err error, deleteSession bool)

Check 检测err是否为nil

func DelFile added in v0.9.27

func DelFile(path string) bool

DelFile 删除一个给定path,并返回删除结果

func DownloadFile added in v0.9.37

func DownloadFile(url, path string, limit int64, headers map[string]string) error

DownloadFile 将给定URL对应的文件下载至给定Path

func DownloadFileMultiThreading added in v0.9.37

func DownloadFileMultiThreading(url, path string, limit int64, threadCount int, headers map[string]string) error

DownloadFileMultiThreading 使用threadCount个线程将给定URL对应的文件下载至给定Path

func EncodeMP4 added in v0.9.38

func EncodeMP4(src string, dst string) error

EncodeMP4 将给定视频文件编码为MP4

func EncoderSilk added in v0.9.38

func EncoderSilk(data []byte) ([]byte, error)

EncoderSilk 将音频编码为Silk

func EnsureBool added in v0.9.20

func EnsureBool(p interface{}, defaultVal bool) bool

EnsureBool 判断给定的p是否可表示为合法Bool类型,否则返回defaultVal

支持的合法类型有

type bool

type gjson.True or gjson.False

type string "true","yes","1" or "false","no","0" (case insensitive)

func ExtractCover added in v0.9.38

func ExtractCover(src string, target string) error

ExtractCover 获取给定视频文件的Cover

func FindFile added in v0.9.26

func FindFile(file, cache, p string) (data []byte, err error)

FindFile 从给定的File寻找文件,并返回文件byte数组。File是一个合法的URL。p为文件寻找位置。 对于HTTP/HTTPS形式的URL,Cache为"1"或空时表示启用缓存

func GetBytes

func GetBytes(url string) ([]byte, error)

GetBytes 对给定URL发送Get请求,返回响应主体

func GetLogLevel added in v0.9.40

func GetLogLevel(level string) []logrus.Level

GetLogLevel 获取日志等级

可能的值有

"trace","debug","info","warn","warn","error"

func GetSliderTicket added in v0.9.37

func GetSliderTicket(raw, id string) (string, error)

GetSliderTicket 通过给定的验证链接raw和id,获取验证结果Ticket

func HTTPGetReadCloser

func HTTPGetReadCloser(url string) (io.ReadCloser, error)

HTTPGetReadCloser 从 Http url 获取 io.ReadCloser

func IsAMRorSILK added in v0.9.20

func IsAMRorSILK(b []byte) bool

IsAMRorSILK 判断给定文件是否为Amr或Silk格式

func NeteaseMusicSongInfo added in v0.9.22

func NeteaseMusicSongInfo(id string) (gjson.Result, error)

NeteaseMusicSongInfo 通过给定id在wdd音乐上查找曲目信息

func NewBuffer added in v1.0.0

func NewBuffer() *bytes.Buffer

NewBuffer 从池中获取新 bytes.Buffer

func NewGzipReadCloser

func NewGzipReadCloser(reader io.ReadCloser) (io.ReadCloser, error)

NewGzipReadCloser 从 io.ReadCloser 创建 gunzip io.ReadCloser

func PathExists

func PathExists(path string) bool

PathExists 判断给定path是否存在

func PutBuffer added in v1.0.0

func PutBuffer(buf *bytes.Buffer)

PutBuffer 将 Buffer放入池中

func QQMusicSongInfo added in v0.9.21

func QQMusicSongInfo(id string) (gjson.Result, error)

QQMusicSongInfo 通过给定id在QQ音乐上查找曲目信息

func ReadAddrFile added in v0.9.31

func ReadAddrFile(path string) []*net.TCPAddr

ReadAddrFile 从给定path中读取合法的IP地址与端口,每个IP地址以换行符"\n"作为分隔

func ReadAllText

func ReadAllText(path string) string

ReadAllText 读取给定path对应文件,无法读取时返回空值

func SetAtDefault

func SetAtDefault(variable, value, defaultValue interface{})

SetAtDefault 在变量 variable 为默认值 defaultValue 的时候修改为 value

func SetExcludeDefault

func SetExcludeDefault(variable, value, defaultValue interface{})

SetExcludeDefault 在目标值 value 不为默认值 defaultValue 时修改 variable 为 value

func SetupMainSignalHandler added in v1.0.0

func SetupMainSignalHandler() <-chan struct{}

SetupMainSignalHandler is for main to use at last

func SplitURL added in v0.9.39

func SplitURL(s string) []string

SplitURL 将给定URL字符串分割为两部分,用于URL预处理防止风控

func VersionNameCompare added in v0.9.30

func VersionNameCompare(current, remote string) bool

VersionNameCompare 检查版本名是否需要更新, 仅适用于 go-cqhttp 的版本命名规则

例: v0.9.29-fix2 == v0.9.29-fix2 -> false

v0.9.29-fix1 < v0.9.29-fix2 -> true

v0.9.29-fix2 > v0.9.29-fix1 -> false

v0.9.29-fix2 < v0.9.30 -> true

v1.0.0-alpha2 < v1.0.0-beta1 -> true

v1.0.0 > v1.0.0-beta1 -> false

func WriteAllText

func WriteAllText(path, text string) error

WriteAllText 将给定text写入给定path

Types

type Filter added in v0.9.21

type Filter interface {
	Eval(payload gjson.Result) bool
}

Filter 定义了一个消息上报过滤接口

func Generate added in v0.9.25

func Generate(opName string, argument gjson.Result) Filter

Generate 根据给定操作符名opName及操作符参数argument创建一个过滤器实例

type LocalHook added in v0.9.40

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

LocalHook logrus本地钩子

func NewLocalHook added in v0.9.40

func NewLocalHook(args interface{}, formatter logrus.Formatter, levels ...logrus.Level) *LocalHook

NewLocalHook 初始化本地日志钩子实现

func (*LocalHook) Fire added in v0.9.40

func (hook *LocalHook) Fire(entry *logrus.Entry) error

Fire ref: logrus/hooks.go impl Hook interface

func (*LocalHook) Levels added in v0.9.40

func (hook *LocalHook) Levels() []logrus.Level

Levels ref: logrus/hooks.go impl Hook interface

func (*LocalHook) SetFormatter added in v0.9.40

func (hook *LocalHook) SetFormatter(formatter logrus.Formatter)

SetFormatter 设置日志格式

func (*LocalHook) SetPath added in v0.9.40

func (hook *LocalHook) SetPath(path string)

SetPath 设置日志写入路径

func (*LocalHook) SetWriter added in v0.9.40

func (hook *LocalHook) SetWriter(writer io.Writer)

SetWriter 设置Writer

type LogFormat added in v1.0.0

type LogFormat struct{}

LogFormat specialize for go-cqhttp

func (LogFormat) Format added in v1.0.0

func (f LogFormat) Format(entry *logrus.Entry) ([]byte, error)

Format implements logrus.Formatter

Directories

Path Synopsis
Package codec Slik编码核心模块
Package codec Slik编码核心模块
Package config 包含go-cqhttp操作配置文件的相关函数
Package config 包含go-cqhttp操作配置文件的相关函数
Package terminal 包含用于检测在windows下是否通过双击运行go-cqhttp的函数
Package terminal 包含用于检测在windows下是否通过双击运行go-cqhttp的函数
Package update 包含go-cqhttp自我更新相关函数
Package update 包含go-cqhttp自我更新相关函数

Jump to

Keyboard shortcuts

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