mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
fix: rate limited unit tests from createBot async
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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: [
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
|
||||
@@ -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" }),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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, {
|
||||
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user