~wabarc/wayback/main

« back to all changes in this revision

Viewing changes to publish/channel.go

  • Committer: nobody
  • Date: 2020-11-28 09:11:12 UTC
  • Revision ID: git-v1:befcdd0055443aa779777d9f2e3a212d1b5da429
Add supports for Tor hidden service

Refactor code base.

Remove debug mode of telegram-bot-api.

Remove suspicious characters in regex

https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2020 Wayback Archiver. All rights reserved.
 
2
// Use of this source code is governed by the GNU GPL v3
 
3
// license that can be found in the LICENSE file.
 
4
 
 
5
package publish // import "github.com/wabarc/wayback/publish"
 
6
 
 
7
import (
 
8
        "github.com/go-telegram-bot-api/telegram-bot-api"
 
9
        "github.com/wabarc/wayback/config"
 
10
        "github.com/wabarc/wayback/logger"
 
11
)
 
12
 
 
13
func ToChannel(opts *config.Options, bot *tgbotapi.BotAPI, text string) bool {
 
14
        if bot == nil {
 
15
                var err error
 
16
                bot, err = tgbotapi.NewBotAPI(opts.TelegramToken())
 
17
                if err != nil {
 
18
                        logger.Error("Publish to Telegram Channel failed, %v", err)
 
19
                        return false
 
20
                }
 
21
        }
 
22
 
 
23
        msg := tgbotapi.NewMessageToChannel("@"+opts.TelegramChannel(), text)
 
24
        msg.ParseMode = "html"
 
25
        if _, err := bot.Send(msg); err != nil {
 
26
                logger.Error("Publish message to channel failed, %v", err)
 
27
                return false
 
28
        }
 
29
 
 
30
        return true
 
31
}