Public Access
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
|
"github.com/bwmarrin/discordgo"
|
|
"github.com/SevereCloud/vksdk/v2/api"
|
|
)
|
|
|
|
// Структура для хранения клиентов
|
|
type Bridge struct {
|
|
Telegram *tgbotapi.BotAPI
|
|
Discord *discordgo.Session
|
|
VK *api.VK
|
|
}
|
|
|
|
func NewBridge(telegramToken, discordToken, vkToken string) (*Bridge, error) {
|
|
// Telegram
|
|
tgBot, err := tgbotapi.NewBotAPI(telegramToken)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Discord
|
|
dg, err := discordgo.New("Bot " + discordToken)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// VK
|
|
vk := api.NewVK(vkToken)
|
|
|
|
return &Bridge{
|
|
Telegram: tgBot,
|
|
Discord: dg,
|
|
VK: vk,
|
|
}, nil
|
|
}
|
|
|
|
// Отправка сообщения в Telegram
|
|
func (b *Bridge) SendToTelegram(chatID int64, text string) error {
|
|
msg := tgbotapi.NewMessage(chatID, text)
|
|
_, err := b.Telegram.Send(msg)
|
|
return err
|
|
}
|
|
|
|
// Отправка сообщения в Discord
|
|
func (b *Bridge) SendToDiscord(channelID, text string) error {
|
|
_, err := b.Discord.ChannelMessageSend(channelID, text)
|
|
return err
|
|
}
|
|
|
|
// Отправка сообщения в VK
|
|
func (b *Bridge) SendToVK(peerID int, text string) error {
|
|
_, err := b.VK.MessagesSend(api.Params{
|
|
"peer_id": peerID,
|
|
"message": text,
|
|
"random_id": 0,
|
|
})
|
|
return err
|
|
}
|