summaryrefslogtreecommitdiffstats
path: root/bridge/telegram/telegram.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-12-12 23:50:08 +0100
committerGitHub <noreply@github.com>2018-12-12 23:50:08 +0100
commitbfa9a83d316041769704c8b5da96d6f6fb68d732 (patch)
treee08c617f168ead907aee832d178ed86c73ffecfc /bridge/telegram/telegram.go
parent2f7b4d7f68076f45d74900d5dec8648fbf783b9e (diff)
downloadmatterbridge-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/telegram.go')
-rw-r--r--bridge/telegram/telegram.go37
1 files changed, 2 insertions, 35 deletions
diff --git a/bridge/telegram/telegram.go b/bridge/telegram/telegram.go
index e16e2bef..33d55bcd 100644
--- a/bridge/telegram/telegram.go
+++ b/bridge/telegram/telegram.go
@@ -75,15 +75,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
// Delete message
if msg.Event == config.EventMsgDelete {
- 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
+ return b.handleDelete(&msg, chatid)
}
// Upload a file if it exists
@@ -101,32 +93,7 @@ func (b *Btelegram) Send(msg config.Message) (string, error) {
// edit the message if we have a msg ID
if msg.ID != "" {
- 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)
- if b.GetString("MessageFormat") == HTMLFormat {
- b.Log.Debug("Using mode HTML")
- m.ParseMode = tgbotapi.ModeHTML
- }
- if b.GetString("MessageFormat") == "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
+ return b.handleEdit(&msg, chatid)
}
// Post normal message