Skip to content

Commit

Permalink
Ping debug messages
Browse files Browse the repository at this point in the history
A friend of mine got weird behaviours, such as negative numbers. Now I'm gonna gather everything I can to put an end to this problem once and for all
  • Loading branch information
LEGOlord208 authored and LEGOlord208 committed Apr 10, 2017
1 parent b9b6508 commit 13e3d9c
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,35 +432,42 @@ func messageCommand(session *discordgo.Session, e *discordgo.Message, guild *dis

if strings.EqualFold(cmd, "ping") {
first := time.Now().UTC()
fmt.Println("Got time. It's", first)
fmt.Println("time.Now() without .UTC() is", time.Now())

timestamp, err := e.Timestamp.Parse()
if err != nil {
stdutil.PrintErr("Couldn't parse timestamp", err)
return
}
fmt.Println("Timestamp time is", timestamp)

inMS := first.Sub(timestamp).Nanoseconds() / time.Millisecond.Nanoseconds()
text := "Incoming: `" + strconv.FormatInt(inMS, 10) + "ms`"

middle := time.Now().UTC()
_, err = session.ChannelMessageEditComplex(e.ChannelID, e.ID, &discordgo.MessageEdit{
Content: "Pong! 1/2",
Embed: &discordgo.MessageEmbed{
Description: text,
},
})
fmt.Println("Got time again. It's", middle)

msg := &discordgo.MessageEdit{}
msg.SetContent("Pong! 1/2")
msg.Embed = &discordgo.MessageEmbed{
Description: text,
}
_, err = session.ChannelMessageEditComplex(e.ChannelID, e.ID, msg)

last := time.Now().UTC()
fmt.Println("Got time a last time. It's ", last)
outMS := last.Sub(middle).Nanoseconds() / time.Millisecond.Nanoseconds()
text += "\nOutgoing: `" + strconv.FormatInt(outMS, 10) + "ms`"
text += "\n\n\nIncoming is the time it takes for the message to reach DiscordConsole."
text += "\nOutgoing is the time it takes for DiscordConsole to reach discord."

_, err = session.ChannelMessageEditComplex(e.ChannelID, e.ID, &discordgo.MessageEdit{
Content: "Pong! 2/2",
Embed: &discordgo.MessageEmbed{
Description: text,
},
})
msg = &discordgo.MessageEdit{}
msg.SetContent("Pong! 2/2")
msg.Embed = &discordgo.MessageEmbed{
Description: text,
}
_, err = session.ChannelMessageEditComplex(e.ChannelID, e.ID, msg)
if err != nil {
stdutil.PrintErr("Couldn't edit message", err)
}
Expand Down

1 comment on commit 13e3d9c

@jD91mZM2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and I use this weird syntax because of bwmarrin/discordgo#352. If it's not merged I will revert it.
I basically just changed the wrong branch

Please sign in to comment.