commit
42e934d3b2
4 changed files with 61 additions and 14 deletions
|
@ -19,8 +19,8 @@ type Message struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
ChannelID string `json:"channel_id"`
|
ChannelID string `json:"channel_id"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Timestamp string `json:"timestamp"`
|
Timestamp Timestamp `json:"timestamp"`
|
||||||
EditedTimestamp string `json:"edited_timestamp"`
|
EditedTimestamp Timestamp `json:"edited_timestamp"`
|
||||||
MentionRoles []string `json:"mention_roles"`
|
MentionRoles []string `json:"mention_roles"`
|
||||||
Tts bool `json:"tts"`
|
Tts bool `json:"tts"`
|
||||||
MentionEveryone bool `json:"mention_everyone"`
|
MentionEveryone bool `json:"mention_everyone"`
|
||||||
|
|
|
@ -144,7 +144,7 @@ type Invite struct {
|
||||||
Channel *Channel `json:"channel"`
|
Channel *Channel `json:"channel"`
|
||||||
Inviter *User `json:"inviter"`
|
Inviter *User `json:"inviter"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
CreatedAt string `json:"created_at"` // TODO make timestamp
|
CreatedAt Timestamp `json:"created_at"`
|
||||||
MaxAge int `json:"max_age"`
|
MaxAge int `json:"max_age"`
|
||||||
Uses int `json:"uses"`
|
Uses int `json:"uses"`
|
||||||
MaxUses int `json:"max_uses"`
|
MaxUses int `json:"max_uses"`
|
||||||
|
@ -207,7 +207,7 @@ type Guild struct {
|
||||||
AfkChannelID string `json:"afk_channel_id"`
|
AfkChannelID string `json:"afk_channel_id"`
|
||||||
EmbedChannelID string `json:"embed_channel_id"`
|
EmbedChannelID string `json:"embed_channel_id"`
|
||||||
OwnerID string `json:"owner_id"`
|
OwnerID string `json:"owner_id"`
|
||||||
JoinedAt string `json:"joined_at"` // make this a timestamp
|
JoinedAt Timestamp `json:"joined_at"`
|
||||||
Splash string `json:"splash"`
|
Splash string `json:"splash"`
|
||||||
AfkTimeout int `json:"afk_timeout"`
|
AfkTimeout int `json:"afk_timeout"`
|
||||||
VerificationLevel VerificationLevel `json:"verification_level"`
|
VerificationLevel VerificationLevel `json:"verification_level"`
|
||||||
|
|
23
types.go
Normal file
23
types.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
// Discordgo - Discord bindings for Go
|
||||||
|
// Available at https://github.com/bwmarrin/discordgo
|
||||||
|
|
||||||
|
// Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// This file contains custom types, currently only a timestamp wrapper.
|
||||||
|
|
||||||
|
package discordgo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Timestamp stores a timestamp, as sent by the Discord API.
|
||||||
|
type Timestamp string
|
||||||
|
|
||||||
|
// Parse parses a timestamp string into a time.Time object.
|
||||||
|
// The only time this can fail is if Discord changes their timestamp format.
|
||||||
|
func (t Timestamp) Parse() (time.Time, error) {
|
||||||
|
return time.Parse(time.RFC3339, string(t))
|
||||||
|
}
|
24
types_test.go
Normal file
24
types_test.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package discordgo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTimestampParse(t *testing.T) {
|
||||||
|
ts, err := Timestamp("2016-03-24T23:15:59.605000+00:00").Parse()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if ts.Year() != 2016 || ts.Month() != time.March || ts.Day() != 24 {
|
||||||
|
t.Error("Incorrect date")
|
||||||
|
}
|
||||||
|
if ts.Hour() != 23 || ts.Minute() != 15 || ts.Second() != 59 {
|
||||||
|
t.Error("Incorrect time")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, offset := ts.Zone()
|
||||||
|
if offset != 0 {
|
||||||
|
t.Error("Incorrect timezone")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue