diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9bf4c39..5f2afe8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,7 +29,8 @@ integration_test: only: variables: - $BOT_TOKEN - - $VOICE_ID # for voice tests + - $VOICE_ID # for voice tests + - $CHANNEL_ID # for API integration tests script: # go get first, so it doesn't count towards the timeout. - go get ./... diff --git a/api/guild.go b/api/guild.go index fa4546e..e902468 100644 --- a/api/guild.go +++ b/api/guild.go @@ -4,7 +4,6 @@ import ( "io" "github.com/diamondburned/arikawa/discord" // for clarity - d "github.com/diamondburned/arikawa/discord" "github.com/diamondburned/arikawa/utils/httputil" ) @@ -16,9 +15,9 @@ type CreateGuildData struct { Icon Image `json:"image,omitempty"` // package dc is just package discord - Verification d.Verification `json:"verification_level"` - Notification d.Notification `json:"default_message_notifications"` - ExplicitFilter d.ExplicitFilter `json:"explicit_content_filter"` + Verification discord.Verification `json:"verification_level"` + Notification discord.Notification `json:"default_message_notifications"` + ExplicitFilter discord.ExplicitFilter `json:"explicit_content_filter"` // [0] (First entry) is ALWAYS @everyone. Roles []discord.Role `json:"roles,omitempty"` @@ -124,19 +123,19 @@ type ModifyGuildData struct { Icon Image `json:"image,omitempty"` // package d is just package discord - Verification *d.Verification `json:"verification_level,omitempty"` - Notification *d.Notification `json:"default_message_notifications,omitempty"` - ExplicitFilter *d.ExplicitFilter `json:"explicit_content_filter,omitempty"` + Verification *discord.Verification `json:"verification_level,omitempty"` + Notification *discord.Notification `json:"default_message_notifications,omitempty"` + ExplicitFilter *discord.ExplicitFilter `json:"explicit_content_filter,omitempty"` - AFKChannelID *d.Snowflake `json:"afk_channel_id,string,omitempty"` - AFKTimeout *d.Seconds `json:"afk_timeout,omitempty"` + AFKChannelID *discord.Snowflake `json:"afk_channel_id,string,omitempty"` + AFKTimeout *discord.Seconds `json:"afk_timeout,omitempty"` - OwnerID d.Snowflake `json:"owner_id,string,omitempty"` + OwnerID discord.Snowflake `json:"owner_id,string,omitempty"` Splash Image `json:"splash,omitempty"` Banner Image `json:"banner,omitempty"` - SystemChannelID d.Snowflake `json:"system_channel_id,string,omitempty"` + SystemChannelID discord.Snowflake `json:"system_channel_id,string,omitempty"` } func (c *Client) ModifyGuild( diff --git a/api/integration_test.go b/api/integration_test.go index 5c90798..0ad028e 100644 --- a/api/integration_test.go +++ b/api/integration_test.go @@ -3,18 +3,46 @@ package api import ( + "fmt" "log" "os" "testing" + "time" + + "github.com/diamondburned/arikawa/discord" ) -func TestIntegration(t *testing.T) { +type testConfig struct { + BotToken string + ChannelID discord.Snowflake +} + +func mustConfig(t *testing.T) testConfig { var token = os.Getenv("BOT_TOKEN") if token == "" { t.Fatal("Missing $BOT_TOKEN") } - client := NewClient("Bot " + token) + var cid = os.Getenv("CHANNEL_ID") + if cid == "" { + t.Fatal("Missing $CHANNEL_ID") + } + + id, err := discord.ParseSnowflake(cid) + if err != nil { + t.Fatal("Invalid $CHANNEL_ID:", err) + } + + return testConfig{ + BotToken: token, + ChannelID: id, + } +} + +func TestIntegration(t *testing.T) { + cfg := mustConfig(t) + + client := NewClient("Bot " + cfg.BotToken) // Simple GET request u, err := client.Me() @@ -30,3 +58,44 @@ func TestIntegration(t *testing.T) { t.Fatal("Can't get guilds:", err) } } + +var emojisToSend = [...]string{ + "πŸ₯Ί", + "❀", + "πŸ˜‚", + "πŸ₯°", + "😊", + "πŸ”₯", + "βœ”", + "πŸ‘", + "😍", + "🐻", + "🀯", + "πŸ”£", + "πŸ”", + "🎌", + "πŸ‡―πŸ‡΅", + "πŸŽ₯", + "πŸ‡ΊπŸ‡Έ", + "🌎", +} + +func TestReactions(t *testing.T) { + cfg := mustConfig(t) + + client := NewClient("Bot " + cfg.BotToken) + + msg := fmt.Sprint("This is a message sent at ", time.Now()) + + // Send a new message. + m, err := client.SendMessage(cfg.ChannelID, msg, nil) + if err != nil { + t.Fatal("Failed to send message:", err) + } + + for _, emojiString := range emojisToSend { + if err := client.React(cfg.ChannelID, m.ID, emojiString); err != nil { + t.Fatal("Failed to send emoji "+emojiString+":", err) + } + } +} diff --git a/go.mod b/go.mod index 5ddaccf..a8aca42 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/pkg/errors v0.9.1 github.com/sasha-s/go-csync v0.0.0-20160729053059-3bc6c8bdb3fa github.com/sasha-s/go-deadlock v0.2.0 - golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 - golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect + golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 golang.org/x/time v0.0.0-20191024005414-555d28b269f0 ) diff --git a/go.sum b/go.sum index eb097f4..390fa1d 100644 --- a/go.sum +++ b/go.sum @@ -12,9 +12,13 @@ github.com/sasha-s/go-deadlock v0.2.0 h1:lMqc+fUb7RrFS3gQLtoQsJ7/6TV/pAIFvBsqX73 github.com/sasha-s/go-deadlock v0.2.0/go.mod h1:StQn567HiB1fF2yJ44N9au7wOhrPS3iZqiDbRupzT10= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=