feat(discord): add channel/category management actions (#487)
Co-authored-by: Shadow <shadow@clawd.bot>
This commit is contained in:
@@ -183,6 +183,41 @@ export type DiscordStickerUpload = {
|
||||
mediaUrl: string;
|
||||
};
|
||||
|
||||
export type DiscordChannelCreate = {
|
||||
guildId: string;
|
||||
name: string;
|
||||
type?: number;
|
||||
parentId?: string;
|
||||
topic?: string;
|
||||
position?: number;
|
||||
nsfw?: boolean;
|
||||
};
|
||||
|
||||
export type DiscordChannelEdit = {
|
||||
channelId: string;
|
||||
name?: string;
|
||||
topic?: string;
|
||||
position?: number;
|
||||
parentId?: string | null;
|
||||
nsfw?: boolean;
|
||||
rateLimitPerUser?: number;
|
||||
};
|
||||
|
||||
export type DiscordChannelMove = {
|
||||
guildId: string;
|
||||
channelId: string;
|
||||
parentId?: string | null;
|
||||
position?: number;
|
||||
};
|
||||
|
||||
export type DiscordChannelPermissionSet = {
|
||||
channelId: string;
|
||||
targetId: string;
|
||||
targetType: 0 | 1;
|
||||
allow?: string;
|
||||
deny?: string;
|
||||
};
|
||||
|
||||
function resolveToken(params: {
|
||||
explicit?: string;
|
||||
accountId: string;
|
||||
@@ -1191,3 +1226,93 @@ export async function banMemberDiscord(
|
||||
});
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
// Channel management functions
|
||||
|
||||
export async function createChannelDiscord(
|
||||
payload: DiscordChannelCreate,
|
||||
opts: DiscordReactOpts = {},
|
||||
): Promise<APIChannel> {
|
||||
const rest = resolveDiscordRest(opts);
|
||||
const body: Record<string, unknown> = {
|
||||
name: payload.name,
|
||||
};
|
||||
if (payload.type !== undefined) body.type = payload.type;
|
||||
if (payload.parentId) body.parent_id = payload.parentId;
|
||||
if (payload.topic) body.topic = payload.topic;
|
||||
if (payload.position !== undefined) body.position = payload.position;
|
||||
if (payload.nsfw !== undefined) body.nsfw = payload.nsfw;
|
||||
return (await rest.post(Routes.guildChannels(payload.guildId), {
|
||||
body,
|
||||
})) as APIChannel;
|
||||
}
|
||||
|
||||
export async function editChannelDiscord(
|
||||
payload: DiscordChannelEdit,
|
||||
opts: DiscordReactOpts = {},
|
||||
): Promise<APIChannel> {
|
||||
const rest = resolveDiscordRest(opts);
|
||||
const body: Record<string, unknown> = {};
|
||||
if (payload.name !== undefined) body.name = payload.name;
|
||||
if (payload.topic !== undefined) body.topic = payload.topic;
|
||||
if (payload.position !== undefined) body.position = payload.position;
|
||||
if (payload.parentId !== undefined) body.parent_id = payload.parentId;
|
||||
if (payload.nsfw !== undefined) body.nsfw = payload.nsfw;
|
||||
if (payload.rateLimitPerUser !== undefined)
|
||||
body.rate_limit_per_user = payload.rateLimitPerUser;
|
||||
return (await rest.patch(Routes.channel(payload.channelId), {
|
||||
body,
|
||||
})) as APIChannel;
|
||||
}
|
||||
|
||||
export async function deleteChannelDiscord(
|
||||
channelId: string,
|
||||
opts: DiscordReactOpts = {},
|
||||
) {
|
||||
const rest = resolveDiscordRest(opts);
|
||||
await rest.delete(Routes.channel(channelId));
|
||||
return { ok: true, channelId };
|
||||
}
|
||||
|
||||
export async function moveChannelDiscord(
|
||||
payload: DiscordChannelMove,
|
||||
opts: DiscordReactOpts = {},
|
||||
) {
|
||||
const rest = resolveDiscordRest(opts);
|
||||
const body: Array<Record<string, unknown>> = [
|
||||
{
|
||||
id: payload.channelId,
|
||||
...(payload.parentId !== undefined && { parent_id: payload.parentId }),
|
||||
...(payload.position !== undefined && { position: payload.position }),
|
||||
},
|
||||
];
|
||||
await rest.patch(Routes.guildChannels(payload.guildId), { body });
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
export async function setChannelPermissionDiscord(
|
||||
payload: DiscordChannelPermissionSet,
|
||||
opts: DiscordReactOpts = {},
|
||||
) {
|
||||
const rest = resolveDiscordRest(opts);
|
||||
const body: Record<string, unknown> = {
|
||||
type: payload.targetType,
|
||||
};
|
||||
if (payload.allow !== undefined) body.allow = payload.allow;
|
||||
if (payload.deny !== undefined) body.deny = payload.deny;
|
||||
await rest.put(
|
||||
`/channels/${payload.channelId}/permissions/${payload.targetId}`,
|
||||
{ body },
|
||||
);
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
export async function removeChannelPermissionDiscord(
|
||||
channelId: string,
|
||||
targetId: string,
|
||||
opts: DiscordReactOpts = {},
|
||||
) {
|
||||
const rest = resolveDiscordRest(opts);
|
||||
await rest.delete(`/channels/${channelId}/permissions/${targetId}`);
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user