refactor: typings using ReturnType (#2105)

* fix: check new types idea

* fix: type errors

* fix: new style

* fix: more cleanup

* fix: more cleanup

* fix: cleanup audit logs

* fix: cleanup stickers

* fix: cleanup integrations

* fix: more cleanup

* fix: organize into 1 place

* fix: few errors

* fix: some broken import fixes

* fix: quite a lot of fixes across the board

* fix: more fixes for broken imports

* fix: more fixes for broken imports

* fix: handler imports

* fix: all remaining import errors

* fix: more errors needing fixes

* fix: clearing up transformers

* fix: few moer types

* fix: more cleanup of extra types

* fix: fmt

* fix: cleanup discordeno file

* Nuke Base Types (#2102)

* fix: cleanup snake stuff

* convert camelCase to snake_case (#2103)

* fix: add camelize

* fix: finalize remaining errors

* fix: imports in test

Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
This commit is contained in:
Skillz4Killz
2022-03-14 22:11:22 -04:00
committed by GitHub
parent da29ff294d
commit a0a1554756
505 changed files with 5647 additions and 7106 deletions
@@ -1,6 +1,6 @@
import type { Bot } from "../../../bot.ts";
import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/applicationCommandPermissions.ts";
import { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guildApplicationCommandPermissions.ts";
import { DiscordGuildApplicationCommandPermissions } from "../../../types/discord.ts";
import { ApplicationCommandPermissionTypes } from "../../../types/shared.ts";
/** Batch edits permissions for all commands in a guild. Takes an array of partial GuildApplicationCommandPermissions objects including `id` and `permissions`. */
export async function batchEditApplicationCommandPermissions(
@@ -8,7 +8,7 @@ export async function batchEditApplicationCommandPermissions(
guildId: bigint,
options: { id: string; permissions: ApplicationCommandPermissions[] }[],
) {
const result = await bot.rest.runMethod<GuildApplicationCommandPermissions[]>(
const result = await bot.rest.runMethod<DiscordGuildApplicationCommandPermissions[]>(
bot.rest,
"put",
bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId),
@@ -17,3 +17,13 @@ export async function batchEditApplicationCommandPermissions(
return result.map((res) => bot.transformers.applicationCommandPermission(bot, res));
}
/** https://discord.com/developers/docs/interactions/slash-commands#applicationcommandpermissions */
export interface ApplicationCommandPermissions {
/** The id of the role or user */
id: string;
/** Role or User */
type: ApplicationCommandPermissionTypes;
/** `true` to allow, `false`, to disallow */
permission: boolean;
}
@@ -1,7 +1,6 @@
import type { ApplicationCommand } from "../../../types/interactions/commands/applicationCommand.ts";
import type { CreateApplicationCommand } from "../../../types/interactions/commands/createGlobalApplicationCommand.ts";
import type { Bot } from "../../../bot.ts";
import { ApplicationCommandOption } from "../../../types/interactions/commands/applicationCommandOption.ts";
import { ApplicationCommandOption, ApplicationCommandTypes } from "../../../mod.ts";
import { DiscordApplicationCommand } from "../../../types/discord.ts";
/**
* There are two kinds of Application Commands: global commands and guild commands. Global commands are available for every guild that adds your app; guild commands are specific to the guild you specify when making them. Command names are unique per application within each scope (global and guild). That means:
@@ -15,7 +14,7 @@ import { ApplicationCommandOption } from "../../../types/interactions/commands/a
* Guild commands update **instantly**. We recommend you use guild commands for quick testing, and global commands when they're ready for public use.
*/
export async function createApplicationCommand(bot: Bot, options: CreateApplicationCommand, guildId?: bigint) {
const result = await bot.rest.runMethod<ApplicationCommand>(
const result = await bot.rest.runMethod<DiscordApplicationCommand>(
bot.rest,
"post",
guildId
@@ -47,3 +46,15 @@ export function makeOptionsForCommand(options: ApplicationCommandOption[]) {
max_value: option.maxValue,
}));
}
/** https://discord.com/developers/docs/interactions/slash-commands#create-global-application-command-json-params */
export interface CreateApplicationCommand {
/** 1-31 character name matching lowercase `^[\w-]{1,32}$` */
name: string;
/** 1-100 character description */
description: string;
/** The type of the command */
type?: ApplicationCommandTypes;
/** The parameters for the command */
options?: ApplicationCommandOption[];
}
@@ -1,6 +1,6 @@
import type { ApplicationCommandPermissions } from "../../../types/interactions/commands/applicationCommandPermissions.ts";
import type { Bot } from "../../../bot.ts";
import { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guildApplicationCommandPermissions.ts";
import { DiscordGuildApplicationCommandPermissions } from "../../../types/discord.ts";
import { ApplicationCommandPermissions } from "./batchEditApplicationCommandPermissions.ts";
/** Edits command permissions for a specific command for your application in a guild. */
export async function editApplicationCommandPermissions(
@@ -9,7 +9,7 @@ export async function editApplicationCommandPermissions(
commandId: bigint,
options: ApplicationCommandPermissions[],
) {
const result = await bot.rest.runMethod<GuildApplicationCommandPermissions>(
const result = await bot.rest.runMethod<DiscordGuildApplicationCommandPermissions>(
bot.rest,
"put",
bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId),
@@ -1,9 +1,16 @@
import type { DiscordenoEditWebhookMessage } from "../../../types/discordeno/editWebhookMessage.ts";
import type { Bot } from "../../../bot.ts";
import { MessageComponentTypes } from "../../../types/messages/components/messageComponentTypes.ts";
import { MessageComponentTypes } from "../../../types/shared.ts";
import { EditWebhookMessage } from "../../webhooks/editWebhookMessage.ts";
/** To edit your response to a application command. If a messageId is not provided it will default to editing the original response. */
export async function editInteractionResponse(bot: Bot, token: string, options: DiscordenoEditWebhookMessage) {
export async function editInteractionResponse(
bot: Bot,
token: string,
options: EditWebhookMessage & {
/** Id of the message you want to edit if undefined the initial response message will be edited */
messageId?: bigint;
},
) {
const result = await bot.rest.runMethod(
bot.rest,
"patch",
@@ -1,9 +1,9 @@
import type { ApplicationCommand } from "../../../types/interactions/commands/applicationCommand.ts";
import type { Bot } from "../../../bot.ts";
import { DiscordApplicationCommand } from "../../../types/discord.ts";
/** Fetches the global command for the given Id. If a guildId is provided, the guild command will be fetched. */
export async function getApplicationCommand(bot: Bot, commandId: bigint, guildId?: bigint) {
const result = await bot.rest.runMethod<ApplicationCommand>(
const result = await bot.rest.runMethod<DiscordApplicationCommand>(
bot.rest,
"get",
guildId
@@ -1,9 +1,9 @@
import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guildApplicationCommandPermissions.ts";
import type { Bot } from "../../../bot.ts";
import { DiscordGuildApplicationCommandPermissions } from "../../../types/discord.ts";
/** Fetches command permissions for a specific command for your application in a guild. Returns a GuildApplicationCommandPermissions object. */
export async function getApplicationCommandPermission(bot: Bot, guildId: bigint, commandId: bigint) {
const result = await bot.rest.runMethod<GuildApplicationCommandPermissions>(
const result = await bot.rest.runMethod<DiscordGuildApplicationCommandPermissions>(
bot.rest,
"get",
bot.constants.endpoints.COMMANDS_PERMISSION(bot.applicationId, guildId, commandId),
@@ -1,10 +1,10 @@
import type { Bot } from "../../../bot.ts";
import type { GuildApplicationCommandPermissions } from "../../../types/interactions/commands/guildApplicationCommandPermissions.ts";
import { DiscordGuildApplicationCommandPermissions } from "../../../types/discord.ts";
import { Collection } from "../../../util/collection.ts";
/** Fetches command permissions for all commands for your application in a guild. Returns an array of GuildApplicationCommandPermissions objects. */
export async function getApplicationCommandPermissions(bot: Bot, guildId: bigint) {
const result = await bot.rest.runMethod<GuildApplicationCommandPermissions[]>(
const result = await bot.rest.runMethod<DiscordGuildApplicationCommandPermissions[]>(
bot.rest,
"get",
bot.constants.endpoints.COMMANDS_PERMISSIONS(bot.applicationId, guildId),
@@ -1,10 +1,10 @@
import type { ApplicationCommand } from "../../../types/interactions/commands/applicationCommand.ts";
import { Collection } from "../../../util/collection.ts";
import type { Bot } from "../../../bot.ts";
import { DiscordApplicationCommand } from "../../../types/discord.ts";
/** Fetch all the commands for your application. If a guild id is not provided, it will fetch global commands. */
export async function getApplicationCommands(bot: Bot, guildId?: bigint) {
const result = await bot.rest.runMethod<ApplicationCommand[]>(
const result = await bot.rest.runMethod<DiscordApplicationCommand[]>(
bot.rest,
"get",
guildId
@@ -1,7 +1,8 @@
import type { ApplicationCommand } from "../../../types/interactions/commands/applicationCommand.ts";
import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/editGlobalApplicationCommand.ts";
import type { Bot } from "../../../bot.ts";
import { makeOptionsForCommand } from "./createApplicationCommand.ts";
import { DiscordApplicationCommand } from "../../../types/discord.ts";
import { ApplicationCommandOption } from "../../../transformers/applicationCommandOption.ts";
import { ApplicationCommandTypes } from "../../../types/shared.ts";
/**
* Edit an existing application command. If this command did not exist, it will create it.
@@ -12,7 +13,7 @@ export async function upsertApplicationCommand(
options: EditGlobalApplicationCommand,
guildId?: bigint,
) {
const result = await bot.rest.runMethod<ApplicationCommand>(
const result = await bot.rest.runMethod<DiscordApplicationCommand>(
bot.rest,
"patch",
guildId
@@ -28,3 +29,17 @@ export async function upsertApplicationCommand(
return bot.transformers.applicationCommand(bot, result);
}
/** https://discord.com/developers/docs/interactions/slash-commands#edit-global-application-command-json-params */
export interface EditGlobalApplicationCommand {
/** 1-32 character name matching lowercase `^[\w-]{1,32}$` */
name?: string;
/** 1-100 character description */
description?: string;
/** The type of the command */
type?: ApplicationCommandTypes;
/** The parameters for the command */
options?: ApplicationCommandOption[] | null;
/** Whether the command is enabled by default when the app is added to a guild. Default: true */
defaultPermission?: boolean;
}
@@ -1,9 +1,9 @@
import type { ApplicationCommand } from "../../../types/interactions/commands/applicationCommand.ts";
import type { EditGlobalApplicationCommand } from "../../../types/interactions/commands/editGlobalApplicationCommand.ts";
import type { MakeRequired } from "../../../types/util.ts";
import type { Bot } from "../../../bot.ts";
import { Collection } from "../../../util/collection.ts";
import { makeOptionsForCommand } from "./createApplicationCommand.ts";
import { DiscordApplicationCommand } from "../../../types/discord.ts";
import { EditGlobalApplicationCommand } from "./upsertApplicationCommand.ts";
import { MakeRequired } from "../../../types/shared.ts";
/**
* Bulk edit existing application commands. If a command does not exist, it will create it.
@@ -15,7 +15,7 @@ export async function upsertApplicationCommands(
options: MakeRequired<EditGlobalApplicationCommand, "name">[],
guildId?: bigint,
) {
const result = await bot.rest.runMethod<ApplicationCommand[]>(
const result = await bot.rest.runMethod<DiscordApplicationCommand[]>(
bot.rest,
"put",
guildId