This repository has been archived by the owner on Sep 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
msgUserStats.go
99 lines (83 loc) · 2.5 KB
/
msgUserStats.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"fmt"
"strings"
"time"
"github.com/bwmarrin/discordgo"
)
func init() {
newCommand("whois", 0, false, msgUserStats).setHelp("Args: [@user]\n\nSome info about the given user.\n\nExample:\n`!owo whois @Strum355#2298`").add()
}
func msgUserStats(s *discordgo.Session, m *discordgo.MessageCreate, msglist []string) {
channel, err := channelDetails(m.ChannelID, s)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "There was an error getting the data :(")
return
}
guild, err := guildDetails("", channel.GuildID, s)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "There was an error getting the data :(")
return
}
var userID string
var nick string
if len(msglist) > 1 {
submatch := userIDRegex.FindStringSubmatch(msglist[1])
if len(submatch) != 0 {
userID = submatch[1]
}
} else {
userID = m.Author.ID
}
user, err := userDetails(userID, s)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "There was an error getting the data :(")
return
}
memberStruct, err := memberDetails(guild.ID, userID, s)
if err != nil {
s.ChannelMessageSend(m.ChannelID, "There was an error getting the data :(")
return
}
var roleNames []string
for _, role := range memberStruct.Roles {
for _, guildRole := range guild.Roles {
if guildRole.ID == role {
roleNames = append(roleNames, guildRole.Name)
}
}
}
if len(roleNames) == 0 {
roleNames = append(roleNames, "None")
}
if memberStruct.Nick == "" {
nick = "None"
} else {
nick = memberStruct.Nick
}
var joinString string
joinDateParsed, _ := memberStruct.JoinedAt.Parse()
joinDate, err := time.Parse("2006-01-02T15:04:05.999999-07:00", joinDateParsed.String())
if err != nil {
log.Error("error parsing time", err)
joinString = "???"
} else {
joinString = joinDate.Format("02 Jan 06 15:04")
}
s.ChannelMessageSendEmbed(m.ChannelID, &discordgo.MessageEmbed{
Color: s.State.UserColor(userID, m.ChannelID),
Description: fmt.Sprintf("%s is a loyal member of %s", user.Username, guild.Name),
Author: &discordgo.MessageEmbedAuthor{
Name: user.Username,
IconURL: discordgo.EndpointUserAvatar(userID, user.Avatar),
},
Footer: footer,
Fields: []*discordgo.MessageEmbedField{
{Name: "Username:", Value: user.Username, Inline: true},
{Name: "Nickname:", Value: nick, Inline: true},
{Name: "Joined Server:", Value: joinString, Inline: false},
{Name: "Roles:", Value: strings.Join(roleNames, ", "), Inline: true},
{Name: "ID Number:", Value: user.ID, Inline: true},
},
})
}