cleanup chatid/topicid parsing
This commit is contained in:
@@ -86,36 +86,44 @@ func TGGetParseMode(b *Btelegram, username string, text string) (textout string,
|
|||||||
return textout, parsemode
|
return textout, parsemode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Btelegram) Send(msg config.Message) (string, error) {
|
func (b *Btelegram) getIds(channel string) (int64, int, error) {
|
||||||
b.Log.Debugf("=> Receiving %#v", msg)
|
|
||||||
|
|
||||||
var chatid int64
|
var chatid int64
|
||||||
topicid := 0
|
topicid := 0
|
||||||
|
|
||||||
// get the chatid
|
// get the chatid
|
||||||
if strings.Contains(msg.Channel, "/") {
|
if strings.Contains(channel, "/") {
|
||||||
s := strings.Split(msg.Channel, "/")
|
s := strings.Split(channel, "/")
|
||||||
if len(s) < 2 {
|
if len(s) < 2 {
|
||||||
b.Log.Errorf("Invalid channel format: %#v\n", msg.Channel)
|
b.Log.Errorf("Invalid channel format: %#v\n", channel)
|
||||||
return "", nil
|
return 0, 0, nil
|
||||||
}
|
}
|
||||||
id, err := strconv.ParseInt(s[0], 10, 64)
|
id, err := strconv.ParseInt(s[0], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
chatid = id
|
chatid = id
|
||||||
tid, err := strconv.Atoi(s[1])
|
tid, err := strconv.Atoi(s[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
topicid = tid
|
topicid = tid
|
||||||
} else {
|
} else {
|
||||||
id, err := strconv.ParseInt(msg.Channel, 10, 64)
|
id, err := strconv.ParseInt(channel, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
chatid = id
|
chatid = id
|
||||||
}
|
}
|
||||||
|
return chatid, topicid, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Btelegram) Send(msg config.Message) (string, error) {
|
||||||
|
b.Log.Debugf("=> Receiving %#v", msg)
|
||||||
|
|
||||||
|
chatid, topicid, err := b.getIds(msg.Channel)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
// map the file SHA to our user (caches the avatar)
|
// map the file SHA to our user (caches the avatar)
|
||||||
if msg.Event == config.EventAvatarDownload {
|
if msg.Event == config.EventAvatarDownload {
|
||||||
|
|||||||
Reference in New Issue
Block a user