This commit is contained in:
Skillz4Killz
2021-11-23 17:18:58 +00:00
committed by GitHub
parent 76fedbae62
commit d0a3f6b1d0
6 changed files with 18 additions and 11 deletions
+2
View File
@@ -15,6 +15,8 @@ jobs:
deno-version: ${{ matrix.deno }}
- name: Cache dependencies
run: deno cache mod.ts
- name: Prepare configs file
run: cp configs.example.ts configs.ts
- name: Run test script for maintainers
if: ${{ github.actor == 'Skillz4Killz' || github.actor == 'itohatweb' }}
run: deno test --unstable --coverage=coverage -A tests/mod.ts
+1
View File
@@ -0,0 +1 @@
export const UNITTEST_TOKEN = "" || Deno.env.get("DISCORD_TOKEN");
+4 -5
View File
@@ -1,13 +1,12 @@
import type { Channel } from "../../types/channels/channel.ts";
import type { CreateMessage } from "../../types/messages/createMessage.ts";
import type { Bot } from "../../bot.ts";
/** Send a message to a users DM. Note: this takes 2 API calls. 1 is to fetch the users dm channel. 2 is to send a message to that channel. */
export async function getDmChannel(bot: Bot, memberId: bigint, content: string | CreateMessage) {
if (memberId === bot.id) throw new Error(bot.constants.Errors.YOU_CAN_NOT_DM_THE_BOT_ITSELF);
/** Get a user's dm channel. This is required in order to send a DM. */
export async function getDmChannel(bot: Bot, userId: bigint) {
if (userId === bot.id) throw new Error(bot.constants.Errors.YOU_CAN_NOT_DM_THE_BOT_ITSELF);
const dmChannelData = await bot.rest.runMethod<Channel>(bot.rest, "post", bot.constants.endpoints.USER_DM, {
recipient_id: memberId.toString(),
recipient_id: userId.toString(),
});
return bot.transformers.channel(bot, { channel: dmChannelData });
}
-1
View File
@@ -1,4 +1,3 @@
import { GatewayIntents } from "../../types/gateway/gatewayIntents.ts";
import type { GuildMemberWithUser } from "../../types/members/guildMember.ts";
import type { ListGuildMembers } from "../../types/members/listGuildMembers.ts";
import type { Bot } from "../../bot.ts";
+7
View File
@@ -0,0 +1,7 @@
import { bot } from "../mod.ts";
Deno.test("[member] get dm channel and send a message", async () => {
// Skillz ID
const channel = await bot.helpers.getDmChannel(130136895395987456n);
await bot.helpers.sendMessage(channel.id, "https://i.imgur.com/doG55NR.png");
});
+4 -5
View File
@@ -1,4 +1,4 @@
// import { UNITTEST_TOKEN } from "../configs.ts";
import { UNITTEST_TOKEN } from "../configs.ts";
import { createBot, createEventHandlers, ChannelTypes, OverwriteTypes, startBot } from "../mod.ts";
import { assertEquals, assertExists, enableCachePlugin } from "./deps.ts";
import { deleteMessageWithReasonTest, deleteMessageWithoutReasonTest } from "./helpers/messages/deleteMessage.ts";
@@ -36,13 +36,11 @@ import { deleteChannelOverwriteTests } from "./helpers/channels/deleteChannelOve
import { editChannelTests } from "./helpers/channels/editChannel.ts";
import { CACHED_COMMUNITY_GUILD_ID, sanitizeMode } from "./constants.ts";
// const botId = BigInt(atob(UNITTEST_TOKEN.split(".")[0]));
const botId = BigInt(atob(Deno.env.get("DISCORD_TOKEN")!.split(".")[0]));
const botId = BigInt(atob(UNITTEST_TOKEN.split(".")[0]));
let startedAt = 0;
export const bot = createBot({
// token: UNITTEST_TOKEN || Deno.env.get("DISCORD_TOKEN"),
token: Deno.env.get("DISCORD_TOKEN")!,
token: UNITTEST_TOKEN || Deno.env.get("DISCORD_TOKEN"),
botId,
events: createEventHandlers({
ready: () => {
@@ -579,6 +577,7 @@ import "./invite/getInvite.ts";
import "./invite/getInvites.ts";
import "./members/avatarlUrl.ts";
import "./members/ban.ts";
import "./members/getDmChannel.ts";
import "./misc/getDiscoveryCategories.ts";
import "./misc/getUser.ts";
import "./misc/snowflake.ts";