mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
add guild widget settings interface, transformer (#2197)
* add guild widget settings interface, transformer * fix bot.transformers.widgetSettings is not a function Co-authored-by: ITOH <to@itoh.at>
This commit is contained in:
@@ -65,6 +65,7 @@ import { transformApplicationCommand } from "./transformers/applicationCommand.t
|
||||
import { transformWelcomeScreen } from "./transformers/welcomeScreen.ts";
|
||||
import { transformVoiceRegion } from "./transformers/voiceRegion.ts";
|
||||
import { transformWidget } from "./transformers/widget.ts";
|
||||
import { transformWidgetSettings } from "./transformers/widgetSettings.ts";
|
||||
import { transformStageInstance } from "./transformers/stageInstance.ts";
|
||||
import { StickerPack, transformSticker, transformStickerPack } from "./transformers/sticker.ts";
|
||||
import { GetGatewayBot, transformGatewayBot } from "./transformers/gatewayBot.ts";
|
||||
@@ -93,6 +94,7 @@ import {
|
||||
DiscordGuild,
|
||||
DiscordGuildApplicationCommandPermissions,
|
||||
DiscordGuildWidget,
|
||||
DiscordGuildWidgetSettings,
|
||||
DiscordIntegrationCreateUpdate,
|
||||
DiscordInteraction,
|
||||
DiscordInviteCreate,
|
||||
@@ -126,6 +128,7 @@ import { ApplicationCommandPermission } from "./transformers/applicationCommandP
|
||||
import { WelcomeScreen } from "./transformers/welcomeScreen.ts";
|
||||
import { VoiceRegions } from "./transformers/voiceRegion.ts";
|
||||
import { GuildWidget } from "./transformers/widget.ts";
|
||||
import { GuildWidgetSettings } from "./transformers/widgetSettings.ts";
|
||||
import { StageInstance } from "./transformers/stageInstance.ts";
|
||||
import { Sticker } from "./transformers/sticker.ts";
|
||||
import {
|
||||
@@ -424,6 +427,7 @@ export interface Transformers {
|
||||
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;
|
||||
@@ -473,6 +477,7 @@ export function createTransformers(options: Partial<Transformers>) {
|
||||
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,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGuildWidget } from "../../types/discord.ts";
|
||||
import { DiscordGuildWidgetSettings } from "../../types/discord.ts";
|
||||
|
||||
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
|
||||
export async function editWidget(bot: Bot, guildId: bigint, enabled: boolean, channelId?: string | null) {
|
||||
const result = await bot.rest.runMethod<DiscordGuildWidget>(
|
||||
const result = await bot.rest.runMethod<DiscordGuildWidgetSettings>(
|
||||
bot.rest,
|
||||
"patch",
|
||||
bot.constants.endpoints.GUILD_WIDGET(guildId),
|
||||
@@ -13,5 +13,5 @@ export async function editWidget(bot: Bot, guildId: bigint, enabled: boolean, ch
|
||||
},
|
||||
);
|
||||
|
||||
return bot.transformers.widget(bot, result);
|
||||
return bot.transformers.widgetSettings(bot, result);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { DiscordGuildWidget } from "../../types/discord.ts";
|
||||
import { DiscordGuildWidgetSettings } from "../../types/discord.ts";
|
||||
|
||||
/** Returns the guild widget object. Requires the MANAGE_GUILD permission. */
|
||||
/** Returns a guild widget settings object. Requires the MANAGE_GUILD permission. */
|
||||
export async function getWidgetSettings(bot: Bot, guildId: bigint) {
|
||||
const result = await bot.rest.runMethod<DiscordGuildWidget>(
|
||||
const result = await bot.rest.runMethod<DiscordGuildWidgetSettings>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_WIDGET(guildId),
|
||||
);
|
||||
|
||||
return bot.transformers.widget(bot, result);
|
||||
return bot.transformers.widgetSettings(bot, result);
|
||||
}
|
||||
|
||||
+2
-1
@@ -24,10 +24,11 @@ export * from "./scheduledEvent.ts";
|
||||
export * from "./stageInstance.ts";
|
||||
export * from "./sticker.ts";
|
||||
export * from "./team.ts";
|
||||
export * from "./template.ts";
|
||||
export * from "./threadMember.ts";
|
||||
export * from "./voiceRegion.ts";
|
||||
export * from "./voiceState.ts";
|
||||
export * from "./webhook.ts";
|
||||
export * from "./welcomeScreen.ts";
|
||||
export * from "./widget.ts";
|
||||
export * from "./template.ts";
|
||||
export * from "./widgetSettings.ts";
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Bot } from "../bot.ts";
|
||||
import { DiscordGuildWidgetSettings } from "../types/discord.ts";
|
||||
import { Optionalize } from "../types/shared.ts";
|
||||
|
||||
export function transformWidgetSettings(bot: Bot, payload: DiscordGuildWidgetSettings) {
|
||||
const widget = {
|
||||
enabled: payload.enabled,
|
||||
channelId: payload.channel_id ?? undefined,
|
||||
};
|
||||
|
||||
return widget as Optionalize<typeof widget>;
|
||||
}
|
||||
|
||||
export interface GuildWidgetSettings extends ReturnType<typeof transformWidgetSettings> {}
|
||||
@@ -2230,6 +2230,13 @@ export interface DiscordVoiceRegion {
|
||||
custom: boolean;
|
||||
}
|
||||
|
||||
export interface DiscordGuildWidgetSettings {
|
||||
/** whether the widget is enabled */
|
||||
enabled: boolean;
|
||||
/** the widget channel id */
|
||||
channel_id: string | null;
|
||||
}
|
||||
|
||||
export interface DiscordInstallParams {
|
||||
/** he scopes to add the application to the server with */
|
||||
scopes: string[];
|
||||
|
||||
Reference in New Issue
Block a user