Skip to content

Commit

Permalink
Merge 34c6e4b into 52cdf1e
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko authored Mar 22, 2024
2 parents 52cdf1e + 34c6e4b commit 1056c15
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/cross_compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,24 @@ jobs:
CGO_ENABLED: 0
run: |
if [ "$GOOS" = "windows" ]; then
go build -o output/gensokyo-kook-${{ matrix.os }}-${{ matrix.goarch }}.exe
go build -ldflags="-s -w" -o output/gensokyo-kook-${{ matrix.os }}-${{ matrix.goarch }}.exe
else
go build -o output/gensokyo-kook-${{ matrix.os }}-${{ matrix.goarch }}
go build -ldflags="-s -w" -o output/gensokyo-kook-${{ matrix.os }}-${{ matrix.goarch }}
fi
- name: Compress executable files with UPX (except for gensokyo-android-arm64)
run: |
sudo apt-get update
sudo apt-get install -y upx
if [[ "${{ matrix.os }}" == *"windows"* ]]; then
FILENAME="output/gensokyo-kook-${{ matrix.os }}-${{ matrix.goarch }}.exe"
else
FILENAME="output/gensokyo-kook-${{ matrix.os }}-${{ matrix.goarch }}"
fi
if [[ "${{ matrix.os }}" == "android" && "${{ matrix.goarch }}" == "arm64" ]]; then
echo "Skipping UPX compression for $FILENAME"
else
upx --best --lzma "$FILENAME"
fi
- name: Upload artifacts
Expand Down
2 changes: 1 addition & 1 deletion Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func PostMessageToUrls(message map[string]interface{}) {
// 设置请求头
req.Header.Set("Content-Type", "application/json")
// 设置 X-Self-ID
selfid := config.GetAppIDStr()
selfid := config.BotID
req.Header.Set("X-Self-ID", selfid)

// 发送请求
Expand Down
21 changes: 1 addition & 20 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
var (
instance *Config
mu sync.Mutex
BotID string
)

type Config struct {
Expand Down Expand Up @@ -632,26 +633,6 @@ func GetArrayValue() bool {
return instance.Settings.Array
}

// 获取AppID
func GetAppID() uint64 {
mu.Lock()
defer mu.Unlock()
if instance != nil {
return instance.Settings.AppID
}
return 0 // or whatever default value you'd like to return if instance is nil
}

// 获取AppID String
func GetAppIDStr() string {
mu.Lock()
defer mu.Unlock()
if instance != nil {
return fmt.Sprintf("%d", instance.Settings.AppID)
}
return "0"
}

// 获取WsToken
func GetWsToken() []string {
mu.Lock()
Expand Down
2 changes: 1 addition & 1 deletion echo/messageidmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func GetLazyMessagesId(groupID string) string {
randomIndex := rand.Intn(len(recentMessages))
randomMessageID = recentMessages[randomIndex]
} else {
msgType := GetMessageTypeByGroupidv2(config.GetAppIDStr(), groupID)
msgType := GetMessageTypeByGroupidv2(config.BotID, groupID)
if strings.HasPrefix(msgType, "guild") {
randomMessageID = "1000" // 频道主动信息
} else {
Expand Down
2 changes: 1 addition & 1 deletion handlers/get_login_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func GetLoginInfo(client callapi.Client, Token string, BaseUrl string, message c
var botname string

// Assuming 全局_botid is a global or environment variable
globalBotID := config.GetAppID() // Replace with the actual global variable or value
globalBotID := config.BotID // Replace with the actual global variable or value
userIDStr := fmt.Sprintf("%d", globalBotID)
botname = config.GetCustomBotName()

Expand Down
8 changes: 7 additions & 1 deletion handlers/message_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,13 @@ func RevertTransformedText(data interface{}, msgtype string, Token string, BaseU
submatches := re.FindStringSubmatch(m)
if len(submatches) > 1 {
userID := submatches[1]

if userID == BotID {
if config.GetRemoveAt() {
return ""
} else {
return "[CQ:at,qq=" + BotID + "]"
}
}
// 不是 BotID,进行正常映射
userID64, err := idmap.StoreIDv2(userID)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ func main() {
if !nologin {
if configURL == "" { //初始化handlers
handlers.BotID = response.Data.ID
config.BotID = response.Data.ID
} else { //初始化handlers
handlers.BotID = config.GetDevBotid()
config.BotID = response.Data.ID
}
botID64, err := strconv.ParseUint(handlers.BotID, 10, 64)

Expand Down Expand Up @@ -278,10 +280,10 @@ func main() {
r.POST("/url", url.CreateShortURLHandler)
r.GET("/url/:shortURL", url.RedirectFromShortURLHandler)
if config.GetIdentifyFile() {
appIDStr := config.GetAppIDStr()
appIDStr := config.BotID
fileName := appIDStr + ".json"
r.GET("/"+fileName, func(c *gin.Context) {
content := fmt.Sprintf(`{"bot_appid":%d}`, config.GetAppID())
content := fmt.Sprintf(`{"bot_appid":%d}`, config.BotID)
c.Header("Content-Type", "application/json")
c.String(200, content)
})
Expand Down
2 changes: 1 addition & 1 deletion server/wsserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func wsHandler(Token string, BaseUrl string, p *Processor.Processors, c *gin.Con
p.WsServerClients = append(p.WsServerClients, client)

// 获取botID
botID := config.GetAppID()
botID := config.BotID

// 发送连接成功的消息
message := map[string]interface{}{
Expand Down

0 comments on commit 1056c15

Please sign in to comment.