-
Notifications
You must be signed in to change notification settings - Fork 0
/
returns.go
74 lines (56 loc) · 1.58 KB
/
returns.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package baapi
import (
"errors"
"fmt"
"strconv"
"strings"
)
func populateBotInfoReturnStruct(response getBotResponseStruct) (BotInfo, error) {
var ret BotInfo
var result = response.Result
if response.Message != "" {
return ret, errors.New(response.Message)
}
if result.Msg != "http://t.me/BotsArchive/0" {
ret.ChannelLink = response.Result.Msg
}
if result.DeveloperID != "0" {
devid, err := strconv.Atoi(fmt.Sprintf("%v", result.DeveloperID))
if err != nil {
return ret, errors.New(UnexpectedError)
}
ret.DeveloperID = devid
}
ret.Infos.Languages = strings.Split(result.Languages, " ")
ret.Infos.Tags = strings.Split(strings.ReplaceAll(result.Tags, "#", ""), " ")
ret.Infos.Name, ret.Infos.Username, ret.Infos.Description = result.Name, result.Username, result.Description
ret.Infos.HasPhoto, ret.Rating.TotalStars, ret.Rating.VotesCount = result.Photo, result.Stars, result.Votes
ret.Rating.AverageRating, ret.ID = result.Vote, result.ID
if result.Groups == 1 {
ret.Infos.SupportsGroups = true
}
if result.Inline == 1 {
ret.Infos.SupportsInline = true
}
if result.Warn != "" {
ret.Infos.HasCopyrightAlert = true
}
return ret, nil
}
func populateUserRatingReturnValues(response getUserVoteResponseStruct) (bool, int, error) {
var hasvoted bool
if response.Message != "" {
return false, 0, errors.New(response.Message)
}
if response.Result == "" {
response.Result = "0"
}
vote, err := strconv.Atoi(response.Result)
if err != nil {
return false, 0, errors.New(UnexpectedError)
}
if vote != 0 {
hasvoted = true
}
return hasvoted, vote, nil
}