From fb726bca3420cd703d58d704ba2821c0fcbbf5dd Mon Sep 17 00:00:00 2001 From: Etzelia Date: Sun, 2 Aug 2020 14:43:49 -0500 Subject: [PATCH] Add welcome command Signed-off-by: Etzelia --- discord/welcome.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 discord/welcome.go diff --git a/discord/welcome.go b/discord/welcome.go new file mode 100644 index 0000000..e4380b2 --- /dev/null +++ b/discord/welcome.go @@ -0,0 +1,53 @@ +package discord + +import ( + "fmt" + + "github.com/bwmarrin/discordgo" +) + +func init() { + commands["welcome"] = command{ + validate: func(cmd commandInit) bool { + return isStaff(cmd.message.Member.Roles, cmd.config.StaffRoles) + }, + run: func(cmd commandInit) (string, error) { + if err := cmd.session.ChannelMessageDelete(cmd.message.ChannelID, cmd.message.ID); err != nil { + return "", err + } + + orphans := make([]*discordgo.Member, 0) + + members, err := cmd.session.GuildMembers(cmd.message.GuildID, "", 1000) + if err != nil { + return "", err + } + for _, member := range members { + if len(member.Roles) == 0 { + orphans = append(orphans, member) + } + } + + resp := "There are no members without roles!" + if len(orphans) > 0 { + resp = "```\n" + for _, orphan := range orphans { + resp += fmt.Sprintf("<@%s>\n", orphan.User.ID) + } + resp += "```" + } + + channel, err := cmd.session.UserChannelCreate(cmd.message.Author.ID) + if err != nil { + return "", nil + } + + if _, err := cmd.session.ChannelMessageSend(channel.ID, resp); err != nil { + return "", nil + } + + return "", nil + }, + help: "Get a list of people with no roles", + } +}