mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-17 05:33:42 +08:00
🔖 chore: Rename relay/util to relay/relay_util package and add utils package
This commit is contained in:
@@ -2,6 +2,7 @@ package telegram
|
||||
|
||||
import (
|
||||
"one-api/common"
|
||||
"one-api/common/utils"
|
||||
"strings"
|
||||
|
||||
"github.com/PaulSonOfLars/gotgbot/v2"
|
||||
@@ -15,7 +16,7 @@ func commandAffStart(b *gotgbot.Bot, ctx *ext.Context) error {
|
||||
}
|
||||
|
||||
if user.AffCode == "" {
|
||||
user.AffCode = common.GetRandomString(4)
|
||||
user.AffCode = utils.GetRandomString(4)
|
||||
if err := user.Update(false); err != nil {
|
||||
ctx.EffectiveMessage.Reply(b, "系统错误,请稍后再试", nil)
|
||||
return nil
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"one-api/common"
|
||||
@@ -243,22 +245,16 @@ func getHttpClient() (httpClient *http.Client) {
|
||||
},
|
||||
}
|
||||
case "socks5":
|
||||
var auth *proxy.Auth = nil
|
||||
password, isSetPassword := proxyURL.User.Password()
|
||||
if isSetPassword {
|
||||
auth = &proxy.Auth{
|
||||
User: proxyURL.User.Username(),
|
||||
Password: password,
|
||||
}
|
||||
}
|
||||
dialer, err := proxy.SOCKS5("tcp", proxyURL.Host, auth, proxy.Direct)
|
||||
dialer, err := proxy.FromURL(proxyURL, proxy.Direct)
|
||||
if err != nil {
|
||||
common.SysLog("failed to create TG SOCKS5 dialer: " + err.Error())
|
||||
return
|
||||
}
|
||||
httpClient = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Dial: dialer.Dial,
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return dialer.(proxy.ContextDialer).DialContext(ctx, network, addr)
|
||||
},
|
||||
},
|
||||
}
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user