|
|
|
@ -97,7 +97,7 @@ func (b *Btelegram) handleForwarded(rmsg *config.Message, message *tgbotapi.Mess
|
|
|
|
|
// handleQuoting handles quoting of previous messages
|
|
|
|
|
func (b *Btelegram) handleQuoting(rmsg *config.Message, message *tgbotapi.Message) {
|
|
|
|
|
// Used to check if the message was a reply to the root topic
|
|
|
|
|
if message.ReplyToMessage != nil && !(message.ReplyToMessage.MessageID == message.MessageThreadID) { //nolint:nestif
|
|
|
|
|
if message.ReplyToMessage != nil && (!message.IsTopicMessage || message.ReplyToMessage.MessageID != message.MessageThreadID) { //nolint:nestif
|
|
|
|
|
usernameReply := ""
|
|
|
|
|
if message.ReplyToMessage.From != nil {
|
|
|
|
|
if b.GetBool("UseFirstName") {
|
|
|
|
@ -199,6 +199,8 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
|
|
|
|
spew.Dump(update.Message)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b.handleGroupUpdate(update)
|
|
|
|
|
|
|
|
|
|
var message *tgbotapi.Message
|
|
|
|
|
|
|
|
|
|
rmsg := config.Message{Account: b.Account, Extra: make(map[string][]interface{})}
|
|
|
|
@ -217,14 +219,14 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
|
|
|
|
// set the ID's from the channel or group message
|
|
|
|
|
rmsg.ID = strconv.Itoa(message.MessageID)
|
|
|
|
|
rmsg.Channel = strconv.FormatInt(message.Chat.ID, 10)
|
|
|
|
|
if message.MessageThreadID != 0 {
|
|
|
|
|
if message.IsTopicMessage {
|
|
|
|
|
rmsg.Channel += "/" + strconv.Itoa(message.MessageThreadID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// preserve threading from telegram reply
|
|
|
|
|
if message.ReplyToMessage != nil &&
|
|
|
|
|
// Used to check if the message was a reply to the root topic
|
|
|
|
|
!(message.ReplyToMessage.MessageID == message.MessageThreadID) {
|
|
|
|
|
(!message.IsTopicMessage || message.ReplyToMessage.MessageID != message.MessageThreadID) {
|
|
|
|
|
rmsg.ParentID = strconv.Itoa(message.ReplyToMessage.MessageID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -261,6 +263,50 @@ func (b *Btelegram) handleRecv(updates <-chan tgbotapi.Update) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Btelegram) handleGroupUpdate(update tgbotapi.Update) {
|
|
|
|
|
msg := update.Message
|
|
|
|
|
|
|
|
|
|
switch {
|
|
|
|
|
case msg.NewChatMembers != nil:
|
|
|
|
|
b.handleUserJoin(update)
|
|
|
|
|
case msg.LeftChatMember != nil:
|
|
|
|
|
b.handleUserLeave(update)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Btelegram) handleUserJoin(update tgbotapi.Update) {
|
|
|
|
|
msg := update.Message
|
|
|
|
|
for _, user := range msg.NewChatMembers {
|
|
|
|
|
rmsg := config.Message{
|
|
|
|
|
UserID: strconv.FormatInt(user.ID, 10),
|
|
|
|
|
Username: user.FirstName, // for some reason all the other name felids are empty on this event (at least for me)
|
|
|
|
|
Channel: strconv.FormatInt(msg.Chat.ID, 10),
|
|
|
|
|
Account: b.Account,
|
|
|
|
|
Protocol: b.Protocol,
|
|
|
|
|
Event: config.EventJoinLeave,
|
|
|
|
|
Text: "joined chat",
|
|
|
|
|
}
|
|
|
|
|
b.Remote <- rmsg
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Btelegram) handleUserLeave(update tgbotapi.Update) {
|
|
|
|
|
msg := update.Message
|
|
|
|
|
user := msg.LeftChatMember
|
|
|
|
|
|
|
|
|
|
rmsg := config.Message{
|
|
|
|
|
UserID: strconv.FormatInt(user.ID, 10),
|
|
|
|
|
Username: user.FirstName, // for some reason all the other name felids are empty on this event (at least for me)
|
|
|
|
|
Channel: strconv.FormatInt(msg.Chat.ID, 10),
|
|
|
|
|
Account: b.Account,
|
|
|
|
|
Protocol: b.Protocol,
|
|
|
|
|
Event: config.EventJoinLeave,
|
|
|
|
|
Text: "left chat",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b.Remote <- rmsg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// handleDownloadAvatar downloads the avatar of userid from channel
|
|
|
|
|
// sends a EVENT_AVATAR_DOWNLOAD message to the gateway if successful.
|
|
|
|
|
// logs an error message if it fails
|
|
|
|
|