добавил интеграцию с сайтом

This commit is contained in:
taz
2025-08-13 23:35:56 +02:00
parent 9a4f305853
commit 7c2951fc78
3 changed files with 136 additions and 35 deletions
+29
View File
@@ -5,8 +5,37 @@ import (
tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
"github.com/bwmarrin/discordgo"
"github.com/SevereCloud/vksdk/v2/api"
"net/http"
"net/url"
"fmt"
"io"
"os"
)
// Отправка сообщения на сайт
func (b *Bridge) SendToSite(text string) error {
apiURL := os.Getenv("SITE_API_URL")
token := os.Getenv("SITE_API_TOKEN")
if apiURL == "" || token == "" {
return fmt.Errorf("SITE_API_URL или SITE_API_TOKEN не заданы")
}
fullURL := fmt.Sprintf("%s?token=%s&text=%s", apiURL, token, url.QueryEscape(text))
req, err := http.NewRequest("GET", fullURL, nil)
if err != nil {
return err
}
req.Header.Set("Accept", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
_, err = io.ReadAll(resp.Body)
return err
}
// Получить имя пользователя VK по id
func (b *Bridge) GetVKUserName(userID int) (string, error) {
resp, err := b.VK.UsersGet(api.Params{"user_ids": userID})