fix: rate limited unit tests from createBot async

This commit is contained in:
Skillz4Killz
2022-05-27 18:11:25 +00:00
committed by ITOH
parent 8eeb975161
commit 19ff286a6d
21 changed files with 37 additions and 26 deletions

View File

@@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new category channel",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "Discordeno-test",
type: ChannelTypes.GuildCategory,

View File

@@ -6,11 +6,14 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new news channel",
async fn(t) {
const bot = loadBot();
console.log("news", 1);
const bot = await loadBot();
console.log("news", 2);
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "Discordeno-test",
type: ChannelTypes.GuildNews,
});
console.log("news", 3);
// Assertions
assertExists(channel);
@@ -22,7 +25,9 @@ Deno.test({
assertEquals(channel.nsfw, false);
assertEquals(channel.permissionOverwrites.length, 0);
console.log("news", 4);
// Delete the channel once test is done
await bot.helpers.deleteChannel(channel.id);
console.log("news", 5);
},
});

View File

@@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new text channel",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "Discordeno-test" });
// Assertions

View File

@@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new text channel with NSFW",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "discordeno-test",
nsfw: true,

View File

@@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new text channel with permission overwrites",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "discordeno-test",
permissionOverwrites: [

View File

@@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new text channel with a rate limit per user",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "discordeno-test",
rateLimitPerUser: 2423,

View File

@@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new voice channel",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "Discordeno-test",
type: ChannelTypes.GuildVoice,

View File

@@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new voice channel with a bitrate",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "discordeno-test",
type: ChannelTypes.GuildVoice,

View File

@@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] create a new voice channel with a user limit",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "discordeno-test",
type: ChannelTypes.GuildVoice,

View File

@@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] delete a channel with a reason",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "delete-channel",
});

View File

@@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] delete a channel without a reason",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
// Create a channel to delete
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "delete-channel",

View File

@@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] Get a channel",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "fetching",
});

View File

@@ -5,7 +5,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[channel] Get all channels",
async fn() {
const bot = loadBot();
const bot = await loadBot();
const [first, second] = await Promise.all([
bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "first" }),
bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "second" }),

View File

@@ -6,7 +6,7 @@ import { CACHED_COMMUNITY_GUILD_ID } from "../utils.ts";
Deno.test({
name: "[stage] Create a stage instance",
async fn(t) {
const bot = loadBot();
const bot = await loadBot();
const stage = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, {
name: "createinstance",
type: ChannelTypes.GuildStageVoice,

View File

@@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] Delete a thread", async (t) => {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" });
const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" });
const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, {

View File

@@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] Edit and archive a thread", async (t) => {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" });
const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" });
const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, {

View File

@@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] Get active threads", async (t) => {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" });
const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" });
const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, {

View File

@@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] Get archived threads", async (t) => {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" });
const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" });
const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, {

View File

@@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] join and leave a thread", async (t) => {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" });
const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" });
const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, {

View File

@@ -3,7 +3,7 @@ import { loadBot } from "../../mod.ts";
import { CACHED_COMMUNITY_GUILD_ID } from "../../utils.ts";
Deno.test("[thread] Start a thread", async (t) => {
const bot = loadBot();
const bot = await loadBot();
const channel = await bot.helpers.createChannel(CACHED_COMMUNITY_GUILD_ID, { name: "threads" });
const message = await bot.helpers.sendMessage(channel.id, { content: "thread message" });
const thread = await bot.helpers.startThreadWithMessage(channel.id, message.id, {

View File

@@ -3,16 +3,22 @@ import { dotenv } from "./deps.ts";
dotenv({ export: true, path: `${Deno.cwd()}/.env` });
export function loadBot() {
export async function loadBot() {
const token = Deno.env.get("DISCORD_TOKEN");
if (!token) throw new Error("Token was not provided.");
const botId = BigInt(atob(token.split(".")[0]));
const bot = createBot({
events: {},
intents: 0,
botId,
const bot = await createBot({
token,
botGatewayData: {
url: "wss://gateway.discord.gg",
shards: 1,
sessionStartLimit: {
maxConcurrency: 1,
remaining: 1000,
resetAfter: Date.now() + 1000 * 60 * 60 * 24,
total: 1000,
},
},
});
bot.rest = createRestManager({