/
execute.go
51 lines (39 loc) Β· 1.15 KB
/
execute.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
package api
import (
"fmt"
"net/url"
"github.com/botscommunity/vkgo/internal/pkg/responses"
"github.com/botscommunity/vkgo/types"
)
func (bot *Bot) Execute(properties ...any) (result any, err *responses.Error) {
query, installed := make(url.Values), make(map[string]bool)
for _, property := range properties {
switch property := property.(type) {
case types.Execute:
setExecuteStructProperty(&query, property, installed)
case string:
query.Set("code", property)
case float32, float64:
query.Set("func_v", fmt.Sprintf("%f", property))
installed["version"] = true
}
}
if !installed["version"] {
query.Set("func_v", fmt.Sprintf("%f", bot.Version))
}
reply := responses.Execute{}
err = responses.NewInternalError(bot.Call("execute", query.Encode(), &reply))
if reply.Error != nil {
err = reply.Error
}
return reply.Result, err
}
func setExecuteStructProperty(query *url.Values, property types.Execute, installed map[string]bool) {
if property, ok := property.Code.(string); ok {
query.Set("code", property)
}
if property.Version != 0 {
query.Set("func_v", fmt.Sprintf("%f", property))
installed["version"] = true
}
}