2020-01-16 04:27:57 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2020-04-27 00:25:47 +00:00
|
|
|
"fmt"
|
2020-01-16 04:27:57 +00:00
|
|
|
"log"
|
|
|
|
"testing"
|
2020-04-27 00:25:47 +00:00
|
|
|
"time"
|
|
|
|
|
2021-06-02 02:53:19 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
|
|
"github.com/diamondburned/arikawa/v3/internal/testenv"
|
2020-01-16 04:27:57 +00:00
|
|
|
)
|
|
|
|
|
2020-04-27 00:25:47 +00:00
|
|
|
func TestIntegration(t *testing.T) {
|
2020-12-01 01:49:18 +00:00
|
|
|
cfg := testenv.Must(t)
|
2020-04-27 00:25:47 +00:00
|
|
|
|
|
|
|
client := NewClient("Bot " + cfg.BotToken)
|
2020-01-16 04:27:57 +00:00
|
|
|
|
|
|
|
// Simple GET request
|
|
|
|
u, err := client.Me()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Can't get self:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Println("API user:", u.Username)
|
|
|
|
|
|
|
|
// POST with URL param and paginator
|
2021-06-12 08:26:01 +00:00
|
|
|
guilds, err := client.Guilds(100)
|
2020-01-16 04:27:57 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Can't get guilds:", err)
|
|
|
|
}
|
2021-06-12 08:26:01 +00:00
|
|
|
|
|
|
|
for _, guild := range guilds {
|
|
|
|
if !guild.ID.IsValid() {
|
|
|
|
t.Errorf("guild %q has invalid ID", guild.Name)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
channels, err := client.Channels(guild.ID)
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf(
|
|
|
|
"failed to fetch channels for guild %q (%v): %v",
|
|
|
|
guild.Name, guild.ID, err,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ch := range channels {
|
|
|
|
if !ch.ID.IsValid() {
|
|
|
|
t.Errorf(
|
|
|
|
"channel %q of guild %q (%v) has invalid ID",
|
|
|
|
ch.Name, guild.Name, guild.ID,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 04:27:57 +00:00
|
|
|
}
|
2020-04-27 00:25:47 +00:00
|
|
|
|
2020-12-16 22:51:32 +00:00
|
|
|
var emojisToSend = [...]discord.APIEmoji{
|
2020-04-27 00:25:47 +00:00
|
|
|
"🥺",
|
|
|
|
"❤",
|
|
|
|
"😂",
|
|
|
|
"🥰",
|
|
|
|
"😊",
|
|
|
|
"🔥",
|
|
|
|
"✔",
|
|
|
|
"👍",
|
|
|
|
"😍",
|
|
|
|
"🐻",
|
|
|
|
"🤯",
|
|
|
|
"🔣",
|
|
|
|
"🍔",
|
|
|
|
"🎌",
|
|
|
|
"🇯🇵",
|
|
|
|
"🎥",
|
|
|
|
"🇺🇸",
|
|
|
|
"🌎",
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReactions(t *testing.T) {
|
2020-12-01 01:49:18 +00:00
|
|
|
cfg := testenv.Must(t)
|
2020-04-27 00:25:47 +00:00
|
|
|
|
|
|
|
client := NewClient("Bot " + cfg.BotToken)
|
|
|
|
|
2020-05-13 00:09:32 +00:00
|
|
|
msg := fmt.Sprintf("This is a message sent at %v.", time.Now())
|
2020-04-27 00:25:47 +00:00
|
|
|
|
|
|
|
// Send a new message.
|
2021-06-18 06:32:11 +00:00
|
|
|
m, err := client.SendMessage(cfg.ChannelID, msg)
|
2020-04-27 00:25:47 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Failed to send message:", err)
|
|
|
|
}
|
|
|
|
|
2020-05-13 00:09:32 +00:00
|
|
|
now := time.Now()
|
|
|
|
|
2020-04-27 00:25:47 +00:00
|
|
|
for _, emojiString := range emojisToSend {
|
|
|
|
if err := client.React(cfg.ChannelID, m.ID, emojiString); err != nil {
|
|
|
|
t.Fatal("Failed to send emoji "+emojiString+":", err)
|
|
|
|
}
|
|
|
|
}
|
2020-05-13 00:09:32 +00:00
|
|
|
|
2020-05-13 00:34:36 +00:00
|
|
|
msg += fmt.Sprintf(" Total time taken to send all reactions: %v.", time.Now().Sub(now))
|
2020-05-13 00:09:32 +00:00
|
|
|
|
2021-08-16 09:25:37 +00:00
|
|
|
m, err = client.EditMessage(cfg.ChannelID, m.ID, msg)
|
2020-05-13 00:09:32 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal("Failed to edit message:", err)
|
|
|
|
}
|
2020-04-27 00:25:47 +00:00
|
|
|
}
|