File tree Expand file tree Collapse file tree 4 files changed +43
-8
lines changed Expand file tree Collapse file tree 4 files changed +43
-8
lines changed Original file line number Diff line number Diff line change @@ -101,9 +101,9 @@ bot := goicqbot.NewBot(BOT_TOKEN, goicqbot.BotDebug(true))
101101
102102- [x] Delete message
103103
104- - [ ] Chat info
104+ - [x ] Chat info
105105
106- - [ ] Send voice
106+ - [x ] Send voice
107107
108- - [ ] File info
108+ - [x ] File info
109109
Original file line number Diff line number Diff line change @@ -49,9 +49,8 @@ func (b *Bot) GetFileInfo(fileID string) (*File, error) {
4949// NewMessage returns new message
5050func (b * Bot ) NewMessage (chatID string ) * Message {
5151 return & Message {
52- client : b .client ,
53- Chat : Chat {ID : chatID },
54- ContentType : Text ,
52+ client : b .client ,
53+ Chat : Chat {ID : chatID },
5554 }
5655}
5756
@@ -126,7 +125,8 @@ func (b *Bot) NewChat(id string) *Chat {
126125// SendMessage sends a message, passed as an argument.
127126// This method fills the argument with ID of sent message and returns an error if any.
128127func (b * Bot ) SendMessage (message * Message ) error {
129- return b .client .SendTextMessage (message )
128+ message .client = b .client
129+ return message .Send ()
130130}
131131
132132// EditMessage edit a message passed as an argument.
Original file line number Diff line number Diff line change @@ -3,14 +3,16 @@ package goicqbot
33import (
44 "fmt"
55 "os"
6+ "path/filepath"
67)
78
89//go:generate easyjson -all message.go
910
1011type MessageContentType uint8
1112
1213const (
13- Text MessageContentType = iota
14+ Unknown MessageContentType = iota
15+ Text
1416 OtherFile
1517 Voice
1618)
@@ -101,6 +103,26 @@ func (m *Message) Send() error {
101103 }
102104 case Text :
103105 return m .client .SendTextMessage (m )
106+ case Unknown :
107+ // need to autodetect
108+ if m .FileID != "" {
109+ // voice message's fileID always starts with 'I'
110+ if m .FileID [0 ] == voiceMessageLeadingRune {
111+ return m .client .SendVoiceMessage (m )
112+ }
113+ return m .client .SendFileMessage (m )
114+ }
115+
116+ if m .File != nil {
117+ if voiceMessageSupportedExtensions [filepath .Ext (m .File .Name ())] {
118+ return m .client .UploadVoice (m )
119+ }
120+ return m .client .UploadFile (m )
121+ }
122+
123+ if m .Text != "" {
124+ return m .client .SendTextMessage (m )
125+ }
104126 }
105127
106128 return fmt .Errorf ("cannot send message or file without data" )
Original file line number Diff line number Diff line change 1+ package goicqbot
2+
3+ var (
4+ voiceMessageSupportedExtensions = map [string ]bool {
5+ ".aac" : true ,
6+ ".ogg" : true ,
7+ ".m4a" : true ,
8+ }
9+ )
10+
11+ const (
12+ voiceMessageLeadingRune = 'I'
13+ )
You can’t perform that action at this time.
0 commit comments