mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-06-19 14:05:03 +08:00
remove global/config.go
This commit is contained in:
parent
e4abf426bc
commit
a27848979d
@ -1091,10 +1091,11 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
|
|||||||
return maxImageSize
|
return maxImageSize
|
||||||
}()
|
}()
|
||||||
thread, _ := strconv.Atoi(c)
|
thread, _ := strconv.Atoi(c)
|
||||||
if global.PathExists(cacheFile) && cache == "1" {
|
exist := global.PathExists(cacheFile)
|
||||||
|
if exist && cache == "1" {
|
||||||
goto hasCacheFile
|
goto hasCacheFile
|
||||||
}
|
}
|
||||||
if global.PathExists(cacheFile) {
|
if exist {
|
||||||
_ = os.Remove(cacheFile)
|
_ = os.Remove(cacheFile)
|
||||||
}
|
}
|
||||||
if err := global.DownloadFileMultiThreading(f, cacheFile, maxSize, thread, nil); err != nil {
|
if err := global.DownloadFileMultiThreading(f, cacheFile, maxSize, thread, nil); err != nil {
|
||||||
@ -1153,22 +1154,25 @@ func (bot *CQBot) makeImageOrVideoElem(d map[string]string, video, group bool) (
|
|||||||
return &LocalVideoElement{File: rawPath}, nil
|
return &LocalVideoElement{File: rawPath}, nil
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(f, "base64") {
|
if strings.HasPrefix(f, "base64") {
|
||||||
b, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(f, "base64://", ""))
|
b, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(f, "base64://"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &LocalImageElement{Stream: bytes.NewReader(b)}, nil
|
return &LocalImageElement{Stream: bytes.NewReader(b)}, nil
|
||||||
}
|
}
|
||||||
if !global.PathExists(rawPath) && global.PathExists(path.Join(global.ImagePathOld, f)) {
|
exist := global.PathExists(rawPath)
|
||||||
|
if !exist && global.PathExists(path.Join(global.ImagePathOld, f)) {
|
||||||
|
exist = true
|
||||||
rawPath = path.Join(global.ImagePathOld, f)
|
rawPath = path.Join(global.ImagePathOld, f)
|
||||||
}
|
}
|
||||||
if !global.PathExists(rawPath) && global.PathExists(rawPath+".cqimg") {
|
if !exist && global.PathExists(rawPath+".cqimg") {
|
||||||
|
exist = true
|
||||||
rawPath += ".cqimg"
|
rawPath += ".cqimg"
|
||||||
}
|
}
|
||||||
if !global.PathExists(rawPath) && d["url"] != "" {
|
if !exist && d["url"] != "" {
|
||||||
return bot.makeImageOrVideoElem(map[string]string{"file": d["url"]}, false, group)
|
return bot.makeImageOrVideoElem(map[string]string{"file": d["url"]}, false, group)
|
||||||
}
|
}
|
||||||
if global.PathExists(rawPath) {
|
if exist {
|
||||||
file, err := os.Open(rawPath)
|
file, err := os.Open(rawPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
package global
|
|
||||||
|
|
||||||
// AccountToken 存储AccountToken供登录使用
|
|
||||||
var AccountToken []byte
|
|
||||||
|
|
||||||
// PasswordHash 存储QQ密码哈希供登录使用
|
|
||||||
var PasswordHash [16]byte
|
|
||||||
|
|
||||||
/*
|
|
||||||
// GetCurrentPath 预留,获取当前目录地址
|
|
||||||
func GetCurrentPath() (string, error) {
|
|
||||||
file, err := exec.LookPath(os.Args[0])
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
fpath, err := filepath.Abs(file)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
// fpath = strings.Replace(fpath, "\\", "/", -1)
|
|
||||||
fpath = strings.ReplaceAll(fpath, "\\", "/")
|
|
||||||
}
|
|
||||||
i := strings.LastIndex(fpath, "/")
|
|
||||||
if i < 0 {
|
|
||||||
return "", errors.New("system/path_error,Can't find '/' or '\\'")
|
|
||||||
}
|
|
||||||
return fpath[0 : i+1], nil
|
|
||||||
}
|
|
||||||
*/
|
|
@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@ -49,22 +48,14 @@ var (
|
|||||||
|
|
||||||
// GetBytes 对给定URL发送Get请求,返回响应主体
|
// GetBytes 对给定URL发送Get请求,返回响应主体
|
||||||
func GetBytes(url string) ([]byte, error) {
|
func GetBytes(url string) ([]byte, error) {
|
||||||
req, err := http.NewRequest("GET", url, nil)
|
reader, err := HTTPGetReadCloser(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.Header["User-Agent"] = []string{UserAgent}
|
defer func() {
|
||||||
resp, err := client.Do(req)
|
_ = reader.Close()
|
||||||
if err != nil {
|
}()
|
||||||
return nil, err
|
return ioutil.ReadAll(reader)
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
if strings.Contains(resp.Header.Get("Content-Encoding"), "gzip") {
|
|
||||||
r, _ := gzip.NewReader(resp.Body)
|
|
||||||
defer r.Close()
|
|
||||||
return ioutil.ReadAll(r)
|
|
||||||
}
|
|
||||||
return ioutil.ReadAll(resp.Body)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadFile 将给定URL对应的文件下载至给定Path
|
// DownloadFile 将给定URL对应的文件下载至给定Path
|
||||||
@ -311,7 +302,7 @@ func NewGzipReadCloser(reader io.ReadCloser) (io.ReadCloser, error) {
|
|||||||
|
|
||||||
// Read impls io.Reader
|
// Read impls io.Reader
|
||||||
func (g *gzipCloser) Read(p []byte) (n int, err error) {
|
func (g *gzipCloser) Read(p []byte) (n int, err error) {
|
||||||
return rand.Read(p)
|
return g.r.Read(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close impls io.Closer
|
// Close impls io.Closer
|
||||||
|
24
main.go
24
main.go
@ -42,6 +42,12 @@ var (
|
|||||||
d bool
|
d bool
|
||||||
h bool
|
h bool
|
||||||
|
|
||||||
|
// PasswordHash 存储QQ密码哈希供登录使用
|
||||||
|
PasswordHash [16]byte
|
||||||
|
|
||||||
|
// AccountToken 存储AccountToken供登录使用
|
||||||
|
AccountToken []byte
|
||||||
|
|
||||||
// 允许通过配置文件设置的状态列表
|
// 允许通过配置文件设置的状态列表
|
||||||
allowStatus = [...]client.UserOnlineStatus{
|
allowStatus = [...]client.UserOnlineStatus{
|
||||||
client.StatusOnline, client.StatusAway, client.StatusInvisible, client.StatusBusy,
|
client.StatusOnline, client.StatusAway, client.StatusInvisible, client.StatusBusy,
|
||||||
@ -174,8 +180,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Infof("密码加密已启用, 请输入Key对密码进行加密: (Enter 提交)")
|
log.Infof("密码加密已启用, 请输入Key对密码进行加密: (Enter 提交)")
|
||||||
byteKey, _ = term.ReadPassword(int(os.Stdin.Fd()))
|
byteKey, _ = term.ReadPassword(int(os.Stdin.Fd()))
|
||||||
global.PasswordHash = md5.Sum([]byte(conf.Account.Password))
|
PasswordHash = md5.Sum([]byte(conf.Account.Password))
|
||||||
_ = os.WriteFile("password.encrypt", []byte(PasswordHashEncrypt(global.PasswordHash[:], byteKey)), 0644)
|
_ = os.WriteFile("password.encrypt", []byte(PasswordHashEncrypt(PasswordHash[:], byteKey)), 0644)
|
||||||
log.Info("密码已加密,为了您的账号安全,请删除配置文件中的密码后重新启动.")
|
log.Info("密码已加密,为了您的账号安全,请删除配置文件中的密码后重新启动.")
|
||||||
readLine()
|
readLine()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
@ -212,10 +218,10 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("加密存储的密码损坏,请尝试重新配置密码")
|
log.Fatalf("加密存储的密码损坏,请尝试重新配置密码")
|
||||||
}
|
}
|
||||||
copy(global.PasswordHash[:], ph)
|
copy(PasswordHash[:], ph)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
global.PasswordHash = md5.Sum([]byte(conf.Account.Password))
|
PasswordHash = md5.Sum([]byte(conf.Account.Password))
|
||||||
}
|
}
|
||||||
if !isFastStart {
|
if !isFastStart {
|
||||||
log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.")
|
log.Info("Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消.")
|
||||||
@ -236,9 +242,9 @@ func main() {
|
|||||||
return "未知"
|
return "未知"
|
||||||
}())
|
}())
|
||||||
cli = client.NewClientEmpty()
|
cli = client.NewClientEmpty()
|
||||||
if conf.Account.Uin != 0 && global.PasswordHash != [16]byte{} {
|
if conf.Account.Uin != 0 && PasswordHash != [16]byte{} {
|
||||||
cli.Uin = conf.Account.Uin
|
cli.Uin = conf.Account.Uin
|
||||||
cli.PasswordMd5 = global.PasswordHash
|
cli.PasswordMd5 = PasswordHash
|
||||||
}
|
}
|
||||||
cli.OnLog(func(c *client.QQClient, e *client.LogEvent) {
|
cli.OnLog(func(c *client.QQClient, e *client.LogEvent) {
|
||||||
switch e.Type {
|
switch e.Type {
|
||||||
@ -270,8 +276,8 @@ func main() {
|
|||||||
isQRCodeLogin := (conf.Account.Uin == 0 || len(conf.Account.Password) == 0) && !conf.Account.Encrypt
|
isQRCodeLogin := (conf.Account.Uin == 0 || len(conf.Account.Password) == 0) && !conf.Account.Encrypt
|
||||||
isTokenLogin := false
|
isTokenLogin := false
|
||||||
saveToken := func() {
|
saveToken := func() {
|
||||||
global.AccountToken = cli.GenToken()
|
AccountToken = cli.GenToken()
|
||||||
_ = ioutil.WriteFile("session.token", global.AccountToken, 0677)
|
_ = ioutil.WriteFile("session.token", AccountToken, 0677)
|
||||||
}
|
}
|
||||||
if global.PathExists("session.token") {
|
if global.PathExists("session.token") {
|
||||||
token, err := ioutil.ReadFile("session.token")
|
token, err := ioutil.ReadFile("session.token")
|
||||||
@ -337,7 +343,7 @@ func main() {
|
|||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
log.Warnf("尝试重连...")
|
log.Warnf("尝试重连...")
|
||||||
err := cli.TokenLogin(global.AccountToken)
|
err := cli.TokenLogin(AccountToken)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
saveToken()
|
saveToken()
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user