Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

humanize the account creation date #166

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions eventhandler/memberjoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"fmt"
"log"
"runtime/debug"
"time"
"trup/ctx"
"trup/db"
"time"

"github.com/bwmarrin/discordgo"
"github.com/dustin/go-humanize"
)

func MemberJoin(ctx *ctx.Context, m *discordgo.GuildMemberAdd) {
Expand All @@ -19,6 +20,10 @@ func MemberJoin(ctx *ctx.Context, m *discordgo.GuildMemberAdd) {
}()

accountCreateDate, _ := discordgo.SnowflakeTimestamp(m.User.ID)
joinDate, err := m.JoinedAt.Parse()
if err != nil {
joinDate = time.Now().UTC()
}
embed := discordgo.MessageEmbed{
Author: &discordgo.MessageEmbedAuthor{
IconURL: m.User.AvatarURL("64"),
Expand All @@ -28,16 +33,16 @@ func MemberJoin(ctx *ctx.Context, m *discordgo.GuildMemberAdd) {
Fields: []*discordgo.MessageEmbedField{
{
Name: "Account Creation Date",
Value: accountCreateDate.UTC().String(),
Value: accountCreateDate.UTC().Format("2006-01-02 15:04:05.000") + " (" + humanize.Time(accountCreateDate) + ")",
},
{
Name: "Join Date",
Value: time.Now().UTC().String(),
Value: joinDate.Format("2006-01-02 15:04:05.000"),
},
},
}

_, err := ctx.Session.ChannelMessageSendEmbed(ctx.Env.ChannelBotTraffic, &embed)
_, err = ctx.Session.ChannelMessageSendEmbed(ctx.Env.ChannelBotTraffic, &embed)
if err != nil {
log.Printf("Failed to send embed to channel %s of user(%s) join. Error: %s\n", ctx.Env.ChannelBotTraffic, m.User.ID, err)
}
Expand Down