forked from Southclaws/cj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_cmd_userinfo.go
58 lines (49 loc) · 1.49 KB
/
bot_cmd_userinfo.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
package main
import (
"github.com/bwmarrin/discordgo"
"github.com/pkg/errors"
)
func commandUserInfo(cm CommandManager, args string, message discordgo.Message, contextual bool) (bool, bool, error) {
var (
profile UserProfile
verified bool
err error
link string
cachedProfile interface{}
found bool
result string
)
if len(message.Mentions) == 0 {
return false, false, nil
}
for _, user := range message.Mentions {
verified, err = cm.App.IsUserVerified(user.ID)
if err != nil {
result += err.Error() + " "
continue
}
if !verified {
result += cm.App.locale.GetLangString("en", "UserNotVerified", user.ID) + " "
} else {
link, err = cm.App.GetForumUserFromDiscordUser(user.ID)
if err != nil {
return false, false, errors.Wrap(err, "failed to get forum user from discord user")
}
cachedProfile, found = cm.App.cache.Get(link)
if found {
profile = *(cachedProfile.(*UserProfile))
} else {
profile, err = cm.App.GetUserProfilePage(link)
if err != nil {
return false, false, errors.Wrap(err, "failed to get user profile page")
}
}
result += cm.App.locale.GetLangString("en", "CommandUserInfoProfile", profile.UserName, profile.JoinDate, profile.TotalPosts, profile.Reputation) + " "
}
}
_, err = cm.App.discordClient.ChannelMessageSend(message.ChannelID, result)
if err != nil {
return false, false, errors.Wrap(err, "failed to send channel message")
}
return true, false, err
}