generated from gogolcorp/go-yave
/
profile.go
59 lines (51 loc) · 1.68 KB
/
profile.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
package commands
import (
"strconv"
"github.com/blyndusk/cofy/app/core"
"github.com/blyndusk/cofy/app/helpers"
"github.com/blyndusk/cofy/app/middlewares"
"github.com/blyndusk/cofy/app/services"
"github.com/bwmarrin/discordgo"
)
type profileCommand struct {
base core.BaseCommand
}
func ProfileCommandHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
// init new command
cmd := profileCommand{
base: core.BaseCommand{
Name: "profile",
Aliases: []string{"profile", "pf"},
Description: "Give informations about you.",
},
}
// core methods
if services.MatchExecuteCommand(s, m, cmd.base.Aliases) == true {
services.CallExecute(cmd, s, m)
}
if services.MatchHelpCommand(s, m, cmd.base.Aliases) == true {
services.CallHelp(cmd, s, m)
}
if services.MatchTaggedUserProfileCommand(s, m, cmd.base.Aliases) == true {
services.ViewTaggedUserProfile(s, m, cmd.base.Aliases)
}
}
// execute method
func (cmd profileCommand) Execute(s *discordgo.Session, m *discordgo.MessageCreate) {
// systematically get user each time someone createw a message
user := middlewares.GetUser(s, m.Author.ID)
// if the id of the user is not the author id, user doesnt exist
if strconv.Itoa(user.DiscordId) != m.Author.ID {
// if the user is not found, create a new user in db
services.HandleUserNotFound(s, m, user)
} else {
// get the discord user from the session using discordId
discordUser, _ := s.User(strconv.Itoa(user.DiscordId))
// display profile
helpers.EmbedViewProfile(s, m, user, discordUser)
}
}
// help method
func (cmd profileCommand) Help(s *discordgo.Session, m *discordgo.MessageCreate) {
s.ChannelMessageSend(m.ChannelID, cmd.base.Description)
}