mirror of
https://github.com/sern-handler/cli
synced 2026-06-28 02:32:20 +00:00
feat: publish command (#105)
Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Co-authored-by: jacob <jacoobes@sern.dev>
This commit is contained in:
41
src/rest.ts
Normal file
41
src/rest.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import type { PublishableModule } from './create-publish.d.ts';
|
||||
|
||||
const baseURL = new URL('https://discord.com/api/v10/applications/');
|
||||
|
||||
const excludedKeys = new Set(['command', 'absPath']);
|
||||
|
||||
const publishablesIntoJson = (ps: PublishableModule[]) =>
|
||||
JSON.stringify(
|
||||
ps.map((module) => module.data),
|
||||
(key, value) => (excludedKeys.has(key) ? undefined : value),
|
||||
4
|
||||
);
|
||||
|
||||
export const create = (appid: string, token: string) => {
|
||||
const globalURL = new URL(`${appid}/commands`, baseURL);
|
||||
const headers = {
|
||||
Authorization: 'Bot ' + token,
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
return {
|
||||
updateGlobal: (commands: PublishableModule[]) =>
|
||||
fetch(globalURL, {
|
||||
method: 'PUT',
|
||||
body: publishablesIntoJson(commands),
|
||||
headers,
|
||||
}),
|
||||
getGuildCommands: (id: string) => {
|
||||
const guildCommandURL = new URL(`${appid}/guilds/${id}/commands`, baseURL);
|
||||
return fetch(guildCommandURL, { headers });
|
||||
},
|
||||
|
||||
putGuildCommands: (guildId: string, guildCommand: any) => {
|
||||
const guildCommandURL = new URL(`${appid}/guilds/${guildId}/commands`, baseURL);
|
||||
return fetch(guildCommandURL, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify(guildCommand),
|
||||
headers,
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user