Browse Source

Remove Facebook functionality from sender

develop
parent
commit
654248a36f
  1. 52
      internal/models/config.go
  2. 48
      internal/send/send.go

52
internal/models/config.go

@ -1,12 +1,5 @@ @@ -1,12 +1,5 @@
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 {
@ -20,49 +13,4 @@ type Config struct { @@ -20,49 +13,4 @@ type Config struct {
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")
}
}
}

48
internal/send/send.go

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
package send
import (
"log"
"ssender/internal/models"
"github.com/SevereCloud/vksdk/v2/api"
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)
func RunSend(senditems *models.SendItems, config models.Config) error {
for _, v := range senditems.ItemList {
if config.Telegram.Send {
log.Println("Send to telegram")
bot, err := tgbotapi.NewBotAPI(config.Telegram.Token)
if err != nil {
return 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 {
return 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 {
return err
}
log.Println("Sended to VK")
}
}
return nil
}
Loading…
Cancel
Save