feat: internal intents resolution (#390)

* better intents typing

* Update README.md

* Update mod.test.ts

* support enum too
This commit is contained in:
ITOH
2021-01-19 09:18:13 +01:00
committed by GitHub
parent 8b663ca4de
commit e56d67a138
4 changed files with 7 additions and 7 deletions

View File

@@ -28,11 +28,11 @@ If you do not wish to use a boilerplate, you may continue reading.
Here's a minimal example to get started with:
```typescript
import { Intents, startBot } from "https://deno.land/x/discordeno@10.0.1/mod.ts";
import { startBot } from "https://deno.land/x/discordeno/mod.ts";
startBot({
token: "BOT TOKEN",
intents: [Intents.GUILDS, Intents.GUILD_MESSAGES],
intents: ["GUILDS", "GUILD_MESSAGES"],
eventHandlers: {
ready() {
console.log("Successfully connected to gateway");

View File

@@ -3,6 +3,7 @@ import {
BotConfig,
DiscordBotGatewayData,
EventHandlers,
Intents,
} from "./types/mod.ts";
import { baseEndpoints, endpoints, GATEWAY_VERSION } from "./util/constants.ts";
import { spawnShards } from "./ws/shard_manager.ts";
@@ -54,7 +55,7 @@ export async function startBot(config: BotConfig) {
proxyWSURL = botGatewayData.url;
identifyPayload.token = config.token;
identifyPayload.intents = config.intents.reduce(
(bits, next) => (bits |= next),
(bits, next) => (bits |= typeof next === "string" ? Intents[next] : next),
0,
);
identifyPayload.shard = [0, botGatewayData.shards];
@@ -96,7 +97,7 @@ export async function startBigBrainBot(data: BigBrainBotConfig) {
}
identifyPayload.intents = data.intents.reduce(
(bits, next) => (bits |= next),
(bits, next) => (bits |= typeof next === "string" ? Intents[next] : next),
0,
);

View File

@@ -28,7 +28,7 @@ import {
export interface BotConfig {
token: string;
compress?: boolean;
intents: Intents[];
intents: (Intents | keyof typeof Intents)[];
eventHandlers?: EventHandlers;
}

View File

@@ -22,7 +22,6 @@ import {
getMessage,
getPins,
Guild,
Intents,
OverwriteType,
pin,
removeReaction,
@@ -37,7 +36,7 @@ if (!token) throw new Error("Token is not provided");
startBot({
token,
intents: [Intents.GUILD_MESSAGES, Intents.GUILDS],
intents: ["GUILD_MESSAGES", "GUILDS"],
});
// Default options for tests