[tg] Refactor and little godoc fix

This commit is contained in:
Hamcha 2016-02-19 16:59:36 +00:00
parent 1f113c54bd
commit b393317e7e
1 changed files with 14 additions and 18 deletions

View File

@ -35,29 +35,23 @@ func (b *Broker) Close() {
b.Socket.Close()
}
// SendTextMessage sends a HTML-styles text message to a specific chat.
// SendTextMessage sends a HTML-styles text message to a chat.
// A reply_to message ID can be specified as optional parameter.
func (b *Broker) SendTextMessage(chat *APIChat, text string, original *int) {
cmd := ClientCommand{
sendCmd(ClientCommand{
Type: CmdSendTextMessage,
TextMessageData: &ClientTextMessageData{
Text: text,
ChatID: chat.ChatID,
ReplyID: original,
},
}
// Encode command and send to broker
data, err := json.Marshal(cmd)
if err != nil {
log.Printf("[SendTextMessage] JSON Encode error: %s\n", err.Error())
}
fmt.Fprintln(b.Socket, string(data))
})
}
// SendTextMessage sends a HTML-styles text message to a specific chat.
// SendPhoto sends a photo with an optional caption to a chat.
// A reply_to message ID can be specified as optional parameter.
func (b *Broker) SendPhoto(chat *APIChat, data []byte, caption *string, original *int) {
cmd := ClientCommand{
sendCmd(ClientCommand{
Type: CmdSendPhoto,
PhotoData: &ClientPhotoData{
ChatID: chat.ChatID,
@ -65,13 +59,7 @@ func (b *Broker) SendPhoto(chat *APIChat, data []byte, caption *string, original
Caption: caption,
ReplyID: original,
},
}
// Encode command and send to broker
data, err := json.Marshal(cmd)
if err != nil {
log.Printf("[SendPhoto] JSON Encode error: %s\n", err.Error())
}
fmt.Fprintln(b.Socket, string(data))
})
}
// GetFile sends a file retrieval request to the Broker.
@ -122,6 +110,14 @@ func (b *Broker) SpliceCallback(id int) BrokerCallback {
return b.Callbacks[id]
}
func (b *Broker) sendCmd(cmd ClientCommand) {
data, err := json.Marshal(cmd)
if err != nil {
log.Printf("[sendCmd] JSON Encode error: %s\n", err.Error())
}
fmt.Fprintln(b.Socket, string(data))
}
func (b *Broker) resizeCbArray() {
var i int
cut := false