mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
templates
This commit is contained in:
@@ -3,7 +3,7 @@ import { rest } from "../../rest/rest.ts";
|
||||
import { Guild } from "../../types/guilds/guild.ts";
|
||||
import { CreateGuildFromTemplate } from "../../types/templates/create_guild_from_template.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { snakeKeysToCamelCase, urlToBase64 } from "../../util/utils.ts";
|
||||
import { urlToBase64 } from "../../util/utils.ts";
|
||||
|
||||
/**
|
||||
* Create a new guild based on a template
|
||||
@@ -23,11 +23,11 @@ export async function createGuildFromTemplate(
|
||||
data.icon = await urlToBase64(data.icon);
|
||||
}
|
||||
|
||||
const result = await rest.runMethod(
|
||||
// TODO: discordeno guild?
|
||||
|
||||
return await rest.runMethod<Guild>(
|
||||
"post",
|
||||
endpoints.GUILD_TEMPLATE(templateCode),
|
||||
data,
|
||||
);
|
||||
|
||||
return snakeKeysToCamelCase<Guild>(result);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
|
||||
import { Template } from "../../types/templates/template.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
/**
|
||||
* Creates a template for the guild.
|
||||
@@ -24,11 +23,9 @@ export async function createGuildTemplate(
|
||||
throw new Error("The description can only be in between 0-120 characters.");
|
||||
}
|
||||
|
||||
const template = await rest.runMethod<DiscordTemplate>(
|
||||
return await rest.runMethod<Template>(
|
||||
"post",
|
||||
endpoints.GUILD_TEMPLATES(guildId),
|
||||
data,
|
||||
);
|
||||
|
||||
return snakeKeysToCamelCase<Template>(template);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
|
||||
import { Template } from "../../types/templates/template.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
/**
|
||||
* Deletes a template from a guild.
|
||||
@@ -14,10 +13,8 @@ export async function deleteGuildTemplate(
|
||||
) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
const deletedTemplate = await rest.runMethod<DiscordTemplate>(
|
||||
return await rest.runMethod<Template>(
|
||||
"delete",
|
||||
`${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`,
|
||||
);
|
||||
|
||||
return snakeKeysToCamelCase<Template>(deletedTemplate);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { ModifyGuildTemplate } from "../../types/templates/modify_guild_template.ts";
|
||||
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
|
||||
import { Template } from "../../types/templates/template.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
/**
|
||||
* Edit a template's metadata.
|
||||
@@ -24,11 +23,9 @@ export async function editGuildTemplate(
|
||||
throw new Error("The description can only be in between 0-120 characters.");
|
||||
}
|
||||
|
||||
const template = await rest.runMethod<DiscordTemplate>(
|
||||
return await rest.runMethod<Template>(
|
||||
"patch",
|
||||
`${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`,
|
||||
data,
|
||||
);
|
||||
|
||||
return snakeKeysToCamelCase<Template>(template);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
|
||||
import { Template } from "../../types/templates/template.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
/**
|
||||
* Returns an array of templates.
|
||||
@@ -12,15 +11,15 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
export async function getGuildTemplates(guildId: string) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
const templates = (await rest.runMethod(
|
||||
const templates = await rest.runMethod<Template[]>(
|
||||
"get",
|
||||
endpoints.GUILD_TEMPLATES(guildId),
|
||||
)) as DiscordTemplate[];
|
||||
);
|
||||
|
||||
return new Collection(
|
||||
templates.map((template) => [
|
||||
template.code,
|
||||
snakeKeysToCamelCase<Template>(template),
|
||||
template,
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
|
||||
import { Template } from "../../types/templates/template.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
/** Returns the guild template if it exists */
|
||||
export async function getTemplate(templateCode: string) {
|
||||
const template = await rest.runMethod<DiscordTemplate>(
|
||||
return await rest.runMethod<Template>(
|
||||
"get",
|
||||
endpoints.GUILD_TEMPLATE(templateCode),
|
||||
);
|
||||
|
||||
return snakeKeysToCamelCase<Template>(template);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { DiscordTemplate, Template } from "../../types/templates/template.ts";
|
||||
import { Template } from "../../types/templates/template.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
|
||||
/**
|
||||
* Syncs the template to the guild's current state.
|
||||
@@ -11,10 +10,8 @@ import { snakeKeysToCamelCase } from "../../util/utils.ts";
|
||||
export async function syncGuildTemplate(guildId: string, templateCode: string) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
const template = await rest.runMethod<DiscordTemplate>(
|
||||
return await rest.runMethod<Template>(
|
||||
"put",
|
||||
`${endpoints.GUILD_TEMPLATES(guildId)}/${templateCode}`,
|
||||
);
|
||||
|
||||
return snakeKeysToCamelCase<Template>(template);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user