-
Notifications
You must be signed in to change notification settings - Fork 1
/
pinMessage.go
54 lines (43 loc) Β· 1.14 KB
/
pinMessage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package api
import (
"fmt"
"net/url"
"github.com/botscommunity/vkgo/internal/pkg/responses"
"github.com/botscommunity/vkgo/types"
)
func (bot *Bot) PinMessage(properties ...any) responses.PinMessage {
query, chatID := make(url.Values), false
for _, property := range properties {
switch property := property.(type) {
case types.PinMessage:
if property.ChatID != 0 {
query.Set("peer_id", fmt.Sprint(property.ChatID))
chatID = true
}
if property.MessageID != 0 {
query.Set("message_id", fmt.Sprint(property.MessageID))
} else if property.ChatMessageID != 0 {
query.Set("conversation_message_id", fmt.Sprint(property.ChatMessageID))
}
case int:
if !chatID {
query.Set("peer_id", fmt.Sprint(property))
chatID = true
} else {
query.Set("conversation_message_id", fmt.Sprint(property))
}
}
}
var (
pinned = responses.PinMessageReply{}
err = responses.NewInternalError(bot.Call("messages.pin", query.Encode(), &pinned))
)
if err != nil {
pinned.Response.Error = err
return pinned.Response
}
if pinned.Error != nil {
pinned.Response.Error = pinned.Error
}
return pinned.Response
}