refactor: revert "feat: base plugin lib idea (#2308)" (#2336)

* Revert "feat: base plugin lib idea (#2308)"

This reverts commit ffe7cdbc6f.

* fmt
This commit is contained in:
ITOH
2022-07-02 14:24:43 +01:00
committed by GitHub
parent f57b2274e0
commit 03996c5f58
346 changed files with 786 additions and 856 deletions
-897
View File
@@ -1,897 +0,0 @@
import * as handlers from "./handlers/mod.ts";
import * as helpers from "./helpers/mod.ts";
import { calculateShardId } from "../../gateway/calculateShardId.ts";
import {
baseEndpoints,
CHANNEL_MENTION_REGEX,
CONTEXT_MENU_COMMANDS_NAME_REGEX,
createGatewayManager,
createRestManager,
CreateRestManagerOptions,
CreateShardManager,
delay,
DISCORD_SNOWFLAKE_REGEX,
DiscordActivity,
DiscordAllowedMentions,
DiscordApplication,
DiscordApplicationCommand,
DiscordApplicationCommandOption,
DiscordApplicationCommandOptionChoice,
DiscordAttachment,
DiscordAuditLogEntry,
DiscordAutoModerationActionExecution,
DiscordAutoModerationRule,
DiscordChannel,
DiscordComponent,
DiscordEmbed,
DiscordEmoji,
DISCORDENO_VERSION,
DiscordGatewayPayload,
DiscordGetGatewayBot,
DiscordGuild,
DiscordGuildApplicationCommandPermissions,
DiscordGuildWidget,
DiscordGuildWidgetSettings,
DiscordIntegrationCreateUpdate,
DiscordInteraction,
DiscordInteractionDataOption,
DiscordInviteCreate,
DiscordMember,
DiscordMessage,
DiscordPresenceUpdate,
DiscordReady,
DiscordRole,
DiscordScheduledEvent,
DiscordStageInstance,
DiscordSticker,
DiscordStickerPack,
DiscordTeam,
DiscordTemplate,
DiscordThreadMember,
DiscordUser,
DiscordVoiceRegion,
DiscordVoiceState,
DiscordWebhook,
DiscordWelcomeScreen,
Errors,
GatewayDispatchEventNames,
GatewayIntents,
getBotIdFromToken,
removeTokenPrefix,
SLASH_COMMANDS_NAME_REGEX,
USER_AGENT,
} from "./deps.ts";
import { Activity, transformActivity } from "./transformers/activity.ts";
import { Application, transformApplication } from "./transformers/application.ts";
import { ApplicationCommand, transformApplicationCommand } from "./transformers/applicationCommand.ts";
import {
ApplicationCommandOption,
transformApplicationCommandOption,
} from "./transformers/applicationCommandOption.ts";
import {
ApplicationCommandOptionChoice,
transformApplicationCommandOptionChoice,
} from "./transformers/applicationCommandOptionChoice.ts";
import {
ApplicationCommandPermission,
transformApplicationCommandPermission,
} from "./transformers/applicationCommandPermission.ts";
import { Attachment, transformAttachment } from "./transformers/attachment.ts";
import { AuditLogEntry, transformAuditLogEntry } from "./transformers/auditLogEntry.ts";
import {
AutoModerationActionExecution,
transformAutoModerationActionExecution,
} from "./transformers/automodActionExecution.ts";
import { AutoModerationRule, transformAutoModerationRule } from "./transformers/automodRule.ts";
import { Channel, transformChannel } from "./transformers/channel.ts";
import { Component, transformComponent } from "./transformers/component.ts";
import { Embed, transformEmbed } from "./transformers/embed.ts";
import { Emoji, transformEmoji } from "./transformers/emoji.ts";
import { GetGatewayBot, transformGatewayBot } from "./transformers/gatewayBot.ts";
import { Guild, transformGuild } from "./transformers/guild.ts";
import { Integration, transformIntegration } from "./transformers/integration.ts";
import {
Interaction,
InteractionDataOption,
transformInteraction,
transformInteractionDataOption,
} from "./transformers/interaction.ts";
import { Invite, transformInvite } from "./transformers/invite.ts";
import { Member, transformMember, transformUser, User } from "./transformers/member.ts";
import { Message, transformMessage } from "./transformers/message.ts";
import { PresenceUpdate, transformPresence } from "./transformers/presence.ts";
import { transformActivityToDiscordActivity } from "./transformers/reverse/activity.ts";
import { transformAllowedMentionsToDiscordAllowedMentions } from "./transformers/reverse/allowedMentions.ts";
import { transformApplicationToDiscordApplication } from "./transformers/reverse/application.ts";
import { transformComponentToDiscordComponent } from "./transformers/reverse/component.ts";
import { transformEmbedToDiscordEmbed } from "./transformers/reverse/embed.ts";
import { transformMemberToDiscordMember, transformUserToDiscordUser } from "./transformers/reverse/member.ts";
import { transformTeamToDiscordTeam } from "./transformers/reverse/team.ts";
import { Role, transformRole } from "./transformers/role.ts";
import { ScheduledEvent, transformScheduledEvent } from "./transformers/scheduledEvent.ts";
import { StageInstance, transformStageInstance } from "./transformers/stageInstance.ts";
import { Sticker, StickerPack, transformSticker, transformStickerPack } from "./transformers/sticker.ts";
import { Team, transformTeam } from "./transformers/team.ts";
import { Template, transformTemplate } from "./transformers/template.ts";
import { ThreadMember, transformThreadMember } from "./transformers/threadMember.ts";
import { transformVoiceRegion, VoiceRegions } from "./transformers/voiceRegion.ts";
import { transformVoiceState, VoiceState } from "./transformers/voiceState.ts";
import { transformWebhook, Webhook } from "./transformers/webhook.ts";
import { transformWelcomeScreen, WelcomeScreen } from "./transformers/welcomeScreen.ts";
import { GuildWidget, transformWidget } from "./transformers/widget.ts";
import { GuildWidgetSettings, transformWidgetSettings } from "./transformers/widgetSettings.ts";
import { AllowedMentions } from "./typings.ts";
import { bigintToSnowflake, snowflakeToBigint } from "./util/bigint.ts";
import { BotCollection } from "./util/collection.ts";
import { iconBigintToHash, iconHashToBigInt } from "./util/hash.ts";
import { calculateBits, calculatePermissions } from "./util/permissions.ts";
import { routes } from "./util/routes.ts";
import { urlToBase64 } from "./util/urlToBase64.ts";
import { formatImageURL } from "./util/utils.ts";
import { validateLength } from "./util/validateLength.ts";
export function createBot(options: CreateBotOptions): Bot {
const bot = {
id: options.botId ?? getBotIdFromToken(options.token),
applicationId: options.applicationId || options.botId,
token: removeTokenPrefix(options.token),
events: createEventHandlers(options.events ?? {}),
intents: options.intents,
botGatewayData: options.botGatewayData,
activeGuildIds: new Set<bigint>(),
constants: createBotConstants(),
handlers: createBotGatewayHandlers({}),
utils: createUtils(options.utils ?? {}),
transformers: createTransformers(options.transformers ?? {}),
enabledPlugins: new Set(),
handleDiscordPayload: options.handleDiscordPayload,
cache: {
unrepliedInteractions: new Set<bigint>(),
fetchAllMembersProcessingRequests: new Map(),
},
rest: createRestManager({
token: options.token,
debug: options.events?.debug,
secretKey: options.secretKey ?? undefined,
}),
} as Bot;
bot.helpers = createHelpers(bot, options.helpers ?? {});
bot.gateway = createGatewayManager({
gatewayBot: bot.botGatewayData ?? {} as any,
gatewayConfig: {
token: options.token,
intents: options.intents,
},
debug: bot.events.debug,
handleDiscordPayload: bot.handleDiscordPayload ??
async function (shard, data: DiscordGatewayPayload) {
// TRIGGER RAW EVENT
bot.events.raw(bot as Bot, data, shard.id);
if (!data.t) return;
// RUN DISPATCH CHECK
await bot.events.dispatchRequirements(bot as Bot, data, shard.id);
bot.handlers[data.t as GatewayDispatchEventNames]?.(
bot as Bot,
data,
shard.id,
);
},
});
return bot as Bot;
}
export function createEventHandlers(
events: Partial<EventHandlers>,
): EventHandlers {
function ignore() {}
return {
debug: events.debug ?? ignore,
automodRuleCreate: events.automodRuleCreate ?? ignore,
automodRuleUpdate: events.automodRuleUpdate ?? ignore,
automodRuleDelete: events.automodRuleDelete ?? ignore,
automodActionExecution: events.automodActionExecution ?? ignore,
threadCreate: events.threadCreate ?? ignore,
threadDelete: events.threadDelete ?? ignore,
threadMemberUpdate: events.threadMemberUpdate ?? ignore,
threadMembersUpdate: events.threadMembersUpdate ?? ignore,
threadUpdate: events.threadUpdate ?? ignore,
scheduledEventCreate: events.scheduledEventCreate ?? ignore,
scheduledEventUpdate: events.scheduledEventUpdate ?? ignore,
scheduledEventDelete: events.scheduledEventDelete ?? ignore,
scheduledEventUserAdd: events.scheduledEventUserAdd ?? ignore,
scheduledEventUserRemove: events.scheduledEventUserRemove ?? ignore,
ready: events.ready ?? ignore,
dispatchRequirements: events.dispatchRequirements ?? ignore,
integrationCreate: events.integrationCreate ?? ignore,
integrationDelete: events.integrationDelete ?? ignore,
integrationUpdate: events.integrationUpdate ?? ignore,
interactionCreate: events.interactionCreate ?? ignore,
inviteCreate: events.inviteCreate ?? ignore,
inviteDelete: events.inviteDelete ?? ignore,
guildMemberAdd: events.guildMemberAdd ?? ignore,
guildMemberRemove: events.guildMemberRemove ?? ignore,
guildMemberUpdate: events.guildMemberUpdate ?? ignore,
messageCreate: events.messageCreate ?? ignore,
messageDelete: events.messageDelete ?? ignore,
messageDeleteBulk: events.messageDeleteBulk ?? ignore,
messageUpdate: events.messageUpdate ?? ignore,
reactionAdd: events.reactionAdd ?? ignore,
reactionRemove: events.reactionRemove ?? ignore,
reactionRemoveAll: events.reactionRemoveAll ?? ignore,
reactionRemoveEmoji: events.reactionRemoveEmoji ?? ignore,
presenceUpdate: events.presenceUpdate ?? ignore,
voiceServerUpdate: events.voiceServerUpdate ?? ignore,
voiceStateUpdate: events.voiceStateUpdate ?? ignore,
channelCreate: events.channelCreate ?? ignore,
channelDelete: events.channelDelete ?? ignore,
channelPinsUpdate: events.channelPinsUpdate ?? ignore,
channelUpdate: events.channelUpdate ?? ignore,
guildEmojisUpdate: events.guildEmojisUpdate ?? ignore,
guildBanAdd: events.guildBanAdd ?? ignore,
guildBanRemove: events.guildBanRemove ?? ignore,
guildLoaded: events.guildLoaded ?? ignore,
guildCreate: events.guildCreate ?? ignore,
guildDelete: events.guildDelete ?? ignore,
guildUpdate: events.guildUpdate ?? ignore,
raw: events.raw ?? ignore,
stageInstanceCreate: events.stageInstanceCreate ?? ignore,
stageInstanceDelete: events.stageInstanceDelete ?? ignore,
stageInstanceUpdate: events.stageInstanceUpdate ?? ignore,
roleCreate: events.roleCreate ?? ignore,
roleDelete: events.roleDelete ?? ignore,
roleUpdate: events.roleUpdate ?? ignore,
webhooksUpdate: events.webhooksUpdate ?? ignore,
botUpdate: events.botUpdate ?? ignore,
typingStart: events.typingStart ?? ignore,
};
}
export async function startBot(bot: Bot) {
if (!Object.keys(bot.botGatewayData ?? {}).length) {
bot.gateway.gatewayBot = await bot.helpers.getGatewayBot();
bot.gateway.lastShardId = bot.gateway.gatewayBot.shards - 1;
bot.gateway.manager.totalShards = bot.gateway.gatewayBot.shards;
}
bot.gateway.spawnShards();
}
export function createUtils(options: Partial<HelperUtils>) {
return {
snowflakeToBigint,
bigintToSnowflake,
calculateShardId,
delay,
iconHashToBigInt,
iconBigintToHash,
validateLength,
urlToBase64,
formatImageURL,
calculateBits,
calculatePermissions,
};
}
export interface HelperUtils {
snowflakeToBigint: typeof snowflakeToBigint;
bigintToSnowflake: typeof bigintToSnowflake;
delay: typeof delay;
iconHashToBigInt: typeof iconHashToBigInt;
iconBigintToHash: typeof iconBigintToHash;
validateLength: typeof validateLength;
urlToBase64: typeof urlToBase64;
formatImageURL: typeof formatImageURL;
calculateBits: typeof calculateBits;
calculatePermissions: typeof calculatePermissions;
}
export async function stopBot(bot: Bot) {
await bot.gateway.stop(1000, "User requested bot stop");
return bot;
}
export interface CreateBotOptions {
token: string;
botId?: bigint;
applicationId?: bigint;
secretKey?: string;
events?: Partial<EventHandlers>;
intents?: GatewayIntents;
botGatewayData?: GetGatewayBot;
rest?: Omit<CreateRestManagerOptions, "token">;
handleDiscordPayload?: CreateShardManager["handleMessage"];
utils?: Partial<ReturnType<typeof createUtils>>;
transformers?: Partial<ReturnType<typeof createTransformers>>;
helpers?: Partial<Helpers>;
}
export type UnPromise<T extends Promise<unknown>> = T extends Promise<infer K> ? K
: never;
export interface Bot {
id: bigint;
applicationId: bigint;
token: string;
intents: GatewayIntents;
urlWSS: string;
botGatewayData?: GetGatewayBot;
utils: ReturnType<typeof createUtils>;
transformers: Transformers;
helpers: ReturnType<typeof createHelpers>;
rest: ReturnType<typeof createRestManager>;
gateway: ReturnType<typeof createGatewayManager>;
events: EventHandlers;
handlers: ReturnType<typeof createBotGatewayHandlers>;
activeGuildIds: Set<bigint>;
constants: ReturnType<typeof createBotConstants>;
cache: {
unrepliedInteractions: Set<bigint>;
fetchAllMembersProcessingRequests: Map<string, Function>;
};
enabledPlugins: Set<string>;
handleDiscordPayload?: CreateShardManager["handleMessage"];
}
export const defaultHelpers = { ...helpers };
export type DefaultHelpers = typeof defaultHelpers;
// deno-lint-ignore no-empty-interface
export interface Helpers extends DefaultHelpers {} // Use interface for declaration merging
export function createHelpers(
bot: Bot,
customHelpers?: Partial<Helpers>,
): FinalHelpers {
const converted = {} as FinalHelpers;
for (
const [name, fun] of Object.entries({
...createBaseHelpers(customHelpers || {}),
})
) {
// @ts-ignore - TODO: make the types better
converted[name as keyof FinalHelpers] = (
// @ts-ignore - TODO: make the types better
...args: RemoveFirstFromTuple<Parameters<typeof fun>>
) =>
// @ts-ignore - TODO: make the types better
fun(bot, ...args);
}
return converted;
}
export function createBaseHelpers(options: Partial<Helpers>) {
return {
...defaultHelpers,
...options,
};
}
export interface Transformers {
reverse: {
allowedMentions: (bot: Bot, payload: AllowedMentions) => DiscordAllowedMentions;
embed: (bot: Bot, payload: Embed) => DiscordEmbed;
component: (bot: Bot, payload: Component) => DiscordComponent;
activity: (bot: Bot, payload: Activity) => DiscordActivity;
member: (bot: Bot, payload: Member) => DiscordMember;
user: (bot: Bot, payload: User) => DiscordUser;
team: (bot: Bot, payload: Team) => DiscordTeam;
application: (bot: Bot, payload: Application) => DiscordApplication;
};
snowflake: (snowflake: string) => bigint;
gatewayBot: (payload: DiscordGetGatewayBot) => GetGatewayBot;
automodRule: (bot: Bot, payload: DiscordAutoModerationRule) => AutoModerationRule;
automodActionExecution: (bot: Bot, payload: DiscordAutoModerationActionExecution) => AutoModerationActionExecution;
channel: (bot: Bot, payload: { channel: DiscordChannel } & { guildId?: bigint }) => Channel;
guild: (bot: Bot, payload: { guild: DiscordGuild } & { shardId: number }) => Guild;
user: (bot: Bot, payload: DiscordUser) => User;
member: (bot: Bot, payload: DiscordMember, guildId: bigint, userId: bigint) => Member;
message: (bot: Bot, payload: DiscordMessage) => Message;
role: (bot: Bot, payload: { role: DiscordRole } & { guildId: bigint }) => Role;
voiceState: (bot: Bot, payload: { voiceState: DiscordVoiceState } & { guildId: bigint }) => VoiceState;
interaction: (bot: Bot, payload: DiscordInteraction) => Interaction;
interactionDataOptions: (bot: Bot, payload: DiscordInteractionDataOption) => InteractionDataOption;
integration: (bot: Bot, payload: DiscordIntegrationCreateUpdate) => Integration;
invite: (bot: Bot, invite: DiscordInviteCreate) => Invite;
application: (bot: Bot, payload: DiscordApplication) => Application;
team: (bot: Bot, payload: DiscordTeam) => Team;
emoji: (bot: Bot, payload: DiscordEmoji) => Emoji;
activity: (bot: Bot, payload: DiscordActivity) => Activity;
presence: (bot: Bot, payload: DiscordPresenceUpdate) => PresenceUpdate;
attachment: (bot: Bot, payload: DiscordAttachment) => Attachment;
embed: (bot: Bot, payload: DiscordEmbed) => Embed;
component: (bot: Bot, payload: DiscordComponent) => Component;
webhook: (bot: Bot, payload: DiscordWebhook) => Webhook;
auditLogEntry: (bot: Bot, payload: DiscordAuditLogEntry) => AuditLogEntry;
applicationCommand: (bot: Bot, payload: DiscordApplicationCommand) => ApplicationCommand;
applicationCommandOption: (bot: Bot, payload: DiscordApplicationCommandOption) => ApplicationCommandOption;
applicationCommandPermission: (
bot: Bot,
payload: DiscordGuildApplicationCommandPermissions,
) => ApplicationCommandPermission;
scheduledEvent: (bot: Bot, payload: DiscordScheduledEvent) => ScheduledEvent;
threadMember: (bot: Bot, payload: DiscordThreadMember) => ThreadMember;
welcomeScreen: (bot: Bot, payload: DiscordWelcomeScreen) => WelcomeScreen;
voiceRegion: (bot: Bot, payload: DiscordVoiceRegion) => VoiceRegions;
widget: (bot: Bot, payload: DiscordGuildWidget) => GuildWidget;
widgetSettings: (bot: Bot, payload: DiscordGuildWidgetSettings) => GuildWidgetSettings;
stageInstance: (bot: Bot, payload: DiscordStageInstance) => StageInstance;
sticker: (bot: Bot, payload: DiscordSticker) => Sticker;
stickerPack: (bot: Bot, payload: DiscordStickerPack) => StickerPack;
applicationCommandOptionChoice: (
bot: Bot,
payload: DiscordApplicationCommandOptionChoice,
) => ApplicationCommandOptionChoice;
template: (bot: Bot, payload: DiscordTemplate) => Template;
}
export function createTransformers(options: Partial<Transformers>) {
return {
reverse: {
allowedMentions: options.reverse?.allowedMentions || transformAllowedMentionsToDiscordAllowedMentions,
embed: options.reverse?.embed || transformEmbedToDiscordEmbed,
component: options.reverse?.component || transformComponentToDiscordComponent,
activity: options.reverse?.activity || transformActivityToDiscordActivity,
member: options.reverse?.member || transformMemberToDiscordMember,
user: options.reverse?.user || transformUserToDiscordUser,
team: options.reverse?.team || transformTeamToDiscordTeam,
application: options.reverse?.application || transformApplicationToDiscordApplication,
},
automodRule: options.automodRule || transformAutoModerationRule,
automodActionExecution: options.automodActionExecution || transformAutoModerationActionExecution,
activity: options.activity || transformActivity,
application: options.application || transformApplication,
attachment: options.attachment || transformAttachment,
channel: options.channel || transformChannel,
component: options.component || transformComponent,
embed: options.embed || transformEmbed,
emoji: options.emoji || transformEmoji,
guild: options.guild || transformGuild,
integration: options.integration || transformIntegration,
interaction: options.interaction || transformInteraction,
interactionDataOptions: options.interactionDataOptions || transformInteractionDataOption,
invite: options.invite || transformInvite,
member: options.member || transformMember,
message: options.message || transformMessage,
presence: options.presence || transformPresence,
role: options.role || transformRole,
user: options.user || transformUser,
team: options.team || transformTeam,
voiceState: options.voiceState || transformVoiceState,
snowflake: options.snowflake || snowflakeToBigint,
webhook: options.webhook || transformWebhook,
auditLogEntry: options.auditLogEntry || transformAuditLogEntry,
applicationCommand: options.applicationCommand ||
transformApplicationCommand,
applicationCommandOption: options.applicationCommandOption ||
transformApplicationCommandOption,
applicationCommandPermission: options.applicationCommandPermission ||
transformApplicationCommandPermission,
scheduledEvent: options.scheduledEvent || transformScheduledEvent,
threadMember: options.threadMember || transformThreadMember,
welcomeScreen: options.welcomeScreen || transformWelcomeScreen,
voiceRegion: options.voiceRegion || transformVoiceRegion,
widget: options.widget || transformWidget,
widgetSettings: options.widgetSettings || transformWidgetSettings,
stageInstance: options.stageInstance || transformStageInstance,
sticker: options.sticker || transformSticker,
stickerPack: options.stickerPack || transformStickerPack,
gatewayBot: options.gatewayBot || transformGatewayBot,
applicationCommandOptionChoice: options.applicationCommandOptionChoice || transformApplicationCommandOptionChoice,
template: options.template || transformTemplate,
};
}
export interface EventHandlers {
debug: (text: string, ...args: any[]) => unknown;
automodRuleCreate: (bot: Bot, rule: AutoModerationRule) => unknown;
automodRuleUpdate: (bot: Bot, rule: AutoModerationRule) => unknown;
automodRuleDelete: (bot: Bot, rule: AutoModerationRule) => unknown;
automodActionExecution: (bot: Bot, payload: AutoModerationActionExecution) => unknown;
threadCreate: (bot: Bot, thread: Channel) => unknown;
threadDelete: (bot: Bot, thread: Channel) => unknown;
threadMemberUpdate: (bot: Bot, payload: {
id: bigint;
guildId: bigint;
joinedAt: number;
flags: number;
}) => unknown;
threadMembersUpdate: (
bot: Bot,
payload: {
id: bigint;
guildId: bigint;
addedMembers?: ThreadMember[];
removedMemberIds?: bigint[];
},
) => unknown;
threadUpdate: (bot: Bot, thread: Channel) => unknown;
scheduledEventCreate: (bot: Bot, event: ScheduledEvent) => unknown;
scheduledEventUpdate: (bot: Bot, event: ScheduledEvent) => unknown;
scheduledEventDelete: (bot: Bot, event: ScheduledEvent) => unknown;
/** Sent when a user has subscribed to a guild scheduled event. EXPERIMENTAL! */
scheduledEventUserAdd: (
bot: Bot,
payload: {
guildScheduledEventId: bigint;
guildId: bigint;
userId: bigint;
},
) => unknown;
/** Sent when a user has unsubscribed to a guild scheduled event. EXPERIMENTAL! */
scheduledEventUserRemove: (
bot: Bot,
payload: {
guildScheduledEventId: bigint;
guildId: bigint;
userId: bigint;
},
) => unknown;
ready: (
bot: Bot,
payload: {
shardId: number;
v: number;
user: User;
guilds: bigint[];
sessionId: string;
shard?: number[];
applicationId: bigint;
},
rawPayload: DiscordReady,
) => unknown;
interactionCreate: (bot: Bot, interaction: Interaction) => unknown;
integrationCreate: (bot: Bot, integration: Integration) => unknown;
integrationDelete: (
bot: Bot,
payload: { id: bigint; guildId: bigint; applicationId?: bigint },
) => unknown;
integrationUpdate: (bot: Bot, payload: { guildId: bigint }) => unknown;
inviteCreate: (bot: Bot, invite: Invite) => unknown;
inviteDelete: (
bot: Bot,
payload: {
channelId: bigint;
guildId?: bigint;
code: string;
},
) => unknown;
guildMemberAdd: (
bot: Bot,
member: Member,
user: User,
) => unknown;
guildMemberRemove: (bot: Bot, user: User, guildId: bigint) => unknown;
guildMemberUpdate: (
bot: Bot,
member: Member,
user: User,
) => unknown;
messageCreate: (bot: Bot, message: Message) => unknown;
messageDelete: (
bot: Bot,
payload: { id: bigint; channelId: bigint; guildId?: bigint },
message?: Message,
) => unknown;
messageDeleteBulk: (bot: Bot, payload: { ids: bigint[]; channelId: bigint; guildId?: bigint }) => unknown;
messageUpdate: (
bot: Bot,
message: Message,
oldMessage?: Message,
) => unknown;
reactionAdd: (
bot: Bot,
payload: {
userId: bigint;
channelId: bigint;
messageId: bigint;
guildId?: bigint;
member?: Member;
user?: User;
emoji: Emoji;
},
) => unknown;
reactionRemove: (
bot: Bot,
payload: {
userId: bigint;
channelId: bigint;
messageId: bigint;
guildId?: bigint;
emoji: Emoji;
},
) => unknown;
reactionRemoveEmoji: (
bot: Bot,
payload: {
channelId: bigint;
messageId: bigint;
guildId?: bigint;
emoji: Emoji;
},
) => unknown;
reactionRemoveAll: (
bot: Bot,
payload: {
channelId: bigint;
messageId: bigint;
guildId?: bigint;
},
) => unknown;
presenceUpdate: (
bot: Bot,
presence: PresenceUpdate,
oldPresence?: PresenceUpdate,
) => unknown;
voiceServerUpdate: (
bot: Bot,
payload: { token: string; endpoint?: string; guildId: bigint },
) => unknown;
voiceStateUpdate: (
bot: Bot,
voiceState: VoiceState,
) => unknown;
channelCreate: (bot: Bot, channel: Channel) => unknown;
dispatchRequirements: (
bot: Bot,
data: DiscordGatewayPayload,
shardId: number,
) => unknown;
channelDelete: (bot: Bot, channel: Channel) => unknown;
channelPinsUpdate: (
bot: Bot,
data: { guildId?: bigint; channelId: bigint; lastPinTimestamp?: number },
) => unknown;
channelUpdate: (bot: Bot, channel: Channel) => unknown;
stageInstanceCreate: (
bot: Bot,
data: {
id: bigint;
guildId: bigint;
channelId: bigint;
topic: string;
},
) => unknown;
stageInstanceDelete: (
bot: Bot,
data: {
id: bigint;
guildId: bigint;
channelId: bigint;
topic: string;
},
) => unknown;
stageInstanceUpdate: (
bot: Bot,
data: {
id: bigint;
guildId: bigint;
channelId: bigint;
topic: string;
},
) => unknown;
guildEmojisUpdate: (
bot: Bot,
payload: {
guildId: bigint;
emojis: BotCollection<bigint, DiscordEmoji>;
},
) => unknown;
guildBanAdd: (bot: Bot, user: User, guildId: bigint) => unknown;
guildBanRemove: (bot: Bot, user: User, guildId: bigint) => unknown;
guildLoaded: (bot: Bot, guild: Guild) => unknown;
guildCreate: (bot: Bot, guild: Guild) => unknown;
guildDelete: (bot: Bot, id: bigint, shardId: number) => unknown;
guildUpdate: (bot: Bot, guild: Guild) => unknown;
raw: (bot: Bot, data: DiscordGatewayPayload, shardId: number) => unknown;
roleCreate: (bot: Bot, role: Role) => unknown;
roleDelete: (bot: Bot, payload: { guildId: bigint; roleId: bigint }) => unknown;
roleUpdate: (bot: Bot, role: Role) => unknown;
webhooksUpdate: (
bot: Bot,
payload: { channelId: bigint; guildId: bigint },
) => unknown;
botUpdate: (bot: Bot, user: User) => unknown;
typingStart: (
bot: Bot,
payload: {
guildId: bigint | undefined;
channelId: bigint;
userId: bigint;
timestamp: number;
member: Member | undefined;
},
) => unknown;
}
export function createBotConstants() {
return {
DISCORDENO_VERSION,
USER_AGENT,
BASE_URL: baseEndpoints.BASE_URL,
CDN_URL: baseEndpoints.CDN_URL,
routes,
regexes: {
SLASH_COMMANDS_NAME_REGEX,
CONTEXT_MENU_COMMANDS_NAME_REGEX,
CHANNEL_MENTION_REGEX,
DISCORD_SNOWFLAKE_REGEX,
},
Errors,
};
}
export interface BotGatewayHandlerOptions {
READY: typeof handlers.handleReady;
CHANNEL_CREATE: typeof handlers.handleChannelCreate;
CHANNEL_DELETE: typeof handlers.handleChannelDelete;
CHANNEL_PINS_UPDATE: typeof handlers.handleChannelPinsUpdate;
CHANNEL_UPDATE: typeof handlers.handleChannelUpdate;
THREAD_CREATE: typeof handlers.handleThreadCreate;
THREAD_UPDATE: typeof handlers.handleThreadUpdate;
THREAD_DELETE: typeof handlers.handleThreadDelete;
THREAD_LIST_SYNC: typeof handlers.handleThreadListSync;
THREAD_MEMBERS_UPDATE: typeof handlers.handleThreadMembersUpdate;
STAGE_INSTANCE_CREATE: typeof handlers.handleStageInstanceCreate;
STAGE_INSTANCE_UPDATE: typeof handlers.handleStageInstanceUpdate;
STAGE_INSTANCE_DELETE: typeof handlers.handleStageInstanceDelete;
GUILD_BAN_ADD: typeof handlers.handleGuildBanAdd;
GUILD_BAN_REMOVE: typeof handlers.handleGuildBanRemove;
GUILD_CREATE: typeof handlers.handleGuildCreate;
GUILD_LOADED_DD: typeof handlers.handleGuildLoaded;
GUILD_DELETE: typeof handlers.handleGuildDelete;
GUILD_EMOJIS_UPDATE: typeof handlers.handleGuildEmojisUpdate;
GUILD_INTEGRATIONS_UPDATE: typeof handlers.handleGuildIntegrationsUpdate;
GUILD_MEMBER_ADD: typeof handlers.handleGuildMemberAdd;
GUILD_MEMBER_REMOVE: typeof handlers.handleGuildMemberRemove;
GUILD_MEMBER_UPDATE: typeof handlers.handleGuildMemberUpdate;
GUILD_MEMBERS_CHUNK: typeof handlers.handleGuildMembersChunk;
GUILD_ROLE_CREATE: typeof handlers.handleGuildRoleCreate;
GUILD_ROLE_DELETE: typeof handlers.handleGuildRoleDelete;
GUILD_ROLE_UPDATE: typeof handlers.handleGuildRoleUpdate;
GUILD_SCHEDULED_EVENT_CREATE: typeof handlers.handleGuildScheduledEventCreate;
GUILD_SCHEDULED_EVENT_DELETE: typeof handlers.handleGuildScheduledEventDelete;
GUILD_SCHEDULED_EVENT_UPDATE: typeof handlers.handleGuildScheduledEventUpdate;
GUILD_SCHEDULED_EVENT_USER_ADD: typeof handlers.handleGuildScheduledEventUserAdd;
GUILD_SCHEDULED_EVENT_USER_REMOVE: typeof handlers.handleGuildScheduledEventUserRemove;
GUILD_UPDATE: typeof handlers.handleGuildUpdate;
INTERACTION_CREATE: typeof handlers.handleInteractionCreate;
INVITE_CREATE: typeof handlers.handleInviteCreate;
INVITE_DELETE: typeof handlers.handleInviteCreate;
MESSAGE_CREATE: typeof handlers.handleMessageCreate;
MESSAGE_DELETE_BULK: typeof handlers.handleMessageDeleteBulk;
MESSAGE_DELETE: typeof handlers.handleMessageDelete;
MESSAGE_REACTION_ADD: typeof handlers.handleMessageReactionAdd;
MESSAGE_REACTION_REMOVE_ALL: typeof handlers.handleMessageReactionRemoveAll;
MESSAGE_REACTION_REMOVE_EMOJI: typeof handlers.handleMessageReactionRemoveEmoji;
MESSAGE_REACTION_REMOVE: typeof handlers.handleMessageReactionRemove;
MESSAGE_UPDATE: typeof handlers.handleMessageUpdate;
PRESENCE_UPDATE: typeof handlers.handlePresenceUpdate;
TYPING_START: typeof handlers.handleTypingStart;
USER_UPDATE: typeof handlers.handleUserUpdate;
VOICE_SERVER_UPDATE: typeof handlers.handleVoiceServerUpdate;
VOICE_STATE_UPDATE: typeof handlers.handleVoiceStateUpdate;
WEBHOOKS_UPDATE: typeof handlers.handleWebhooksUpdate;
INTEGRATION_CREATE: typeof handlers.handleIntegrationCreate;
INTEGRATION_UPDATE: typeof handlers.handleIntegrationUpdate;
INTEGRATION_DELETE: typeof handlers.handleIntegrationDelete;
}
export function createBotGatewayHandlers(
options: Partial<BotGatewayHandlerOptions>,
): Record<
GatewayDispatchEventNames | "GUILD_LOADED_DD",
(bot: Bot, data: DiscordGatewayPayload, shardId: number) => any
> {
return {
// misc
READY: options.READY ?? handlers.handleReady,
// channels
CHANNEL_CREATE: options.CHANNEL_CREATE ?? handlers.handleChannelCreate,
CHANNEL_DELETE: options.CHANNEL_DELETE ?? handlers.handleChannelDelete,
CHANNEL_PINS_UPDATE: options.CHANNEL_PINS_UPDATE ??
handlers.handleChannelPinsUpdate,
CHANNEL_UPDATE: options.CHANNEL_UPDATE ?? handlers.handleChannelUpdate,
THREAD_CREATE: options.THREAD_CREATE ?? handlers.handleThreadCreate,
THREAD_UPDATE: options.THREAD_UPDATE ?? handlers.handleThreadUpdate,
THREAD_DELETE: options.THREAD_DELETE ?? handlers.handleThreadDelete,
THREAD_LIST_SYNC: options.THREAD_LIST_SYNC ?? handlers.handleThreadListSync,
THREAD_MEMBERS_UPDATE: options.THREAD_MEMBERS_UPDATE ?? handlers.handleThreadMembersUpdate,
STAGE_INSTANCE_CREATE: options.STAGE_INSTANCE_CREATE ??
handlers.handleStageInstanceCreate,
STAGE_INSTANCE_UPDATE: options.STAGE_INSTANCE_UPDATE ??
handlers.handleStageInstanceUpdate,
STAGE_INSTANCE_DELETE: options.STAGE_INSTANCE_DELETE ??
handlers.handleStageInstanceDelete,
// guilds
GUILD_BAN_ADD: options.GUILD_BAN_ADD ?? handlers.handleGuildBanAdd,
GUILD_BAN_REMOVE: options.GUILD_BAN_REMOVE ?? handlers.handleGuildBanRemove,
GUILD_CREATE: options.GUILD_CREATE ?? handlers.handleGuildCreate,
GUILD_LOADED_DD: options.GUILD_LOADED_DD ?? handlers.handleGuildLoaded,
GUILD_DELETE: options.GUILD_DELETE ?? handlers.handleGuildDelete,
GUILD_EMOJIS_UPDATE: options.GUILD_EMOJIS_UPDATE ??
handlers.handleGuildEmojisUpdate,
GUILD_INTEGRATIONS_UPDATE: options.GUILD_INTEGRATIONS_UPDATE ??
handlers.handleGuildIntegrationsUpdate,
GUILD_MEMBER_ADD: options.GUILD_MEMBER_ADD ?? handlers.handleGuildMemberAdd,
GUILD_MEMBER_REMOVE: options.GUILD_MEMBER_REMOVE ??
handlers.handleGuildMemberRemove,
GUILD_MEMBER_UPDATE: options.GUILD_MEMBER_UPDATE ??
handlers.handleGuildMemberUpdate,
GUILD_MEMBERS_CHUNK: options.GUILD_MEMBERS_CHUNK ??
handlers.handleGuildMembersChunk,
GUILD_ROLE_CREATE: options.GUILD_ROLE_CREATE ??
handlers.handleGuildRoleCreate,
GUILD_ROLE_DELETE: options.GUILD_ROLE_DELETE ??
handlers.handleGuildRoleDelete,
GUILD_ROLE_UPDATE: options.GUILD_ROLE_UPDATE ??
handlers.handleGuildRoleUpdate,
GUILD_UPDATE: options.GUILD_UPDATE ?? handlers.handleGuildUpdate,
// guild events
GUILD_SCHEDULED_EVENT_CREATE: options.GUILD_SCHEDULED_EVENT_CREATE ??
handlers.handleGuildScheduledEventCreate,
GUILD_SCHEDULED_EVENT_DELETE: options.GUILD_SCHEDULED_EVENT_DELETE ??
handlers.handleGuildScheduledEventDelete,
GUILD_SCHEDULED_EVENT_UPDATE: options.GUILD_SCHEDULED_EVENT_UPDATE ??
handlers.handleGuildScheduledEventUpdate,
GUILD_SCHEDULED_EVENT_USER_ADD: options.GUILD_SCHEDULED_EVENT_USER_ADD ??
handlers.handleGuildScheduledEventUserAdd,
GUILD_SCHEDULED_EVENT_USER_REMOVE: options.GUILD_SCHEDULED_EVENT_USER_REMOVE ??
handlers.handleGuildScheduledEventUserRemove,
// interactions
INTERACTION_CREATE: options.INTERACTION_CREATE ??
handlers.handleInteractionCreate,
// invites
INVITE_CREATE: options.INVITE_CREATE ?? handlers.handleInviteCreate,
INVITE_DELETE: options.INVITE_DELETE ?? handlers.handleInviteCreate,
// messages
MESSAGE_CREATE: options.MESSAGE_CREATE ?? handlers.handleMessageCreate,
MESSAGE_DELETE_BULK: options.MESSAGE_DELETE_BULK ??
handlers.handleMessageDeleteBulk,
MESSAGE_DELETE: options.MESSAGE_DELETE ?? handlers.handleMessageDelete,
MESSAGE_REACTION_ADD: options.MESSAGE_REACTION_ADD ??
handlers.handleMessageReactionAdd,
MESSAGE_REACTION_REMOVE_ALL: options.MESSAGE_REACTION_REMOVE_ALL ??
handlers.handleMessageReactionRemoveAll,
MESSAGE_REACTION_REMOVE_EMOJI: options.MESSAGE_REACTION_REMOVE_EMOJI ??
handlers.handleMessageReactionRemoveEmoji,
MESSAGE_REACTION_REMOVE: options.MESSAGE_REACTION_REMOVE ??
handlers.handleMessageReactionRemove,
MESSAGE_UPDATE: options.MESSAGE_UPDATE ?? handlers.handleMessageUpdate,
// presence
PRESENCE_UPDATE: options.PRESENCE_UPDATE ?? handlers.handlePresenceUpdate,
TYPING_START: options.TYPING_START ?? handlers.handleTypingStart,
USER_UPDATE: options.USER_UPDATE ?? handlers.handleUserUpdate,
// voice
VOICE_SERVER_UPDATE: options.VOICE_SERVER_UPDATE ??
handlers.handleVoiceServerUpdate,
VOICE_STATE_UPDATE: options.VOICE_STATE_UPDATE ??
handlers.handleVoiceStateUpdate,
// webhooks
WEBHOOKS_UPDATE: options.WEBHOOKS_UPDATE ?? handlers.handleWebhooksUpdate,
// integrations
INTEGRATION_CREATE: options.INTEGRATION_CREATE ??
handlers.handleIntegrationCreate,
INTEGRATION_UPDATE: options.INTEGRATION_UPDATE ??
handlers.handleIntegrationUpdate,
INTEGRATION_DELETE: options.INTEGRATION_DELETE ??
handlers.handleIntegrationDelete,
};
}
export type RemoveFirstFromTuple<T extends any[]> = T["length"] extends 0 ? []
: ((...b: T) => void) extends (a: any, ...b: infer I) => void ? I
: [];
export type FinalHelpers = {
[K in keyof Helpers]: (
...args: RemoveFirstFromTuple<Parameters<Helpers[K]>>
) => ReturnType<Helpers[K]>;
};
-1
View File
@@ -1 +0,0 @@
export * from "../../mod.ts";
@@ -1,8 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordChannel, DiscordGatewayPayload } from "../../deps.ts";
export async function handleChannelCreate(bot: Bot, payload: DiscordGatewayPayload) {
const channel = bot.transformers.channel(bot, { channel: payload.d as DiscordChannel });
bot.events.channelCreate(bot, channel);
}
@@ -1,15 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordChannel, DiscordGatewayPayload } from "../../deps.ts";
export async function handleChannelDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordChannel;
if (!payload.guild_id) return;
bot.events.channelDelete(
bot,
bot.transformers.channel(bot, {
channel: payload,
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
}),
);
}
@@ -1,12 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordChannelPinsUpdate, DiscordGatewayPayload } from "../../deps.ts";
export async function handleChannelPinsUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordChannelPinsUpdate;
bot.events.channelPinsUpdate(bot, {
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
channelId: bot.transformers.snowflake(payload.channel_id),
lastPinTimestamp: payload.last_pin_timestamp ? Date.parse(payload.last_pin_timestamp) : undefined,
});
}
@@ -1,9 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordChannel, DiscordGatewayPayload } from "../../deps.ts";
export async function handleChannelUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordChannel;
const channel = bot.transformers.channel(bot, { channel: payload });
bot.events.channelUpdate(bot, channel);
}
@@ -1,13 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordStageInstance } from "../../deps.ts";
export function handleStageInstanceCreate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordStageInstance;
bot.events.stageInstanceCreate(bot, {
id: bot.transformers.snowflake(payload.id),
guildId: bot.transformers.snowflake(payload.guild_id),
channelId: bot.transformers.snowflake(payload.channel_id),
topic: payload.topic,
});
}
@@ -1,13 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordStageInstance } from "../../deps.ts";
export function handleStageInstanceDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordStageInstance;
bot.events.stageInstanceDelete(bot, {
id: bot.transformers.snowflake(payload.id),
guildId: bot.transformers.snowflake(payload.guild_id),
channelId: bot.transformers.snowflake(payload.channel_id),
topic: payload.topic,
});
}
@@ -1,13 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordStageInstance } from "../../deps.ts";
export function handleStageInstanceUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordStageInstance;
bot.events.stageInstanceUpdate(bot, {
id: bot.transformers.snowflake(payload.id),
guildId: bot.transformers.snowflake(payload.guild_id),
channelId: bot.transformers.snowflake(payload.channel_id),
topic: payload.topic,
});
}
@@ -1,8 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordChannel, DiscordGatewayPayload } from "../../deps.ts";
export async function handleThreadCreate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordChannel;
bot.events.threadCreate(bot, bot.transformers.channel(bot, { channel: payload }));
}
@@ -1,7 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordChannel, DiscordGatewayPayload } from "../../deps.ts";
export async function handleThreadDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordChannel;
bot.events.threadDelete(bot, bot.transformers.channel(bot, { channel: payload }));
}
@@ -1,18 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordThreadListSync } from "../../deps.ts";
export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordThreadListSync;
const guildId = bot.transformers.snowflake(payload.guild_id);
return {
guildId,
channelIds: payload.channel_ids?.map((id) => bot.transformers.snowflake(id)),
threads: payload.threads.map((thread) => bot.transformers.channel(bot, { channel: thread, guildId })),
members: payload.members.map((member) => ({
id: member.id ? bot.transformers.snowflake(member.id) : undefined,
userId: member.user_id ? bot.transformers.snowflake(member.user_id) : undefined,
joinTimestamp: Date.parse(member.join_timestamp),
})),
};
}
@@ -1,12 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordThreadMembersUpdate } from "../../deps.ts";
export async function handleThreadMembersUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordThreadMembersUpdate;
bot.events.threadMembersUpdate(bot, {
id: bot.transformers.snowflake(payload.id),
guildId: bot.transformers.snowflake(payload.guild_id),
addedMembers: payload.added_members?.map((member) => bot.transformers.threadMember(bot, member)),
removedMemberIds: payload.removed_member_ids?.map((id) => bot.transformers.snowflake(id)),
});
}
@@ -1,13 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordThreadMemberUpdate } from "../../deps.ts";
export async function handleThreadMemberUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordThreadMemberUpdate;
bot.events.threadMemberUpdate(bot, {
id: bot.transformers.snowflake(payload.id),
guildId: bot.transformers.snowflake(payload.guild_id),
joinedAt: Date.parse(payload.joined_at),
flags: payload.flags,
});
}
@@ -1,8 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordChannel, DiscordGatewayPayload } from "../../deps.ts";
export async function handleThreadUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordChannel;
bot.events.threadUpdate(bot, bot.transformers.channel(bot, { channel: payload }));
}
-12
View File
@@ -1,12 +0,0 @@
export * from "./CHANNEL_CREATE.ts";
export * from "./CHANNEL_DELETE.ts";
export * from "./CHANNEL_PINS_UPDATE.ts";
export * from "./CHANNEL_UPDATE.ts";
export * from "./STAGE_INSTANCE_CREATE.ts";
export * from "./STAGE_INSTANCE_DELETE.ts";
export * from "./STAGE_INSTANCE_UPDATE.ts";
export * from "./THREAD_CREATE.ts";
export * from "./THREAD_DELETE.ts";
export * from "./THREAD_LIST_SYNC.ts";
export * from "./THREAD_MEMBERS_UPDATE.ts";
export * from "./THREAD_UPDATE.ts";
@@ -1,12 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordGuildEmojisUpdate } from "../../deps.ts";
import { BotCollection as Collection } from "../../util/collection.ts";
export async function handleGuildEmojisUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildEmojisUpdate;
bot.events.guildEmojisUpdate(bot, {
guildId: bot.transformers.snowflake(payload.guild_id),
emojis: new Collection(payload.emojis.map((emoji) => [bot.transformers.snowflake(emoji.id!), emoji])),
});
}
-1
View File
@@ -1 +0,0 @@
export * from "./GUILD_EMOJIS_UPDATE.ts";
@@ -1,7 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordGuildBanAddRemove } from "../../deps.ts";
export async function handleGuildBanAdd(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildBanAddRemove;
bot.events.guildBanAdd(bot, bot.transformers.user(bot, payload.user), bot.transformers.snowflake(payload.guild_id));
}
@@ -1,12 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordGuildBanAddRemove } from "../../deps.ts";
export async function handleGuildBanRemove(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildBanAddRemove;
await bot.events.guildBanRemove(
bot,
bot.transformers.user(bot, payload.user),
bot.transformers.snowflake(payload.guild_id),
);
}
@@ -1,8 +0,0 @@
import { Bot } from "../../bot.ts";
import type { Guild } from "../../transformers/guild.ts";
import { DiscordGatewayPayload, DiscordGuild } from "../../deps.ts";
export function handleGuildCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as DiscordGuild;
bot.events.guildCreate(bot, bot.transformers.guild(bot, { guild: payload, shardId }) as Guild);
}
@@ -1,7 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordUnavailableGuild } from "../../deps.ts";
export async function handleGuildDelete(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as DiscordUnavailableGuild;
bot.events.guildDelete(bot, bot.transformers.snowflake(payload.id), shardId);
}
@@ -1,8 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordGuildIntegrationsUpdate } from "../../deps.ts";
export async function handleGuildIntegrationsUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildIntegrationsUpdate;
bot.events.integrationUpdate(bot, { guildId: bot.transformers.snowflake(payload.guild_id) });
}
@@ -1,10 +0,0 @@
import { Bot } from "../../bot.ts";
import type { Guild } from "../../transformers/guild.ts";
import { DiscordGatewayPayload, DiscordGuild } from "../../deps.ts";
export function handleGuildLoaded(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as DiscordGuild;
const guild = bot.transformers.guild(bot, { guild: payload, shardId });
bot.events.guildLoaded(bot, guild as Guild);
}
@@ -1,9 +0,0 @@
import { Bot } from "../../bot.ts";
import type { Guild } from "../../transformers/guild.ts";
import { DiscordGatewayPayload, DiscordGuild } from "../../deps.ts";
export function handleGuildUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as DiscordGuild;
bot.events.guildUpdate(bot, bot.transformers.guild(bot, { guild: payload, shardId }) as Guild);
}
@@ -1,8 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordAutoModerationActionExecution, DiscordGatewayPayload } from "../../../deps.ts";
/** Requires the MANAGE_GUILD permission. */
export function handleAutoModerationActionExecution(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as DiscordAutoModerationActionExecution;
bot.events.automodActionExecution(bot, bot.transformers.automodActionExecution(bot, payload));
}
@@ -1,8 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordAutoModerationRule, DiscordGatewayPayload } from "../../../deps.ts";
/** Requires the MANAGE_GUILD permission. */
export function handleAutoModerationRuleCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as DiscordAutoModerationRule;
bot.events.automodRuleCreate(bot, bot.transformers.automodRule(bot, payload));
}
@@ -1,8 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordAutoModerationRule, DiscordGatewayPayload } from "../../../deps.ts";
/** Requires the MANAGE_GUILD permission. */
export function handleAutoModerationRuleDelete(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as DiscordAutoModerationRule;
bot.events.automodRuleDelete(bot, bot.transformers.automodRule(bot, payload));
}
@@ -1,8 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordAutoModerationRule, DiscordGatewayPayload } from "../../../deps.ts";
/** Requires the MANAGE_GUILD permission. */
export function handleAutoModerationRuleUpdate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as DiscordAutoModerationRule;
bot.events.automodRuleUpdate(bot, bot.transformers.automodRule(bot, payload));
}
-9
View File
@@ -1,9 +0,0 @@
export * from "./scheduledEvents/mod.ts";
export * from "./GUILD_BAN_ADD.ts";
export * from "./GUILD_BAN_REMOVE.ts";
export * from "./GUILD_CREATE.ts";
export * from "./GUILD_DELETE.ts";
export * from "./GUILD_INTEGRATIONS_UPDATE.ts";
export * from "./GUILD_LOADED_DD.ts";
export * from "./GUILD_UPDATE.ts";
@@ -1,7 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../deps.ts";
export function handleGuildScheduledEventCreate(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as DiscordScheduledEvent;
bot.events.scheduledEventCreate(bot, bot.transformers.scheduledEvent(bot, payload));
}
@@ -1,7 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../deps.ts";
export function handleGuildScheduledEventDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordScheduledEvent;
bot.events.scheduledEventDelete(bot, bot.transformers.scheduledEvent(bot, payload));
}
@@ -1,7 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordGatewayPayload, DiscordScheduledEvent } from "../../../deps.ts";
export function handleGuildScheduledEventUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordScheduledEvent;
bot.events.scheduledEventUpdate(bot, bot.transformers.scheduledEvent(bot, payload));
}
@@ -1,12 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordGatewayPayload, DiscordScheduledEventUserAdd } from "../../../deps.ts";
export function handleGuildScheduledEventUserAdd(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordScheduledEventUserAdd;
return bot.events.scheduledEventUserAdd(bot, {
guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id),
userId: bot.transformers.snowflake(payload.user_id),
guildId: bot.transformers.snowflake(payload.guild_id),
});
}
@@ -1,12 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordGatewayPayload, DiscordScheduledEventUserRemove } from "../../../deps.ts";
export function handleGuildScheduledEventUserRemove(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordScheduledEventUserRemove;
return bot.events.scheduledEventUserRemove(bot, {
guildScheduledEventId: bot.transformers.snowflake(payload.guild_scheduled_event_id),
userId: bot.transformers.snowflake(payload.user_id),
guildId: bot.transformers.snowflake(payload.guild_id),
});
}
@@ -1,5 +0,0 @@
export * from "./GUILD_SCHEDULED_EVENT_CREATE.ts";
export * from "./GUILD_SCHEDULED_EVENT_DELETE.ts";
export * from "./GUILD_SCHEDULED_EVENT_UPDATE.ts";
export * from "./GUILD_SCHEDULED_EVENT_USER_ADD.ts";
export * from "./GUILD_SCHEDULED_EVENT_USER_REMOVE.ts";
@@ -1,9 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from "../../deps.ts";
export function handleIntegrationCreate(bot: Bot, data: DiscordGatewayPayload) {
bot.events.integrationCreate(
bot,
bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate),
);
}
@@ -1,12 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordIntegrationDelete } from "../../deps.ts";
export function handleIntegrationDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordIntegrationDelete;
bot.events.integrationDelete(bot, {
id: bot.transformers.snowflake(payload.id),
guildId: bot.transformers.snowflake(payload.guild_id),
applicationId: payload.application_id ? bot.transformers.snowflake(payload.application_id) : undefined,
});
}
@@ -1,9 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordIntegrationCreateUpdate } from "../../deps.ts";
export function handleIntegrationUpdate(bot: Bot, data: DiscordGatewayPayload) {
bot.events.integrationUpdate(
bot,
bot.transformers.integration(bot, data.d as DiscordIntegrationCreateUpdate),
);
}
-3
View File
@@ -1,3 +0,0 @@
export * from "./INTEGRATION_CREATE.ts";
export * from "./INTEGRATION_DELETE.ts";
export * from "./INTEGRATION_UPDATE.ts";
@@ -1,7 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordInteraction } from "../../deps.ts";
export async function handleInteractionCreate(bot: Bot, data: DiscordGatewayPayload) {
bot.cache.unrepliedInteractions.add(bot.transformers.snowflake((data.d as DiscordInteraction).id));
bot.events.interactionCreate(bot, bot.transformers.interaction(bot, data.d as DiscordInteraction));
}
-1
View File
@@ -1 +0,0 @@
export * from "./INTERACTION_CREATE.ts";
@@ -1,6 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordInviteCreate } from "../../deps.ts";
export function handleInviteCreate(bot: Bot, data: DiscordGatewayPayload) {
bot.events.inviteCreate(bot, bot.transformers.invite(bot, data.d as DiscordInviteCreate));
}
@@ -1,15 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordInviteDelete } from "../../deps.ts";
export function handleInviteDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordInviteDelete;
bot.events.inviteDelete(bot, {
/** The channel of the invite */
channelId: bot.transformers.snowflake(payload.channel_id),
/** The guild of the invite */
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
/** The unique invite code */
code: payload.code,
});
}
-2
View File
@@ -1,2 +0,0 @@
export * from "./INVITE_CREATE.ts";
export * from "./INVITE_DELETE.ts";
@@ -1,37 +0,0 @@
import { Bot } from "../../bot.ts";
import { statusTypes } from "../../transformers/presence.ts";
import { DiscordGatewayPayload, DiscordGuildMembersChunk } from "../../deps.ts";
export async function handleGuildMembersChunk(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildMembersChunk;
const guildId = bot.transformers.snowflake(payload.guild_id);
if (payload.nonce && payload.chunk_index >= payload.chunk_count - 1) {
bot.cache.fetchAllMembersProcessingRequests.get(payload.nonce)?.(
`Member fetching complete. Nonce: ${payload.nonce}`,
);
}
return {
guildId,
members: payload.members.map((m) =>
bot.transformers.member(bot, m, guildId, bot.transformers.snowflake(m.user.id))
),
chunkIndex: payload.chunk_index,
chunkCount: payload.chunk_count,
notFound: payload.not_found?.map((id) => bot.transformers.snowflake(id)),
presences: payload.presences?.map((presence) => ({
user: bot.transformers.user(bot, presence.user),
guildId,
status: statusTypes[presence.status],
activities: presence.activities.map((activity) => bot.transformers.activity(bot, activity)),
clientStatus: {
desktop: presence.client_status.desktop,
mobile: presence.client_status.mobile,
web: presence.client_status.web,
},
})),
nonce: payload.nonce,
};
}
@@ -1,10 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordGuildMemberAdd } from "../../deps.ts";
export async function handleGuildMemberAdd(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildMemberAdd;
const guildId = bot.transformers.snowflake(payload.guild_id);
const user = bot.transformers.user(bot, payload.user);
const member = bot.transformers.member(bot, payload, guildId, user.id);
bot.events.guildMemberAdd(bot, member, user);
}
@@ -1,10 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordGuildMemberRemove } from "../../deps.ts";
export async function handleGuildMemberRemove(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildMemberRemove;
const guildId = bot.transformers.snowflake(payload.guild_id);
const user = bot.transformers.user(bot, payload.user);
bot.events.guildMemberRemove(bot, user, guildId);
}
@@ -1,13 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordGuildMemberUpdate } from "../../deps.ts";
export async function handleGuildMemberUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildMemberUpdate;
const user = bot.transformers.user(bot, payload.user);
bot.events.guildMemberUpdate(
bot,
bot.transformers.member(bot, payload, bot.transformers.snowflake(payload.guild_id), user.id),
user,
);
}
-4
View File
@@ -1,4 +0,0 @@
export * from "./GUILD_MEMBER_ADD.ts";
export * from "./GUILD_MEMBER_REMOVE.ts";
export * from "./GUILD_MEMBER_UPDATE.ts";
export * from "./GUILD_MEMBERS_CHUNK.ts";
@@ -1,8 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordMessage } from "../../deps.ts";
export async function handleMessageCreate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessage;
bot.events.messageCreate(bot, bot.transformers.message(bot, payload));
}
@@ -1,12 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordMessageDelete } from "../../deps.ts";
export async function handleMessageDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessageDelete;
bot.events.messageDelete(bot, {
id: bot.transformers.snowflake(payload.id),
channelId: bot.transformers.snowflake(payload.channel_id),
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
});
}
@@ -1,15 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordMessageDeleteBulk } from "../../deps.ts";
export async function handleMessageDeleteBulk(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessageDeleteBulk;
const channelId = bot.transformers.snowflake(payload.channel_id);
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined;
bot.events.messageDeleteBulk(bot, {
ids: payload.ids.map((id) => bot.transformers.snowflake(id)),
channelId: bot.transformers.snowflake(payload.channel_id),
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
});
}
@@ -1,18 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordMessageReactionAdd } from "../../deps.ts";
export async function handleMessageReactionAdd(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessageReactionAdd;
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined;
const userId = bot.transformers.snowflake(payload.user_id);
bot.events.reactionAdd(bot, {
userId,
channelId: bot.transformers.snowflake(payload.channel_id),
messageId: bot.transformers.snowflake(payload.message_id),
guildId,
member: payload.member && guildId ? bot.transformers.member(bot, payload.member, guildId, userId) : undefined,
user: payload.member ? bot.transformers.user(bot, payload.member.user) : undefined,
emoji: bot.transformers.emoji(bot, payload.emoji),
});
}
@@ -1,14 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordMessageReactionRemove } from "../../deps.ts";
export async function handleMessageReactionRemove(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessageReactionRemove;
bot.events.reactionRemove(bot, {
userId: bot.transformers.snowflake(payload.user_id),
channelId: bot.transformers.snowflake(payload.channel_id),
messageId: bot.transformers.snowflake(payload.message_id),
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
emoji: bot.transformers.emoji(bot, payload.emoji),
});
}
@@ -1,12 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordMessageReactionRemoveAll } from "../../deps.ts";
export async function handleMessageReactionRemoveAll(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessageReactionRemoveAll;
bot.events.reactionRemoveAll(bot, {
channelId: bot.transformers.snowflake(payload.channel_id),
messageId: bot.transformers.snowflake(payload.message_id),
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
});
}
@@ -1,13 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordMessageReactionRemoveEmoji } from "../../deps.ts";
export async function handleMessageReactionRemoveEmoji(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessageReactionRemoveEmoji;
bot.events.reactionRemoveEmoji(bot, {
channelId: bot.transformers.snowflake(payload.channel_id),
messageId: bot.transformers.snowflake(payload.message_id),
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
emoji: bot.transformers.emoji(bot, payload.emoji),
});
}
@@ -1,9 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordMessage } from "../../deps.ts";
export async function handleMessageUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordMessage;
if (!payload.edited_timestamp) return;
bot.events.messageUpdate(bot, bot.transformers.message(bot, payload));
}
-8
View File
@@ -1,8 +0,0 @@
export * from "./MESSAGE_CREATE.ts";
export * from "./MESSAGE_DELETE_BULK.ts";
export * from "./MESSAGE_DELETE.ts";
export * from "./MESSAGE_REACTION_ADD.ts";
export * from "./MESSAGE_REACTION_REMOVE_ALL.ts";
export * from "./MESSAGE_REACTION_REMOVE_EMOJI.ts";
export * from "./MESSAGE_REACTION_REMOVE.ts";
export * from "./MESSAGE_UPDATE.ts";
@@ -1,6 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordPresenceUpdate } from "../../deps.ts";
export async function handlePresenceUpdate(bot: Bot, data: DiscordGatewayPayload) {
bot.events.presenceUpdate(bot, bot.transformers.presence(bot, data.d as DiscordPresenceUpdate));
}
-23
View File
@@ -1,23 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordReady } from "../../deps.ts";
export function handleReady(bot: Bot, data: DiscordGatewayPayload, shardId: number) {
const payload = data.d as DiscordReady;
// Triggered on each shard
bot.events.ready(
bot,
{
shardId,
v: payload.v,
user: bot.transformers.user(bot, payload.user),
guilds: payload.guilds.map((p) => bot.transformers.snowflake(p.id)),
sessionId: payload.session_id,
shard: payload.shard,
applicationId: bot.transformers.snowflake(payload.application.id),
},
payload,
);
if (!bot.id) bot.id = bot.transformers.snowflake(payload.user.id);
if (!bot.applicationId) bot.applicationId = bot.transformers.snowflake(payload.application.id);
}
-17
View File
@@ -1,17 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordTypingStart } from "../../deps.ts";
export function handleTypingStart(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordTypingStart;
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined;
const userId = bot.transformers.snowflake(payload.user_id);
bot.events.typingStart(bot, {
guildId,
channelId: bot.transformers.snowflake(payload.channel_id),
userId,
timestamp: payload.timestamp,
member: payload.member && guildId ? bot.transformers.member(bot, payload.member, guildId, userId) : undefined,
});
}
-7
View File
@@ -1,7 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordUser } from "../../deps.ts";
export async function handleUserUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordUser;
bot.events.botUpdate(bot, bot.transformers.user(bot, payload));
}
-4
View File
@@ -1,4 +0,0 @@
export * from "./PRESENCE_UPDATE.ts";
export * from "./READY.ts";
export * from "./TYPING_START.ts";
export * from "./USER_UPDATE.ts";
-12
View File
@@ -1,12 +0,0 @@
export * from "./channels/mod.ts";
export * from "./emojis/mod.ts";
export * from "./guilds/mod.ts";
export * from "./integrations/mod.ts";
export * from "./interactions/mod.ts";
export * from "./invites/mod.ts";
export * from "./members/mod.ts";
export * from "./messages/mod.ts";
export * from "./misc/mod.ts";
export * from "./roles/mod.ts";
export * from "./voice/mod.ts";
export * from "./webhooks/mod.ts";
@@ -1,10 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordGuildRoleCreate } from "../../deps.ts";
export async function handleGuildRoleCreate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildRoleCreate;
bot.events.roleCreate(
bot,
bot.transformers.role(bot, { role: payload.role, guildId: bot.transformers.snowflake(payload.guild_id) }),
);
}
@@ -1,10 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordGuildRoleDelete } from "../../deps.ts";
export async function handleGuildRoleDelete(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildRoleDelete;
bot.events.roleDelete(bot, {
roleId: bot.transformers.snowflake(payload.role_id),
guildId: bot.transformers.snowflake(payload.guild_id),
});
}
@@ -1,11 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordGuildRoleUpdate } from "../../deps.ts";
export async function handleGuildRoleUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordGuildRoleUpdate;
bot.events.roleUpdate(
bot,
bot.transformers.role(bot, { role: payload.role, guildId: bot.transformers.snowflake(payload.guild_id) }),
);
}
-3
View File
@@ -1,3 +0,0 @@
export * from "./GUILD_ROLE_CREATE.ts";
export * from "./GUILD_ROLE_DELETE.ts";
export * from "./GUILD_ROLE_UPDATE.ts";
@@ -1,12 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordVoiceServerUpdate } from "../../deps.ts";
export async function handleVoiceServerUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordVoiceServerUpdate;
bot.events.voiceServerUpdate(bot, {
token: payload.token,
guildId: bot.transformers.snowflake(payload.guild_id),
endpoint: payload.endpoint ?? undefined,
});
}
@@ -1,11 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordVoiceState } from "../../deps.ts";
export async function handleVoiceStateUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordVoiceState;
if (!payload.guild_id) return;
const guildId = bot.transformers.snowflake(payload.guild_id);
bot.events.voiceStateUpdate(bot, bot.transformers.voiceState(bot, { voiceState: payload, guildId }));
}
-2
View File
@@ -1,2 +0,0 @@
export * from "./VOICE_SERVER_UPDATE.ts";
export * from "./VOICE_STATE_UPDATE.ts";
@@ -1,10 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordGatewayPayload, DiscordWebhookUpdate } from "../../deps.ts";
export function handleWebhooksUpdate(bot: Bot, data: DiscordGatewayPayload) {
const payload = data.d as DiscordWebhookUpdate;
bot.events.webhooksUpdate(bot, {
channelId: bot.transformers.snowflake(payload.channel_id),
guildId: bot.transformers.snowflake(payload.guild_id),
});
}
-1
View File
@@ -1 +0,0 @@
export * from "./WEBHOOKS_UPDATE.ts";
@@ -1,63 +0,0 @@
import { Bot } from "../../bot.ts";
import { ChannelTypes, DiscordChannel } from "../../deps.ts";
import { OverwriteReadable } from "./editChannelOverwrite.ts";
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function createChannel(bot: Bot, guildId: bigint, options?: CreateGuildChannel, reason?: string) {
// BITRATE IS IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000
if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000;
const result = await bot.rest.runMethod<DiscordChannel>(
bot.rest,
"POST",
bot.constants.routes.GUILD_CHANNELS(guildId),
options
? {
name: options.name,
topic: options.topic,
bitrate: options.bitrate,
user_limit: options.userLimit,
rate_limit_per_user: options.rateLimitPerUser,
position: options.position,
parent_id: options.parentId?.toString(),
nsfw: options.nsfw,
permission_overwrites: options?.permissionOverwrites?.map((overwrite) => ({
id: overwrite.id.toString(),
type: overwrite.type,
allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : null,
deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : null,
})),
type: options?.type || ChannelTypes.GuildText,
reason,
default_auto_archive_duration: options?.defaultAutoArchiveDuration,
}
: {},
);
return bot.transformers.channel(bot, { channel: result, guildId });
}
export interface CreateGuildChannel {
/** Channel name (1-100 characters) */
name: string;
/** The type of channel */
type?: ChannelTypes;
/** Channel topic (0-1024 characters) */
topic?: string;
/** The bitrate (in bits) of the voice channel (voice only) */
bitrate?: number;
/** The user limit of the voice channel (voice only) */
userLimit?: number;
/** Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission `manage_messages` or `manage_channel`, are unaffected */
rateLimitPerUser?: number;
/** Sorting position of the channel */
position?: number;
/** The channel's permission overwrites */
permissionOverwrites?: OverwriteReadable[];
/** Id of the parent category for a channel */
parentId?: bigint;
/** Whether the channel is nsfw */
nsfw?: boolean;
/** Default duration (in minutes) that clients (not the API) use for newly created threads in this channel, to determine when to automatically archive the thread after the last activity */
defaultAutoArchiveDuration?: number;
}
@@ -1,25 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordStageInstance } from "../../deps.ts";
/** Creates a new Stage instance associated to a Stage channel. Requires the user to be a moderator of the Stage channel. */
export async function createStageInstance(bot: Bot, options: CreateStageInstance) {
const result = await bot.rest.runMethod<DiscordStageInstance>(
bot.rest,
"POST",
bot.constants.routes.STAGE_INSTANCES(),
{
channel_id: options.channelId.toString(),
topic: options.topic,
send_start_notification: options.sendStartNotification,
},
);
return bot.transformers.stageInstance(bot, result);
}
export interface CreateStageInstance {
channelId: bigint;
topic: string;
/** Notify @everyone that the stage instance has started. Requires the MENTION_EVERYONE permission. */
sendStartNotification?: boolean;
}
@@ -1,14 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordChannel } from "../../deps.ts";
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. Bot needs MANAGE_THREADS permissions in the server if deleting thread. */
export async function deleteChannel(bot: Bot, channelId: bigint, reason?: string) {
await bot.rest.runMethod<DiscordChannel>(
bot.rest,
"DELETE",
bot.constants.routes.CHANNEL(channelId),
{
reason,
},
);
}
@@ -1,10 +0,0 @@
import { Bot } from "../../bot.ts";
/** Delete the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
export async function deleteChannelOverwrite(bot: Bot, channelId: bigint, overwriteId: bigint) {
await bot.rest.runMethod<undefined>(
bot.rest,
"DELETE",
bot.constants.routes.CHANNEL_OVERWRITE(channelId, overwriteId),
);
}
@@ -1,6 +0,0 @@
import { Bot } from "../../bot.ts";
/** Deletes the Stage instance. Requires the user to be a moderator of the Stage channel. */
export async function deleteStageInstance(bot: Bot, channelId: bigint) {
await bot.rest.runMethod(bot.rest, "DELETE", bot.constants.routes.STAGE_INSTANCE(channelId));
}
-157
View File
@@ -1,157 +0,0 @@
import { Bot } from "../../bot.ts";
import { Channel } from "../../transformers/channel.ts";
import { ChannelTypes, DiscordChannel, VideoQualityModes } from "../../deps.ts";
import { OverwriteReadable } from "./editChannelOverwrite.ts";
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
export async function editChannel(bot: Bot, channelId: bigint, options: ModifyChannel, reason?: string) {
if (options.name || options.topic) {
const request = editChannelNameTopicQueue.get(channelId);
if (!request) {
// If this hasn't been done before simply add 1 for it
editChannelNameTopicQueue.set(channelId, {
channelId: channelId,
amount: 1,
// 10 minutes from now
timestamp: Date.now() + 600000,
items: [],
});
} else if (request.amount === 1) {
// Start queuing future requests to this channel
request.amount = 2;
request.timestamp = Date.now() + 600000;
} else {
return new Promise<Channel>((resolve, reject) => {
// 2 have already been used add to queue
request.items.push({ channelId, options, resolve, reject });
if (editChannelProcessing) return;
editChannelProcessing = true;
processEditChannelQueue(bot);
});
}
}
const result = await bot.rest.runMethod<DiscordChannel>(
bot.rest,
"PATCH",
bot.constants.routes.CHANNEL(channelId),
{
name: options.name,
topic: options.topic,
bitrate: options.bitrate,
user_limit: options.userLimit,
rate_limit_per_user: options.rateLimitPerUser,
position: options.position,
parent_id: options.parentId === null ? null : options.parentId?.toString(),
nsfw: options.nsfw,
type: options.type,
archived: options.archived,
auto_archive_duration: options.autoArchiveDuration,
locked: options.locked,
invitable: options.invitable,
permission_overwrites: options.permissionOverwrites
? options.permissionOverwrites?.map((overwrite) => ({
id: overwrite.id.toString(),
type: overwrite.type,
allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : null,
deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : null,
}))
: undefined,
reason,
},
);
return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) });
}
interface EditChannelRequest {
amount: number;
timestamp: number;
channelId: bigint;
items: {
channelId: bigint;
options: ModifyChannel;
resolve: (channel: Channel) => void;
// deno-lint-ignore no-explicit-any
reject: (error: any) => void;
}[];
}
const editChannelNameTopicQueue = new Map<bigint, EditChannelRequest>();
let editChannelProcessing = false;
function processEditChannelQueue(bot: Bot) {
if (!editChannelProcessing) return;
const now = Date.now();
editChannelNameTopicQueue.forEach(async (request) => {
bot.events.debug(`Running forEach loop in edit_channel file.`);
if (now < request.timestamp) return;
// 10 minutes have passed so we can reset this channel again
if (!request.items.length) {
return editChannelNameTopicQueue.delete(request.channelId);
}
request.amount = 0;
// There are items to process for this request
const details = request.items.shift();
if (!details) return;
await bot.helpers
.editChannel(details.channelId, details.options)
.then((result) => details.resolve(result))
.catch(details.reject);
const secondDetails = request.items.shift();
if (!secondDetails) return;
await bot.helpers
.editChannel(secondDetails.channelId, secondDetails.options)
.then((result) => secondDetails.resolve(result))
.catch(secondDetails.reject);
return;
});
if (editChannelNameTopicQueue.size) {
setTimeout(() => {
bot.events.debug(`Running setTimeout in EDIT_CHANNEL file.`);
processEditChannelQueue(bot);
}, 60000);
} else {
editChannelProcessing = false;
}
}
export interface ModifyChannel {
/** 1-100 character channel name */
name?: string;
/** The type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature */
type?: ChannelTypes;
/** The position of the channel in the left-hand listing */
position?: number | null;
/** 0-1024 character channel topic */
topic?: string | null;
/** Whether the channel is nsfw */
nsfw?: boolean | null;
/** Amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission `manage_messages` or `manage_channel`, are unaffected */
rateLimitPerUser?: number | null;
/** The bitrate (in bits) of the voice channel; 8000 to 96000 (128000 for VIP servers) */
bitrate?: number | null;
/** The user limit of the voice channel; 0 refers to no limit, 1 to 99 refers to a user limit */
userLimit?: number | null;
/** Channel or category-specific permissions */
permissionOverwrites?: OverwriteReadable[] | null;
/** Id of the new parent category for a channel */
parentId?: bigint | null;
/** Voice region id for the voice channel, automatic when set to null */
rtcRegion?: string | null;
/** The camera video quality mode of the voice channel */
videoQualityMode?: VideoQualityModes;
/** Whether the thread is archived */
archived?: boolean;
/** Duration in minutes to automatically archive the thread after recent activity */
autoArchiveDuration?: 60 | 1440 | 4320 | 10080;
/** When a thread is locked, only users with `MANAGE_THREADS` can unarchive it */
locked?: boolean;
/** whether non-moderators can add other non-moderators to a thread; only available on private threads */
invitable?: boolean;
}
@@ -1,42 +0,0 @@
import { Bot } from "../../bot.ts";
import { OverwriteTypes, PermissionStrings } from "../../deps.ts";
/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
export async function editChannelOverwrite(
bot: Bot,
channelId: bigint,
overwrite: OverwriteReadable,
) {
await bot.rest.runMethod<undefined>(
bot.rest,
"PUT",
bot.constants.routes.CHANNEL_OVERWRITE(channelId, overwrite.id),
{
allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : "0",
deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : "0",
type: overwrite.type,
},
);
}
export interface OverwriteReadable {
/** Role or user id */
id: bigint;
/** Either 0 (role) or 1 (member) */
type: OverwriteTypes;
/** Permission bit set */
allow?: PermissionStrings[];
/** Permission bit set */
deny?: PermissionStrings[];
}
export interface Overwrite {
/** Role or user id */
id: bigint;
/** Either 0 (role) or 1 (member) */
type: OverwriteTypes;
/** Permission bit set */
allow?: bigint;
/** Permission bit set */
deny?: bigint;
}
@@ -1,16 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordFollowedChannel } from "../../deps.ts";
/** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */
export async function followChannel(bot: Bot, sourceChannelId: bigint, targetChannelId: bigint) {
const data = await bot.rest.runMethod<DiscordFollowedChannel>(
bot.rest,
"POST",
bot.constants.routes.CHANNEL_FOLLOW(sourceChannelId),
{
webhook_channel_id: targetChannelId,
},
);
return bot.transformers.snowflake(data.webhook_id);
}
@@ -1,62 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordChannel, FileContent } from "../../../deps.ts";
import { Embed } from "../../../transformers/embed.ts";
import { AllowedMentions, MessageComponents } from "../../../typings.ts";
/** Creates a new public thread from an existing message. Returns a thread channel. */
export async function createForumPost(
bot: Bot,
channelId: bigint,
options: CreateForumPostWithMessage,
) {
const result = await bot.rest.runMethod<DiscordChannel>(
bot.rest,
"POST",
bot.constants.routes.FORUM_START(channelId),
{
name: options.name,
auto_archive_duration: options.autoArchiveDuration,
rate_limit_per_user: options.rateLimitPerUser,
reason: options.reason,
content: options.content,
embeds: options.embeds?.map((embed) => bot.transformers.reverse.embed(bot, embed)),
allowed_mentions: options.allowedMentions
? {
parse: options.allowedMentions?.parse,
roles: options.allowedMentions?.roles?.map((id) => id.toString()),
users: options.allowedMentions?.users?.map((id) => id.toString()),
replied_user: options.allowedMentions?.repliedUser,
}
: undefined,
file: options.file,
components: options.components?.map((component) => bot.transformers.reverse.component(bot, component)),
},
);
return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) });
}
export interface CreateForumPostWithMessage extends CreateForumMessage {
/** 1-100 character thread name */
name: string;
/** Duration in minutes to automatically archive the thread after recent activity */
autoArchiveDuration: 60 | 1440 | 4320 | 10080;
/** Amount of seconds a user has to wait before sending another message (0-21600) */
rateLimitPerUser?: number | null;
/** The reason you are creating the thread */
reason?: string;
}
export interface CreateForumMessage {
/** The message contents (up to 2000 characters) */
content?: string;
/** Embedded `rich` content (up to 6000 characters) */
embeds?: Embed[];
/** Allowed mentions for the message */
allowedMentions?: AllowedMentions;
/** The contents of the file being sent */
file?: FileContent | FileContent[];
/** The components you would like to have sent in this message */
components?: MessageComponents;
}
@@ -1 +0,0 @@
export * from "./createForumPost.ts";
@@ -1,19 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordChannel } from "../../deps.ts";
/** Fetches a single channel object from the api. */
export async function getChannel(bot: Bot, channelId: bigint) {
const result = await bot.rest.runMethod<DiscordChannel>(
bot.rest,
"GET",
bot.constants.routes.CHANNEL(channelId),
);
// IF A CHANNEL DOESN'T EXIST, DISCORD RETURNS `{}`
return result.id
? bot.transformers.channel(bot, {
channel: result,
guildId: result.guild_id ? bot.transformers.snowflake(result.guild_id) : undefined,
})
: undefined;
}
@@ -1,17 +0,0 @@
import { BotCollection as Collection } from "../../util/collection.ts";
import { Bot } from "../../bot.ts";
import { DiscordWebhook } from "../../deps.ts";
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
export async function getChannelWebhooks(bot: Bot, channelId: bigint) {
const result = await bot.rest.runMethod<DiscordWebhook[]>(
bot.rest,
"GET",
bot.constants.routes.CHANNEL_WEBHOOKS(channelId),
);
return new Collection(result.map((hook) => {
const webhook = bot.transformers.webhook(bot, hook);
return [webhook.id, webhook];
}));
}
@@ -1,16 +0,0 @@
import { BotCollection as Collection } from "../../util/collection.ts";
import { Bot } from "../../bot.ts";
import { DiscordChannel } from "../../deps.ts";
/** Returns a list of guild channel objects. */
export async function getChannels(bot: Bot, guildId: bigint) {
const result = await bot.rest.runMethod<DiscordChannel[]>(
bot.rest,
"GET",
bot.constants.routes.GUILD_CHANNELS(guildId),
);
return new Collection(
result.map((res) => bot.transformers.channel(bot, { channel: res, guildId })).map((c) => [c.id, c]),
);
}
-13
View File
@@ -1,13 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordMessage } from "../../deps.ts";
/** Get pinned messages in this channel. */
export async function getPins(bot: Bot, channelId: bigint) {
const result = await bot.rest.runMethod<DiscordMessage[]>(
bot.rest,
"GET",
bot.constants.routes.CHANNEL_PINS(channelId),
);
return result.map((msg) => bot.transformers.message(bot, msg));
}
@@ -1,13 +0,0 @@
import { Bot } from "../../bot.ts";
import { DiscordStageInstance } from "../../deps.ts";
/** Gets the stage instance associated with the Stage channel, if it exists. */
export async function getStageInstance(bot: Bot, channelId: bigint) {
const result = await bot.rest.runMethod<DiscordStageInstance>(
bot.rest,
"GET",
bot.constants.routes.STAGE_INSTANCE(channelId),
);
return bot.transformers.stageInstance(bot, result);
}
-20
View File
@@ -1,20 +0,0 @@
export * from "./threads/mod.ts";
export * from "./forums/mod.ts";
export * from "./createChannel.ts";
export * from "./createStageInstance.ts";
export * from "./deleteChannel.ts";
export * from "./deleteChannelOverwrite.ts";
export * from "./deleteStageInstance.ts";
export * from "./editChannel.ts";
export * from "./editChannelOverwrite.ts";
export * from "./followChannel.ts";
export * from "./getChannel.ts";
export * from "./getChannels.ts";
export * from "./getChannelWebhooks.ts";
export * from "./getPins.ts";
export * from "./getStageInstance.ts";
export * from "./startTyping.ts";
export * from "./swapChannels.ts";
export * from "./updateStageInstance.ts";
export * from "./updateVoiceState.ts";
@@ -1,10 +0,0 @@
import { Bot } from "../../bot.ts";
/**
* Trigger a typing indicator for the specified channel. Generally bots should **NOT** implement this route.
* However, if a bot is responding to a command and expects the computation to take a few seconds,
* this endpoint may be called to let the user know that the bot is processing their message.
*/
export async function startTyping(bot: Bot, channelId: bigint) {
await bot.rest.runMethod<undefined>(bot.rest, "POST", bot.constants.routes.CHANNEL_TYPING(channelId));
}
@@ -1,34 +0,0 @@
import { Bot } from "../../bot.ts";
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permission. Only channels to be modified are required. */
export async function swapChannels(bot: Bot, guildId: bigint, channelPositions: ModifyGuildChannelPositions[]) {
if (!channelPositions.length) {
throw "You must provide at least one channels to be moved.";
}
await bot.rest.runMethod<undefined>(
bot.rest,
"PATCH",
bot.constants.routes.GUILD_CHANNELS(guildId),
channelPositions.map((channelPosition) => {
return {
id: channelPosition.id,
position: channelPosition.position,
lock_positions: channelPosition.lockPositions,
parent_id: channelPosition.parentId,
};
}),
);
}
/** https://discord.com/developers/docs/resources/guild#modify-guild-channel-positions */
export interface ModifyGuildChannelPositions {
/** Channel id */
id: string;
/** Sorting position of the channel */
position: number | null;
/** Syncs the permission overwrites with the new parent, if moving to a new category */
lockPositions?: boolean | null;
/** The new parent ID for the channel that is moved */
parentId?: string | null;
}
@@ -1,6 +0,0 @@
import { Bot } from "../../../bot.ts";
/** Adds a user to a thread. Requires the ability to send messages in the thread. Requires the thread is not archived. */
export async function addToThread(bot: Bot, threadId: bigint, userId: bigint) {
await bot.rest.runMethod<undefined>(bot.rest, "PUT", bot.constants.routes.THREAD_USER(threadId, userId));
}
@@ -1,27 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordListActiveThreads } from "../../../deps.ts";
import { BotCollection as Collection } from "../../../util/collection.ts";
/** Returns all active threads in the guild, including public and private threads. Threads are ordered by their `id`, in descending order. */
export async function getActiveThreads(bot: Bot, guildId: bigint) {
const result = await bot.rest.runMethod<DiscordListActiveThreads>(
bot.rest,
"GET",
bot.constants.routes.THREAD_ACTIVE(guildId),
);
return {
threads: new Collection(
result.threads.map((t) => {
const thread = bot.transformers.channel(bot, { channel: t });
return [thread.id, thread];
}),
),
members: new Collection(
result.members.map((m) => {
const member = bot.transformers.threadMember(bot, m);
return [member.id, member];
}),
),
};
}
@@ -1,48 +0,0 @@
import { BotCollection as Collection } from "../../../util/collection.ts";
import { Bot } from "../../../bot.ts";
import { DiscordListArchivedThreads } from "../../../deps.ts";
/** Get the archived threads for this channel, defaults to public */
export async function getArchivedThreads(
bot: Bot,
channelId: bigint,
options?: ListArchivedThreads & {
type?: "public" | "private" | "privateJoinedThreads";
},
) {
let url = options?.type === "privateJoinedThreads"
? bot.constants.routes.THREAD_ARCHIVED_PRIVATE_JOINED(channelId, options)
: options?.type === "private"
? bot.constants.routes.THREAD_ARCHIVED_PRIVATE(channelId, options)
: bot.constants.routes.THREAD_ARCHIVED_PUBLIC(channelId, options);
const result = (await bot.rest.runMethod<DiscordListArchivedThreads>(
bot.rest,
"GET",
url,
));
return {
threads: new Collection(
result.threads.map((t) => {
const thread = bot.transformers.channel(bot, { channel: t });
return [thread.id, thread];
}),
),
members: new Collection(
result.members.map((m) => {
const member = bot.transformers.threadMember(bot, m);
return [member.id, member];
}),
),
hasMore: result.has_more,
};
}
/** https://discord.com/developers/docs/resources/channel#list-public-archived-threads-query-string-params */
export interface ListArchivedThreads {
/** Returns threads before this timestamp */
before?: number;
/** Optional maximum number of threads to return */
limit?: number;
}
@@ -1,18 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordThreadMember } from "../../../deps.ts";
/** Returns thread members objects that are members of the thread. */
export async function getThreadMember(bot: Bot, threadId: bigint, userId: bigint) {
const result = await bot.rest.runMethod<DiscordThreadMember>(
bot.rest,
"GET",
bot.constants.routes.THREAD_USER(threadId, userId),
);
return {
id: result.id ? bot.transformers.snowflake(result.id) : undefined,
userId: result.user_id ? bot.transformers.snowflake(result.user_id) : undefined,
joinTimestamp: Date.parse(result.join_timestamp),
flags: result.flags,
};
}
@@ -1,18 +0,0 @@
import { Bot } from "../../../bot.ts";
import { DiscordThreadMember } from "../../../deps.ts";
import { BotCollection as Collection } from "../../../util/collection.ts";
/** Returns thread members objects that are members of the thread. */
export async function getThreadMembers(bot: Bot, threadId: bigint) {
const result = await bot.rest.runMethod<DiscordThreadMember[]>(
bot.rest,
"GET",
bot.constants.routes.THREAD_MEMBERS(threadId),
);
// return result;
return new Collection(result.map((res) => {
const member = bot.transformers.threadMember(bot, res);
return [member.id, member];
}));
}
@@ -1,6 +0,0 @@
import { Bot } from "../../../bot.ts";
/** Adds the bot to the thread. Cannot join an archived thread. */
export async function joinThread(bot: Bot, threadId: bigint) {
await bot.rest.runMethod<undefined>(bot.rest, "PUT", bot.constants.routes.THREAD_ME(threadId));
}
@@ -1,6 +0,0 @@
import { Bot } from "../../../bot.ts";
/** Removes the bot from a thread. Requires the thread is not archived. */
export async function leaveThread(bot: Bot, threadId: bigint) {
await bot.rest.runMethod<undefined>(bot.rest, "DELETE", bot.constants.routes.THREAD_ME(threadId));
}

Some files were not shown because too many files have changed in this diff Show More