Skip to content

Commit

Permalink
feat: 增加默认消息输出
Browse files Browse the repository at this point in the history
  • Loading branch information
ser163 committed Jul 4, 2023
1 parent b5c5d8f commit 259860e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package main

import (
"bufio"
"bytes"
"crypto/hmac"
"crypto/sha256"
Expand Down Expand Up @@ -84,6 +85,20 @@ func main() {
picURL := flag.String("pic", "", "图片链接")
flag.Parse()
config = *configd

if *content == "" && !isInputFromPipe() {
fmt.Println("请提供消息内容")
flag.PrintDefaults()
return
}

if *content == "" && isInputFromPipe() {
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
*content += scanner.Text()
}
}

message := Message{MsgType: *msgType}
switch *msgType {
case "text":
Expand Down Expand Up @@ -150,3 +165,8 @@ func getSignature(secret string) (string, string) {
signature := base64.StdEncoding.EncodeToString(data)
return url.QueryEscape(signature), timestamp
}

func isInputFromPipe() bool {
fileInfo, _ := os.Stdin.Stat()
return fileInfo.Mode()&os.ModeCharDevice == 0
}

0 comments on commit 259860e

Please sign in to comment.