You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
1.7 KiB
68 lines
1.7 KiB
package models |
|
|
|
import ( |
|
"log" |
|
|
|
"github.com/SevereCloud/vksdk/v2/api" |
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" |
|
) |
|
|
|
type Config struct { |
|
Dbpath string `yaml:"dbpath"` |
|
Telegram struct { |
|
Send bool `yaml:"send"` |
|
SendDebug bool `yaml:"senddebug"` |
|
ChatId int64 `yaml:"chatid"` |
|
Token string `yaml:"token"` |
|
} `yaml:"telegram"` |
|
VK struct { |
|
Send bool `yaml:"send"` |
|
Token string `yaml:"token"` |
|
OwnerId int64 `yaml:"ownerid"` |
|
} `yaml:"vk"` |
|
Facebook struct { |
|
Send bool `yaml:"send"` |
|
Token string `yaml:"token"` |
|
} `yaml:"facebook"` |
|
} |
|
|
|
func (config Config) RunSend(senditems SendItems) { |
|
for _, v := range senditems.ItemList { |
|
if config.Telegram.Send { |
|
log.Println("Send to telegram") |
|
bot, err := tgbotapi.NewBotAPI(config.Telegram.Token) |
|
if err != nil { |
|
log.Panic(err) |
|
} |
|
bot.Debug = config.Telegram.SendDebug |
|
|
|
// s := "<b>" + string(v.Title) + "</b>\n" + html.UnescapeString(string(v.Description)) + |
|
// "\nhttps://t.me/iv?url=" + v.Link + "&rhash=da76512d0ff2a2" + |
|
// "\n\nСсылка на пост: " + v.Link |
|
msg := tgbotapi.NewMessage(config.Telegram.ChatId, v.Link) |
|
msg.ParseMode = "Html" |
|
_, err = bot.Send(msg) |
|
if err != nil { |
|
log.Panic(err) |
|
|
|
} |
|
log.Println("Sended to telegram") |
|
} |
|
if config.VK.Send { |
|
log.Println("Send to VK") |
|
vk := api.NewVK(config.VK.Token) |
|
_, err := vk.WallPost(api.Params{ |
|
"owner_id": config.VK.OwnerId, |
|
"attachments": v.Link, |
|
}) |
|
if err != nil { |
|
log.Fatal(err) |
|
} |
|
log.Println("Sended to VK") |
|
} |
|
if config.Facebook.Send { |
|
log.Println("Send to Facebook") |
|
log.Println("Sending to facebook is not implemented yet") |
|
} |
|
} |
|
}
|
|
|