✨ Added news/announcement message reposts from bot channel
This commit is contained in:
parent
5b6ce166de
commit
62ba8b5634
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
log "github.com/kirillDanshin/dlog" // Insert logs only in debug builds
|
||||
tg "github.com/toby3d/telegram" // My Telegram bindings
|
||||
)
|
||||
|
||||
func channelPost(post *tg.Message) {
|
||||
if post.Chat.ID != channelID {
|
||||
log.Ln(post.Chat.ID, "!=", channelID)
|
||||
return
|
||||
}
|
||||
|
||||
users, err := dbGetUsers()
|
||||
errCheck(err)
|
||||
|
||||
for i := range users {
|
||||
bot.ForwardMessage(
|
||||
tg.NewForwardMessage(post.Chat.ID, int64(users[i]), post.ID),
|
||||
)
|
||||
|
||||
time.Sleep(time.Second / 10) // For avoid spamming
|
||||
}
|
||||
}
|
|
@ -3,4 +3,5 @@ telegram:
|
|||
webhook:
|
||||
set: https://www.google.com
|
||||
listen: /bot
|
||||
serve: 0.0.0.0:2368
|
||||
serve: 0.0.0.0:2368
|
||||
channel: -1000000000000
|
|
@ -9,8 +9,9 @@ import (
|
|||
|
||||
// allowedUpdates is a value for parameter of updates configuration
|
||||
var allowedUpdates = []string{
|
||||
telegram.UpdateInlineQuery, // For searching and sending stickers
|
||||
telegram.UpdateMessage, // For get commands and messages
|
||||
tg.UpdateInlineQuery, // For searching and sending stickers
|
||||
tg.UpdateMessage, // For get commands and messages
|
||||
tg.UpdateChannelPost,
|
||||
}
|
||||
|
||||
// getUpdatesChannel return webhook or long polling channel with bot updates
|
||||
|
|
5
init.go
5
init.go
|
@ -13,7 +13,8 @@ import (
|
|||
|
||||
var (
|
||||
// Variables with types from imports
|
||||
cfg *config.Config
|
||||
cfg *config.Config
|
||||
channelID int64
|
||||
|
||||
// Setted variables
|
||||
flagWebhook = flag.Bool(
|
||||
|
@ -60,4 +61,6 @@ func init() {
|
|||
_, err = cfg.String("telegram.webhook.serve")
|
||||
errCheck(err)
|
||||
}
|
||||
|
||||
channelID = int64(cfg.UInt("telegram.channel"))
|
||||
}
|
||||
|
|
14
main.go
14
main.go
|
@ -31,19 +31,15 @@ func main() {
|
|||
|
||||
inlineQuery(update.InlineQuery)
|
||||
case update.Message != nil:
|
||||
if update.Message.From.ID == bot.Self.ID {
|
||||
log.Ln("Received a message from myself, ignore this update")
|
||||
if bot.IsMessageFromMe(update.Message) ||
|
||||
bot.IsForwardFromMe(update.Message) {
|
||||
log.Ln("Ignore message update")
|
||||
return
|
||||
}
|
||||
|
||||
if update.Message.ForwardFrom != nil {
|
||||
if update.Message.ForwardFrom.ID == bot.Self.ID {
|
||||
log.Ln("Received a forward from myself, ignore this update")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
messages(update.Message)
|
||||
case update.ChannelPost != nil:
|
||||
channelPost(update.ChannelPost)
|
||||
default:
|
||||
log.Ln("Get unsupported update")
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue