Public Access
добавил интеграцию с сайтом
This commit is contained in:
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user