2017-02-09 23:17:28 +03:00
|
|
|
package idec
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
2017-12-07 17:07:46 +03:00
|
|
|
|
2018-11-11 20:54:49 +03:00
|
|
|
idec "github.com/idec-net/go-idec"
|
2017-02-09 23:17:28 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// ParseMessage ...
|
|
|
|
func ParseMessage(message string) (Message, error) {
|
|
|
|
var m Message
|
|
|
|
|
2017-12-07 17:07:46 +03:00
|
|
|
msg, err := idec.ParseMessage(message)
|
2017-02-09 23:17:28 +03:00
|
|
|
if err != nil {
|
|
|
|
return m, err
|
|
|
|
}
|
2017-12-07 17:07:46 +03:00
|
|
|
|
|
|
|
m.Tags = msg.Tags.II
|
|
|
|
m.Echo = msg.Echo
|
|
|
|
m.Timestamp = msg.Timestamp
|
|
|
|
m.From = msg.From
|
|
|
|
m.Address = msg.Address
|
|
|
|
m.To = msg.To
|
|
|
|
m.Subg = msg.Subg
|
|
|
|
m.Body = msg.Body
|
|
|
|
m.Repto = msg.Tags.Repto
|
|
|
|
m.ID = msg.ID
|
2017-02-09 23:17:28 +03:00
|
|
|
|
|
|
|
return m, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseEchoList parse /list.txt
|
|
|
|
func ParseEchoList(list string) ([]Echo, error) {
|
|
|
|
var echoes []Echo
|
|
|
|
for _, e := range strings.Split(list, "\n") {
|
|
|
|
desc := strings.Split(e, ":")
|
|
|
|
if len(desc) <= 1 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
count, err := strconv.Atoi(desc[1])
|
|
|
|
if err != nil {
|
|
|
|
return echoes, err
|
|
|
|
}
|
|
|
|
echoes = append(echoes, Echo{desc[0], count, desc[2]})
|
|
|
|
}
|
|
|
|
|
|
|
|
return echoes, nil
|
|
|
|
}
|