From e54f51a7afcd544c4af04000f5468d112d78a446 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Wed, 19 Apr 2023 12:57:36 -0500 Subject: [PATCH] fix: hack in helpers again (#3008) * fix: hack in helpers again * fix: remaining type errors * fix: weird linter issue --- packages/bot/src/bot.ts | 7 +- packages/bot/src/helpers.ts | 607 +++++++++++++++++++++++ packages/bot/src/index.ts | 1 + packages/bot/src/transformers.ts | 6 +- packages/bot/src/transformers/channel.ts | 6 +- packages/bot/src/transformers/member.ts | 8 +- packages/bot/src/transformers/role.ts | 6 +- packages/gateway/src/Shard.ts | 19 +- packages/rest/src/manager.ts | 92 ++-- packages/rest/src/types.ts | 8 +- packages/types/src/discord.ts | 7 +- 11 files changed, 696 insertions(+), 71 deletions(-) create mode 100644 packages/bot/src/helpers.ts diff --git a/packages/bot/src/bot.ts b/packages/bot/src/bot.ts index 9e791ac57..9b267e27d 100644 --- a/packages/bot/src/bot.ts +++ b/packages/bot/src/bot.ts @@ -5,6 +5,7 @@ import { createRestManager } from '@discordeno/rest' import type { DiscordEmoji, DiscordGatewayPayload, DiscordReady, GatewayIntents } from '@discordeno/types' import { createLogger, getBotIdFromToken, type Collection } from '@discordeno/utils' import { createBotGatewayHandlers } from './handlers.js' +import { createBotHelpers, type BotHelpers } from './helpers.js' import { createTransformers, type Transformers } from './transformers.js' import type { ApplicationCommandPermission } from './transformers/applicationCommandPermission.js' import type { AuditLogEntry } from './transformers/auditLogEntry.js' @@ -63,7 +64,8 @@ export function createBot(options: CreateBotOptions): Bot { gateway: createGatewayManager(options.gateway), events: options.events ?? {}, logger: createLogger({ name: 'BOT' }), - + // Set up helpers below. + helpers: {} as BotHelpers, async start() { if (!options.gateway?.connection) { bot.gateway.connection = await bot.rest.getSessionInfo() @@ -76,6 +78,8 @@ export function createBot(options: CreateBotOptions): Bot { }, } + bot.helpers = createBotHelpers(bot) + return bot } @@ -111,6 +115,7 @@ export interface Bot { transformers: Transformers /** The handler functions that should handle incoming discord payloads from gateway and call an event. */ handlers: ReturnType + helpers: BotHelpers /** Start the bot connection to the gateway. */ start: () => Promise /** Shuts down all the bot connections to the gateway. */ diff --git a/packages/bot/src/helpers.ts b/packages/bot/src/helpers.ts new file mode 100644 index 000000000..b8028afe0 --- /dev/null +++ b/packages/bot/src/helpers.ts @@ -0,0 +1,607 @@ +import type { CreateWebhook } from '@discordeno/rest' +import type { + ApplicationCommandPermissions, + AtLeastOne, + BeginGuildPrune, + BigString, + CamelizedDiscordActiveThreads, + CamelizedDiscordArchivedThreads, + CamelizedDiscordAuditLog, + CamelizedDiscordBan, + CamelizedDiscordFollowedChannel, + CamelizedDiscordGetGatewayBot, + CamelizedDiscordGuildPreview, + CamelizedDiscordGuildWidgetSettings, + CamelizedDiscordInvite, + CamelizedDiscordInviteMetadata, + CamelizedDiscordModifyGuildWelcomeScreen, + CamelizedDiscordPrunedCount, + CamelizedDiscordVanityUrl, + CamelizedDiscordVoiceRegion, + CreateApplicationCommand, + CreateAutoModerationRuleOptions, + CreateChannelInvite, + CreateForumPostWithMessage, + CreateGuild, + CreateGuildChannel, + CreateGuildEmoji, + CreateGuildFromTemplate, + CreateGuildRole, + CreateGuildStickerOptions, + CreateMessageOptions, + CreateScheduledEvent, + CreateStageInstance, + CreateTemplate, + DiscordMessage, + EditAutoModerationRuleOptions, + EditBotMemberOptions, + EditGuildRole, + EditGuildStickerOptions, + EditMessage, + EditScheduledEvent, + ExecuteWebhook, + GetBans, + GetGuildAuditLog, + GetGuildPruneCountQuery, + GetInvite, + GetMessagesOptions, + GetReactions, + GetScheduledEventUsers, + GetScheduledEvents, + GetWebhookMessageOptions, + InteractionCallbackData, + ListArchivedThreads, + ListGuildMembers, + ModifyChannel, + ModifyGuild, + ModifyGuildEmoji, + ModifyGuildMember, + ModifyGuildTemplate, + ModifyRolePositions, + ModifyWebhook, + SearchMembers, + StartThreadWithMessage, + StartThreadWithoutMessage, +} from '@discordeno/types' +import { snakelize } from '@discordeno/utils' +import type { Bot } from './bot.js' +import type { Application } from './transformers/application.js' +import type { ApplicationCommand } from './transformers/applicationCommand.js' +import type { ApplicationCommandPermission } from './transformers/applicationCommandPermission.js' +import type { AutoModerationRule } from './transformers/automodRule.js' +import type { Channel } from './transformers/channel.js' +import type { Emoji } from './transformers/emoji.js' +import type { Guild } from './transformers/guild.js' +import type { Integration } from './transformers/integration.js' +import type { Member } from './transformers/member.js' +import type { Message } from './transformers/message.js' +import type { Role } from './transformers/role.js' +import type { ScheduledEvent } from './transformers/scheduledEvent.js' +import type { StageInstance } from './transformers/stageInstance.js' +import type { Sticker, StickerPack } from './transformers/sticker.js' +import type { Template } from './transformers/template.js' +import type { ThreadMember } from './transformers/threadMember.js' +import type { User } from './transformers/user.js' +import type { Webhook } from './transformers/webhook.js' +import type { WelcomeScreen } from './transformers/welcomeScreen.js' +import type { GuildWidget } from './transformers/widget.js' +import type { GuildWidgetSettings } from './transformers/widgetSettings.js' + +export function createBotHelpers(bot: Bot): BotHelpers { + return { + createAutomodRule: async (guildId, options, reason) => { + return bot.transformers.automodRule(bot, snakelize(await bot.rest.createAutomodRule(guildId, options, reason))) + }, + createChannel: async (guildId, options, reason) => { + return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.createChannel(guildId, options, reason)), guildId }) + }, + createEmoji: async (guildId, options, reason) => { + return bot.transformers.emoji(bot, snakelize(await bot.rest.createEmoji(guildId, options, reason))) + }, + createForumThread: async (channelId, options, reason) => { + return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.createForumThread(channelId, options, reason)) }) + }, + createGlobalApplicationCommand: async (command) => { + return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.createGlobalApplicationCommand(command))) + }, + createGuild: async (options) => { + return bot.transformers.guild(bot, { guild: snakelize(await bot.rest.createGuild(options)), shardId: 0 }) + }, + createGuildApplicationCommand: async (command, guildId) => { + return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.createGuildApplicationCommand(command, guildId))) + }, + createGuildFromTemplate: async (templateCode, options) => { + return bot.transformers.guild(bot, { guild: snakelize(await bot.rest.createGuildFromTemplate(templateCode, options)), shardId: 0 }) + }, + createGuildSticker: async (guildId, options, reason) => { + return bot.transformers.sticker(bot, snakelize(await bot.rest.createGuildSticker(guildId, options, reason))) + }, + createGuildTemplate: async (guildId, options) => { + return bot.transformers.template(bot, snakelize(await bot.rest.createGuildTemplate(guildId, options))) + }, + createInvite: async (channelId, options, reason) => { + return await bot.rest.createInvite(channelId, options, reason) + }, + createRole: async (guildId, options, reason) => { + return bot.transformers.role(bot, { role: snakelize(await bot.rest.createRole(guildId, options, reason)), guildId }) + }, + createScheduledEvent: async (guildId, options, reason) => { + return bot.transformers.scheduledEvent(bot, snakelize(await bot.rest.createScheduledEvent(guildId, options, reason))) + }, + createStageInstance: async (options, reason) => { + return bot.transformers.stageInstance(bot, snakelize(await bot.rest.createStageInstance(options, reason))) + }, + createWebhook: async (channelId, options, reason) => { + return bot.transformers.webhook(bot, snakelize(await bot.rest.createWebhook(channelId, options, reason))) + }, + editApplicationCommandPermissions: async (guildId, commandId, bearerToken, options) => { + return bot.transformers.applicationCommandPermission( + bot, + snakelize(await bot.rest.editApplicationCommandPermissions(guildId, commandId, bearerToken, options)), + ) + }, + editAutomodRule: async (guildId, ruleId, options, reason) => { + return bot.transformers.automodRule(bot, snakelize(await bot.rest.editAutomodRule(guildId, ruleId, options, reason))) + }, + editBotProfile: async (options) => { + return bot.transformers.user(bot, snakelize(await bot.rest.editBotProfile(options))) + }, + editChannel: async (channelId, options, reason) => { + return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.editChannel(channelId, options, reason)) }) + }, + editEmoji: async (guildId, id, options, reason) => { + return bot.transformers.emoji(bot, snakelize(await bot.rest.editEmoji(guildId, id, options, reason))) + }, + editFollowupMessage: async (token, messageId, options) => { + return bot.transformers.message(bot, snakelize(await bot.rest.editFollowupMessage(token, messageId, options))) + }, + editGlobalApplicationCommand: async (commandId, options) => { + return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.editGlobalApplicationCommand(commandId, options))) + }, + editGuild: async (guildId, options, reason) => { + return bot.transformers.guild(bot, { guild: snakelize(await bot.rest.editGuild(guildId, options, reason)), shardId: 0 }) + }, + editGuildApplicationCommand: async (commandId, guildId, options) => { + return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.editGuildApplicationCommand(commandId, guildId, options))) + }, + editGuildSticker: async (guildId, stickerId, options, reason) => { + return bot.transformers.sticker(bot, snakelize(await bot.rest.editGuildSticker(guildId, stickerId, options, reason))) + }, + editGuildTemplate: async (guildId, templateCode, options) => { + return bot.transformers.template(bot, snakelize(await bot.rest.editGuildTemplate(guildId, templateCode, options))) + }, + editMessage: async (channelId, messageId, options) => { + return bot.transformers.message(bot, snakelize(await bot.rest.editMessage(channelId, messageId, options)) as DiscordMessage) + }, + editOriginalInteractionResponse: async (token, options) => { + const result = await bot.rest.editOriginalInteractionResponse(token, options) + if (!result) return + + return bot.transformers.message(bot, snakelize(result) as DiscordMessage) + }, + editOriginalWebhookMessage: async (webhookId, token, options) => { + return bot.transformers.message(bot, snakelize(await bot.rest.editOriginalWebhookMessage(webhookId, token, options)) as DiscordMessage) + }, + editRole: async (guildId, roleId, options, reason) => { + return bot.transformers.role(bot, { role: snakelize(await bot.rest.editRole(guildId, roleId, options, reason)), guildId }) + }, + editRolePositions: async (guildId, options, reason) => { + return snakelize(await bot.rest.editRolePositions(guildId, options, reason)).map((role) => bot.transformers.role(bot, { role, guildId })) + }, + editScheduledEvent: async (guildId, eventId, options, reason) => { + return bot.transformers.scheduledEvent(bot, snakelize(await bot.rest.editScheduledEvent(guildId, eventId, options, reason))) + }, + editStageInstance: async (channelId, topic, reason) => { + return bot.transformers.stageInstance(bot, snakelize(await bot.rest.editStageInstance(channelId, topic, reason))) + }, + editWebhook: async (webhookId, options, reason) => { + return bot.transformers.webhook(bot, snakelize(await bot.rest.editWebhook(webhookId, options, reason))) + }, + editWebhookMessage: async (webhookId, token, messageId, options) => { + return bot.transformers.message(bot, snakelize(await bot.rest.editWebhookMessage(webhookId, token, messageId, options)) as DiscordMessage) + }, + editWebhookWithToken: async (webhookId, token, options) => { + return bot.transformers.webhook(bot, snakelize(await bot.rest.editWebhookWithToken(webhookId, token, options))) + }, + editWelcomeScreen: async (guildId, options, reason) => { + return bot.transformers.welcomeScreen(bot, snakelize(await bot.rest.editWelcomeScreen(guildId, options, reason))) + }, + editWidgetSettings: async (guildId, options, reason) => { + return bot.transformers.widgetSettings(bot, snakelize(await bot.rest.editWidgetSettings(guildId, options, reason))) + }, + executeWebhook: async (webhookId, token, options) => { + const result = await bot.rest.executeWebhook(webhookId, token, options) + if (!result) return + + return bot.transformers.message(bot, snakelize(result) as DiscordMessage) + }, + followAnnouncement: async (sourceChannelId, targetChannelId) => { + return await bot.rest.followAnnouncement(sourceChannelId, targetChannelId) + }, + getActiveThreads: async (guildId) => { + return await bot.rest.getActiveThreads(guildId) + }, + getApplicationInfo: async () => { + return bot.transformers.application(bot, snakelize(await bot.rest.getApplicationInfo())) + }, + getApplicationCommandPermission: async (guildId, commandId) => { + return bot.transformers.applicationCommandPermission(bot, snakelize(await bot.rest.getApplicationCommandPermission(guildId, commandId))) + }, + getApplicationCommandPermissions: async (guildId) => { + return (await bot.rest.getApplicationCommandPermissions(guildId)).map((res) => + bot.transformers.applicationCommandPermission(bot, snakelize(res)), + ) + }, + getAuditLog: async (guildId, options) => { + return await bot.rest.getAuditLog(guildId, options) + }, + getAutomodRule: async (guildId, ruleId) => { + return bot.transformers.automodRule(bot, snakelize(await bot.rest.getAutomodRule(guildId, ruleId))) + }, + getAutomodRules: async (guildId) => { + return (await bot.rest.getAutomodRules(guildId)).map((res) => bot.transformers.automodRule(bot, snakelize(res))) + }, + getAvailableVoiceRegions: async () => { + return (await bot.rest.getAvailableVoiceRegions()).map((res) => bot.transformers.voiceRegion(bot, snakelize(res))) + }, + getBan: async (guildId, userId) => { + return await bot.rest.getBan(guildId, userId) + }, + getBans: async (guildId, options) => { + return await bot.rest.getBans(guildId, options) + }, + getChannel: async (channelId) => { + return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.getChannel(channelId)) }) + }, + getChannelInvites: async (channelId) => { + return await bot.rest.getChannelInvites(channelId) + // return (await bot.rest.getChannelInvites(channelId)).map((res) => bot.transformers.invite(bot, snakelize(res))) + }, + getChannels: async (guildId) => { + return (await bot.rest.getChannels(guildId)).map((res) => bot.transformers.channel(bot, { channel: snakelize(res), guildId })) + }, + getChannelWebhooks: async (channelId) => { + return (await bot.rest.getChannelWebhooks(channelId)).map((res) => bot.transformers.webhook(bot, snakelize(res))) + }, + getDmChannel: async (userId) => { + return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.getDmChannel(userId)) }) + }, + getEmoji: async (guildId, emojiId) => { + return bot.transformers.emoji(bot, snakelize(await bot.rest.getEmoji(guildId, emojiId))) + }, + getEmojis: async (guildId) => { + return (await bot.rest.getEmojis(guildId)).map((res) => bot.transformers.emoji(bot, snakelize(res))) + }, + getFollowupMessage: async (token, messageId) => { + return bot.transformers.message(bot, snakelize(await bot.rest.getFollowupMessage(token, messageId))) + }, + getGatewayBot: async () => { + return bot.transformers.gatewayBot(snakelize(await bot.rest.getGatewayBot())) + }, + getGlobalApplicationCommand: async (commandId) => { + return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.getGlobalApplicationCommand(commandId))) + }, + getGlobalApplicationCommands: async () => { + return (await bot.rest.getGlobalApplicationCommands()).map((res) => bot.transformers.applicationCommand(bot, snakelize(res))) + }, + getGuild: async (guildId, options) => { + return bot.transformers.guild(bot, { guild: snakelize(await bot.rest.getGuild(guildId, options)), shardId: 0 }) + }, + getGuildApplicationCommand: async (commandId, guildId) => { + return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.getGuildApplicationCommand(commandId, guildId))) + }, + getGuildApplicationCommands: async (guildId) => { + return (await bot.rest.getGuildApplicationCommands(guildId)).map((res) => bot.transformers.applicationCommand(bot, snakelize(res))) + }, + getGuildPreview: async (guildId) => { + return await bot.rest.getGuildPreview(guildId) + // return bot.transformers.xxx(bot, snakelize(await bot.rest.getGuildPreview(guildId))) + }, + getGuildSticker: async (guildId, stickerId) => { + return bot.transformers.sticker(bot, snakelize(await bot.rest.getGuildSticker(guildId, stickerId))) + }, + getGuildStickers: async (guildId) => { + return (await bot.rest.getGuildStickers(guildId)).map((res) => bot.transformers.sticker(bot, snakelize(res))) + }, + getGuildTemplate: async (templateCode) => { + return bot.transformers.template(bot, snakelize(await bot.rest.getGuildTemplate(templateCode))) + }, + getGuildTemplates: async (guildId) => { + return (await bot.rest.getGuildTemplates(guildId)).map((res) => bot.transformers.template(bot, snakelize(res))) + }, + getGuildWebhooks: async (guildId) => { + return (await bot.rest.getGuildWebhooks(guildId)).map((res) => bot.transformers.webhook(bot, snakelize(res))) + }, + getIntegrations: async (guildId) => { + return (await bot.rest.getIntegrations(guildId)).map((res) => + bot.transformers.integration(bot, snakelize({ ...res, guildId: guildId.toString() })), + ) + }, + getInvite: async (inviteCode, options) => { + return await bot.rest.getInvite(inviteCode, options) + // return bot.transformers.invite(bot, snakelize(await bot.rest.getInvite(inviteCode, options))) + }, + getInvites: async (guildId) => { + return await bot.rest.getInvites(guildId) + // .map((res) => bot.transformers.invite(bot, snakelize(res))) + }, + getMessage: async (channelId, messageId) => { + return bot.transformers.message(bot, snakelize(await bot.rest.getMessage(channelId, messageId))) + }, + getMessages: async (channelId, options) => { + return (await bot.rest.getMessages(channelId, options)).map((res) => bot.transformers.message(bot, snakelize(res))) + }, + getNitroStickerPacks: async () => { + return (await bot.rest.getNitroStickerPacks()).map((res) => bot.transformers.stickerPack(bot, snakelize(res))) + }, + getOriginalInteractionResponse: async (token) => { + return bot.transformers.message(bot, snakelize(await bot.rest.getOriginalInteractionResponse(token))) + }, + getPinnedMessages: async (channelId) => { + return (await bot.rest.getPinnedMessages(channelId)).map((res) => bot.transformers.message(bot, snakelize(res))) + }, + getPrivateArchivedThreads: async (channelId, options) => { + return await bot.rest.getPrivateArchivedThreads(channelId, options) + // return bot.transformers.xxx(bot, snakelize(await bot.rest.getPrivateArchivedThreads(channelId, options))) + }, + getPrivateJoinedArchivedThreads: async (channelId, options) => { + return await bot.rest.getPrivateJoinedArchivedThreads(channelId, options) + // return bot.transformers.xxx(bot, snakelize(await bot.rest.getPrivateJoinedArchivedThreads(channelId, options))) + }, + getPruneCount: async (guildId, options) => { + return await bot.rest.getPruneCount(guildId, options) + // return bot.transformers.xxx(bot, snakelize(await bot.rest.getPruneCount(guildId, options))) + }, + getPublicArchivedThreads: async (channelId, options) => { + return await bot.rest.getPublicArchivedThreads(channelId, options) + // return bot.transformers.xxx(bot, snakelize(await bot.rest.getPublicArchivedThreads(channelId, options))) + }, + getRoles: async (guildId) => { + return snakelize(await bot.rest.getRoles(guildId)).map((role) => bot.transformers.role(bot, { role, guildId })) + }, + getScheduledEvent: async (guildId, eventId, options) => { + return bot.transformers.scheduledEvent(bot, snakelize(await bot.rest.getScheduledEvent(guildId, eventId, options))) + }, + getScheduledEvents: async (guildId, options) => { + return (await bot.rest.getScheduledEvents(guildId, options)).map((res) => bot.transformers.scheduledEvent(bot, snakelize(res))) + }, + getScheduledEventUsers: async (guildId, eventId, options) => { + return (await bot.rest.getScheduledEventUsers(guildId, eventId, options)).map((u) => { + return { + user: bot.transformers.user(bot, snakelize(u.user)), + member: u.member && bot.transformers.member(bot, snakelize(u.member), guildId, bot.transformers.snowflake(u.user.id)), + } + }) + }, + getSessionInfo: async () => { + return bot.transformers.gatewayBot(snakelize(await bot.rest.getSessionInfo())) + }, + getStageInstance: async (channelId) => { + return bot.transformers.stageInstance(bot, snakelize(await bot.rest.getStageInstance(channelId))) + }, + getSticker: async (stickerId) => { + return bot.transformers.sticker(bot, snakelize(await bot.rest.getSticker(stickerId))) + }, + getThreadMember: async (channelId, userId) => { + return bot.transformers.threadMember(bot, snakelize(await bot.rest.getThreadMember(channelId, userId))) + }, + getThreadMembers: async (channelId) => { + return (await bot.rest.getThreadMembers(channelId)).map((res) => bot.transformers.threadMember(bot, snakelize(res))) + }, + getReactions: async (channelId, messageId, reaction, options) => { + return (await bot.rest.getReactions(channelId, messageId, reaction, options)).map((res) => bot.transformers.user(bot, snakelize(res))) + }, + getUser: async (id) => { + return bot.transformers.user(bot, snakelize(await bot.rest.getUser(id))) + }, + getVanityUrl: async (guildId) => { + return await bot.rest.getVanityUrl(guildId) + }, + getVoiceRegions: async (guildId) => { + return (await bot.rest.getVoiceRegions(guildId)).map((res) => bot.transformers.voiceRegion(bot, snakelize(res))) + }, + getWebhook: async (webhookId) => { + return bot.transformers.webhook(bot, snakelize(await bot.rest.getWebhook(webhookId))) + }, + getWebhookMessage: async (webhookId, token, messageId, options) => { + return bot.transformers.message(bot, snakelize(await bot.rest.getWebhookMessage(webhookId, token, messageId, options))) + }, + getWebhookWithToken: async (webhookId, token) => { + return bot.transformers.webhook(bot, snakelize(await bot.rest.getWebhookWithToken(webhookId, token))) + }, + getWelcomeScreen: async (guildId) => { + return bot.transformers.welcomeScreen(bot, snakelize(await bot.rest.getWelcomeScreen(guildId))) + }, + getWidget: async (guildId) => { + return bot.transformers.widget(bot, snakelize(await bot.rest.getWidget(guildId))) + }, + getWidgetSettings: async (guildId) => { + return bot.transformers.widgetSettings(bot, snakelize(await bot.rest.getWidgetSettings(guildId))) + }, + publishMessage: async (channelId, messageId) => { + return bot.transformers.message(bot, snakelize(await bot.rest.publishMessage(channelId, messageId))) + }, + sendMessage: async (channelId, options) => { + return bot.transformers.message(bot, snakelize(await bot.rest.sendMessage(channelId, options))) + }, + sendFollowupMessage: async (token, options) => { + return bot.transformers.message(bot, snakelize(await bot.rest.sendFollowupMessage(token, options))) + }, + startThreadWithMessage: async (channelId, messageId, options, reason) => { + return bot.transformers.channel(bot, { + channel: snakelize(await bot.rest.startThreadWithMessage(channelId, messageId, options, reason)), + }) + }, + startThreadWithoutMessage: async (channelId, options, reason) => { + return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.startThreadWithoutMessage(channelId, options, reason)) }) + }, + syncGuildTemplate: async (guildId) => { + return bot.transformers.template(bot, snakelize(await bot.rest.syncGuildTemplate(guildId))) + }, + upsertGlobalApplicationCommands: async (commands) => { + return (await bot.rest.upsertGlobalApplicationCommands(commands)).map((res) => bot.transformers.applicationCommand(bot, snakelize(res))) + }, + upsertGuildApplicationCommands: async (guildId, commands) => { + return (await bot.rest.upsertGuildApplicationCommands(guildId, commands)).map((res) => bot.transformers.applicationCommand(bot, snakelize(res))) + }, + editBotMember: async (guildId, options, reason) => { + return bot.transformers.member(bot, snakelize(await bot.rest.editBotMember(guildId, options, reason)), guildId, bot.id) + }, + editMember: async (guildId, userId, options, reason) => { + return bot.transformers.member(bot, snakelize(await bot.rest.editMember(guildId, userId, options, reason)), guildId, userId) + }, + getMember: async (guildId, userId) => { + return bot.transformers.member(bot, snakelize(await bot.rest.getMember(guildId, userId)), guildId, userId) + }, + getMembers: async (guildId, options) => { + return (await bot.rest.getMembers(guildId, options)).map((res) => + bot.transformers.member(bot, snakelize(res), guildId, bot.transformers.snowflake(res.user.id)), + ) + }, + pruneMembers: async (guildId, options, reason) => { + return await bot.rest.pruneMembers(guildId, options, reason) + }, + searchMembers: async (guildId, query, options) => { + return (await bot.rest.searchMembers(guildId, query, options)).map((res) => + bot.transformers.member(bot, snakelize(res), guildId, bot.transformers.snowflake(res.user.id)), + ) + }, + } +} + +export interface BotHelpers { + createAutomodRule: (guildId: BigString, options: CreateAutoModerationRuleOptions, reason?: string) => Promise + createChannel: (guildId: BigString, options: CreateGuildChannel, reason?: string) => Promise + createEmoji: (guildId: BigString, options: CreateGuildEmoji, reason?: string) => Promise + createForumThread: (channelId: BigString, options: CreateForumPostWithMessage, reason?: string) => Promise + createGlobalApplicationCommand: (command: CreateApplicationCommand) => Promise + createGuild: (options: CreateGuild) => Promise + createGuildApplicationCommand: (command: CreateApplicationCommand, guildId: BigString) => Promise + createGuildFromTemplate: (templateCode: string, options: CreateGuildFromTemplate) => Promise + createGuildSticker: (guildId: BigString, options: CreateGuildStickerOptions, reason?: string) => Promise + createGuildTemplate: (guildId: BigString, options: CreateTemplate) => Promise