diff options
author | Wim <wim@42.be> | 2018-12-12 23:50:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-12 23:50:08 +0100 |
commit | bfa9a83d316041769704c8b5da96d6f6fb68d732 (patch) | |
tree | e08c617f168ead907aee832d178ed86c73ffecfc /bridge/telegram/handlers.go | |
parent | 2f7b4d7f68076f45d74900d5dec8648fbf783b9e (diff) | |
download | matterbridge-msglm-bfa9a83d316041769704c8b5da96d6f6fb68d732.tar.gz matterbridge-msglm-bfa9a83d316041769704c8b5da96d6f6fb68d732.tar.bz2 matterbridge-msglm-bfa9a83d316041769704c8b5da96d6f6fb68d732.zip |
Refactor telegram (#649)
* Decrease complexity in Send() (makes codeclimate happy)
Diffstat (limited to 'bridge/telegram/handlers.go')
-rw-r--r-- | bridge/telegram/handlers.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/bridge/telegram/handlers.go b/bridge/telegram/handlers.go index 8d6c2689..e87466ca 100644 --- a/bridge/telegram/handlers.go +++ b/bridge/telegram/handlers.go @@ -1,6 +1,7 @@ package btelegram import ( + "html" "regexp" "strconv" "strings" @@ -262,6 +263,49 @@ func (b *Btelegram) getDownloadInfo(id string, suffix string, urlpart bool) (str return text, name, url } +// handleDelete handles message deleting +func (b *Btelegram) handleDelete(msg *config.Message, chatid int64) (string, error) { + if msg.ID == "" { + return "", nil + } + msgid, err := strconv.Atoi(msg.ID) + if err != nil { + return "", err + } + _, err = b.c.DeleteMessage(tgbotapi.DeleteMessageConfig{ChatID: chatid, MessageID: msgid}) + return "", err +} + +// handleEdit handles message editing. +func (b *Btelegram) handleEdit(msg *config.Message, chatid int64) (string, error) { + msgid, err := strconv.Atoi(msg.ID) + if err != nil { + return "", err + } + if strings.ToLower(b.GetString("MessageFormat")) == HTMLNick { + b.Log.Debug("Using mode HTML - nick only") + msg.Text = html.EscapeString(msg.Text) + } + m := tgbotapi.NewEditMessageText(chatid, msgid, msg.Username+msg.Text) + switch b.GetString("MessageFormat") { + case HTMLFormat: + b.Log.Debug("Using mode HTML") + m.ParseMode = tgbotapi.ModeHTML + case "Markdown": + b.Log.Debug("Using mode markdown") + m.ParseMode = tgbotapi.ModeMarkdown + } + if strings.ToLower(b.GetString("MessageFormat")) == HTMLNick { + b.Log.Debug("Using mode HTML - nick only") + m.ParseMode = tgbotapi.ModeHTML + } + _, err = b.c.Send(m) + if err != nil { + return "", err + } + return "", nil +} + // handleUploadFile handles native upload of files func (b *Btelegram) handleUploadFile(msg *config.Message, chatid int64) string { var c tgbotapi.Chattable |