Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test4 #49

Merged
merged 100 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
fad0d50
Compiled main.go and pushed changes
Hoshinonyaruko Oct 23, 2023
fda2572
test
Hoshinonyaruko Oct 23, 2023
34cfac1
适配了频道私聊,用bolt数据库取代ini
Hoshinonyaruko Oct 23, 2023
7fc1f10
适配了nonebot2
Hoshinonyaruko Oct 24, 2023
28f9a73
Merge branch 'main' of https://github.com/Hoshinonyaruko/Gensokyo
Hoshinonyaruko Oct 24, 2023
9fadda4
适配私域
Hoshinonyaruko Oct 24, 2023
1336c6a
add license
Hoshinonyaruko Oct 24, 2023
b094949
add a lot
Hoshinonyaruko Oct 25, 2023
f4787f5
Resolved merge conflicts
Hoshinonyaruko Oct 25, 2023
86698c6
trss support
Hoshinonyaruko Oct 26, 2023
045f3e9
fix
Hoshinonyaruko Oct 26, 2023
618561c
add action
Hoshinonyaruko Oct 26, 2023
7e803aa
add action
Hoshinonyaruko Oct 26, 2023
ece4cef
add action
Hoshinonyaruko Oct 26, 2023
f864a50
fixbug
Hoshinonyaruko Oct 26, 2023
4564731
add wss
Hoshinonyaruko Oct 26, 2023
070e4df
merge
Hoshinonyaruko Oct 26, 2023
84e8fe9
bugfix
Hoshinonyaruko Oct 26, 2023
0e4fd50
fix action
Hoshinonyaruko Oct 26, 2023
fe2234a
fix action again
Hoshinonyaruko Oct 26, 2023
cf67a11
fix action againnn
Hoshinonyaruko Oct 26, 2023
0875837
fa
Hoshinonyaruko Oct 26, 2023
3a3c33f
fix
Hoshinonyaruko Oct 26, 2023
8789fa8
add a lot
Hoshinonyaruko Oct 27, 2023
7943466
add ws server token
Hoshinonyaruko Oct 28, 2023
4660983
merge
Hoshinonyaruko Oct 28, 2023
2a1026a
bugifx
Hoshinonyaruko Oct 28, 2023
4186970
fix
Hoshinonyaruko Oct 28, 2023
2f26828
fixat
Hoshinonyaruko Oct 28, 2023
007e1af
bugfix
Hoshinonyaruko Oct 28, 2023
c41fd77
bugfix
Hoshinonyaruko Oct 28, 2023
d8354b7
test
Hoshinonyaruko Oct 28, 2023
6e3c63c
test
Hoshinonyaruko Oct 28, 2023
f08d9d7
test2
Hoshinonyaruko Oct 28, 2023
4dd6e15
add url service
Hoshinonyaruko Oct 31, 2023
1f8c174
add url service
Hoshinonyaruko Oct 31, 2023
240f569
add url service
Hoshinonyaruko Oct 31, 2023
b191cb7
bugfix
Hoshinonyaruko Oct 31, 2023
42daab3
merge
Hoshinonyaruko Oct 31, 2023
8fec03f
fix
Hoshinonyaruko Oct 31, 2023
cca528b
fix
Hoshinonyaruko Oct 31, 2023
463a182
fix
Hoshinonyaruko Oct 31, 2023
e9187a1
bug fix
Hoshinonyaruko Nov 1, 2023
5ba2815
fix
Hoshinonyaruko Nov 1, 2023
c16e1af
fix
Hoshinonyaruko Nov 1, 2023
ec7863d
test
Hoshinonyaruko Nov 2, 2023
e8a7e73
ok
Hoshinonyaruko Nov 2, 2023
122d17d
add webui
Hoshinonyaruko Nov 2, 2023
4e9c209
merge
Hoshinonyaruko Nov 2, 2023
b502d61
add image_compress
Hoshinonyaruko Nov 3, 2023
3519e3e
merge
Hoshinonyaruko Nov 3, 2023
530ff96
bug fix
Hoshinonyaruko Nov 3, 2023
155a701
fix cq code
Hoshinonyaruko Nov 3, 2023
2f5ee4a
fixbug
Hoshinonyaruko Nov 3, 2023
afa03e3
bugfix
Hoshinonyaruko Nov 3, 2023
fdd1a73
merge
Hoshinonyaruko Nov 3, 2023
fe39cd2
bugfix
Hoshinonyaruko Nov 3, 2023
be08cbe
bugfix
Hoshinonyaruko Nov 3, 2023
931dfef
merge
Hoshinonyaruko Nov 3, 2023
73819c8
bugfix
Hoshinonyaruko Nov 3, 2023
b27f062
bugfix
Hoshinonyaruko Nov 3, 2023
1a94197
bugfix
Hoshinonyaruko Nov 3, 2023
745b28e
bugfix
Hoshinonyaruko Nov 3, 2023
1212c9a
bugfix
Hoshinonyaruko Nov 4, 2023
44d8669
bugfix
Hoshinonyaruko Nov 4, 2023
564aba5
add new feature
Hoshinonyaruko Nov 5, 2023
d7345c1
bugfix
Hoshinonyaruko Nov 5, 2023
472a224
bugfix
Hoshinonyaruko Nov 5, 2023
e22b58b
bugfix
Hoshinonyaruko Nov 5, 2023
22cb473
bugfix
Hoshinonyaruko Nov 5, 2023
e563929
bugfix
Hoshinonyaruko Nov 5, 2023
829b5d7
merge
Hoshinonyaruko Nov 5, 2023
b496ac1
bugfix
Hoshinonyaruko Nov 5, 2023
13e7700
bugfix
Hoshinonyaruko Nov 5, 2023
eb7e630
bugfix
Hoshinonyaruko Nov 5, 2023
32d490f
test
Hoshinonyaruko Nov 5, 2023
9815e3a
test
Hoshinonyaruko Nov 5, 2023
7747de6
test
Hoshinonyaruko Nov 5, 2023
fe2e4be
test
Hoshinonyaruko Nov 5, 2023
ec9e797
test
Hoshinonyaruko Nov 5, 2023
3548108
test
Hoshinonyaruko Nov 5, 2023
1e50a7c
test
Hoshinonyaruko Nov 5, 2023
812e6ea
test
Hoshinonyaruko Nov 5, 2023
76363a6
test
Hoshinonyaruko Nov 5, 2023
d8b05cd
test
Hoshinonyaruko Nov 5, 2023
c2e2b20
test
Hoshinonyaruko Nov 5, 2023
cefac16
test
Hoshinonyaruko Nov 5, 2023
273db15
test
Hoshinonyaruko Nov 5, 2023
5379f7d
test
Hoshinonyaruko Nov 5, 2023
56e2429
test
Hoshinonyaruko Nov 5, 2023
4466f30
test
Hoshinonyaruko Nov 6, 2023
a32a124
test
Hoshinonyaruko Nov 6, 2023
246d9c4
test
Hoshinonyaruko Nov 6, 2023
c91d9e2
test
Hoshinonyaruko Nov 6, 2023
6007979
bugfix
Hoshinonyaruko Nov 6, 2023
af64c33
bugfix
Hoshinonyaruko Nov 6, 2023
f5cfda3
Remove dist directory from tracking
Hoshinonyaruko Nov 6, 2023
53b6e5d
test
Hoshinonyaruko Nov 6, 2023
3991193
test
Hoshinonyaruko Nov 7, 2023
7af6759
bugfix2
Hoshinonyaruko Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
webui/dist/* linguist-generated=true
webui/dist/* linguist-generated=true
*.exe binary
10 changes: 5 additions & 5 deletions .github/workflows/cross_compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ jobs:
GITHUB_UPLOAD_URL="${GITHUB_UPLOAD_URL%\{*}"
GITHUB_UPLOAD_URL="${GITHUB_UPLOAD_URL%\?*}"
curl \
-X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: multipart/form-data" \
-F "file=@\"${file}\";name=${asset_name}" \
"${GITHUB_UPLOAD_URL}?name=${asset_name}&label=${asset_name}"
-X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/octet-stream" \
--data-binary @"${file}" \
"${GITHUB_UPLOAD_URL}?name=${asset_name}&label=${asset_name}"
else
echo "Expected a file in ${dir}, but found something else."
fi
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ config.yml
*.exe

# Ignore channel_temp
channel_temp/
channel_temp/

# ignore dist
webui/dist/
130 changes: 109 additions & 21 deletions botgo/token/authtoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"sync"
"time"

"github.com/hoshinonyaruko/gensokyo/config"
"github.com/tencent-connect/botgo/log"
)

Expand Down Expand Up @@ -127,9 +128,10 @@ type queryTokenReq struct {
ClientSecret string `json:"clientSecret"`
}

// 自定义地址返回需满足这个格式
type queryTokenRsp struct {
AccessToken string `json:"access_token"`
ExpiresIn string `json:"expires_in"`
AccessToken string `json:"access_token"`
ExpiresIn interface{} `json:"expires_in"` // 允许任何类型
}

// func queryAccessToken(ctx context.Context, tokenURL, appID, clientSecrent string) (AccessTokenInfo, error) {
Expand Down Expand Up @@ -191,48 +193,134 @@ type queryTokenRsp struct {
// return rdata, err
// }

// queryAccessToken retrieves a new AccessToken.
func queryAccessToken(ctx context.Context, tokenURL, appID, clientSecret string) (AccessTokenInfo, error) {
// 是否使用自定义ac地址
configURL := config.GetDevelop_Acdir()
if tokenURL == "" {
tokenURL = getAccessTokenURL // Assumes getAccessTokenURL is declared elsewhere
if configURL != "" {
tokenURL = configURL
} else {
tokenURL = getAccessTokenURL // 默认值
}
}

reqBody := queryTokenReq{
AppID: appID,
ClientSecret: clientSecret,
}
reqData, err := json.Marshal(reqBody)
if err != nil {
return AccessTokenInfo{}, err
}
var req *http.Request
var err error

req, err := http.NewRequestWithContext(ctx, http.MethodPost, tokenURL, bytes.NewReader(reqData))
if err != nil {
return AccessTokenInfo{}, err
//自定义地址使用get,无需参数
if configURL != "" {
req, err = http.NewRequestWithContext(ctx, http.MethodGet, configURL, nil)
} else {
// 默认ac地址使用post
reqBody := queryTokenReq{
AppID: appID,
ClientSecret: clientSecret,
}
reqData, err := json.Marshal(reqBody)
if err != nil {
return AccessTokenInfo{}, err
}

req, err = http.NewRequestWithContext(ctx, http.MethodPost, tokenURL, bytes.NewReader(reqData))
if err != nil {
return AccessTokenInfo{}, err
}
req.Header.Set("Content-Type", "application/json")
}
req.Header.Add("Content-Type", "application/json")

// Perform the HTTP request.
resp, err := http.DefaultClient.Do(req)
if err != nil {
return AccessTokenInfo{}, err
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
// Read the response body.
body, err := io.ReadAll(resp.Body)
if err != nil {
return AccessTokenInfo{}, err
}

var respData queryTokenRsp
if err := json.Unmarshal(body, &respData); err != nil {
if err = json.Unmarshal(body, &respData); err != nil {
return AccessTokenInfo{}, err
}

expiresIn, _ := strconv.ParseInt(respData.ExpiresIn, 10, 64) // Ignoring error can be dangerous, handle it as needed
// 自定义地址返回可能是string或者int
expiresInInt, err := parseExpiresIn(respData.ExpiresIn)
if err != nil {
return AccessTokenInfo{}, fmt.Errorf("expires_in is not a valid int or string: %v", err)
}

return AccessTokenInfo{
Token: respData.AccessToken,
ExpiresIn: expiresIn,
ExpiresIn: expiresInInt,
UpTime: time.Now(),
}, nil
}

func parseExpiresIn(expiresIn interface{}) (int64, error) {
switch v := expiresIn.(type) {
case float64:
// JSON numbers come as floats by default
return int64(v), nil
case int64:
// In case the JSON decoder was set to use integers
return v, nil
case json.Number:
// Convert json.Number to int64
return v.Int64()
case string:
// If the value is a string, try converting it to an integer
return strconv.ParseInt(v, 10, 64)
default:
// If none of the above types matched, return an error
return 0, fmt.Errorf("expires_in is not a valid type, got %T", expiresIn)
}
}

//原函数
// func queryAccessToken(ctx context.Context, tokenURL, appID, clientSecret string) (AccessTokenInfo, error) {
// if tokenURL == "" {
// tokenURL = getAccessTokenURL // Assumes getAccessTokenURL is declared elsewhere
// }

// reqBody := queryTokenReq{
// AppID: appID,
// ClientSecret: clientSecret,
// }
// reqData, err := json.Marshal(reqBody)
// if err != nil {
// return AccessTokenInfo{}, err
// }

// req, err := http.NewRequestWithContext(ctx, http.MethodPost, tokenURL, bytes.NewReader(reqData))
// if err != nil {
// return AccessTokenInfo{}, err
// }
// req.Header.Add("Content-Type", "application/json")

// resp, err := http.DefaultClient.Do(req)
// if err != nil {
// return AccessTokenInfo{}, err
// }
// defer resp.Body.Close()

// body, err := ioutil.ReadAll(resp.Body)
// if err != nil {
// return AccessTokenInfo{}, err
// }

// var respData queryTokenRsp
// if err := json.Unmarshal(body, &respData); err != nil {
// return AccessTokenInfo{}, err
// }

// expiresIn, _ := strconv.ParseInt(respData.ExpiresIn, 10, 64) // Ignoring error can be dangerous, handle it as needed

// return AccessTokenInfo{
// Token: respData.AccessToken,
// ExpiresIn: expiresIn,
// UpTime: time.Now(),
// }, nil
// }
39 changes: 39 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type Settings struct {
ImageLimit int `yaml:"image_sizelimit"`
RemovePrefix bool `yaml:"remove_prefix"`
BackupPort string `yaml:"backup_port"`
DevlopAcDir string `yaml:"develop_access_token_dir"`
RemoveAt bool `yaml:"remove_at"`
DevBotid string `yaml:"develop_bot_id"`
}

// LoadConfig 从文件中加载配置并初始化单例配置
Expand Down Expand Up @@ -348,6 +351,30 @@ func GetServer_dir() string {
return instance.Settings.Server_dir
}

// 获取DevBotid
func GetDevBotid() string {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to get DevBotid.")
return "1234"
}
return instance.Settings.DevBotid
}

// 获取Develop_Acdir服务的地址
func GetDevelop_Acdir() string {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to get DevlopAcDir.")
return ""
}
return instance.Settings.DevlopAcDir
}

// 获取lotus的值
func GetLotusValue() bool {
mu.Lock()
Expand All @@ -360,6 +387,18 @@ func GetLotusValue() bool {
return instance.Settings.Lotus
}

// 获取RemoveAt的值
func GetRemoveAt() bool {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to get RemoveAt value.")
return false
}
return instance.Settings.RemoveAt
}

// 获取port的值
func GetPortValue() string {
mu.Lock()
Expand Down
15 changes: 13 additions & 2 deletions handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func RevertTransformedText(data interface{}) string {
default:
return ""
}
//处理前 先去前后空
messageText := strings.TrimSpace(msg.Content)

// 将messageText里的BotID替换成AppID
Expand All @@ -232,9 +233,13 @@ func RevertTransformedText(data interface{}) string {
submatches := re.FindStringSubmatch(m)
if len(submatches) > 1 {
userID := submatches[1]
// 检查是否是 BotID,如果是则直接返回,不进行映射
// 检查是否是 BotID,如果是则直接返回,不进行映射,或根据用户需求移除
if userID == AppID {
return "[CQ:at,qq=" + AppID + "]"
if config.GetRemoveAt() {
return ""
} else {
return "[CQ:at,qq=" + AppID + "]"
}
}

// 不是 BotID,进行正常映射
Expand Down Expand Up @@ -271,6 +276,12 @@ func RevertTransformedText(data interface{}) string {
}
}

//如果移除了前部at,信息就会以空格开头,因为只移去了最前面的at,但at后紧跟随一个空格
if config.GetRemoveAt() {
//再次去前后空
messageText = strings.TrimSpace(messageText)
}

return messageText
}

Expand Down
Loading