Skip to content

Commit

Permalink
add emoji registration methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Starman3787 committed Nov 18, 2024
1 parent d2b8bd1 commit 152e361
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,40 @@ class Client extends EventsEmitter {
);
}

/**
* Fetches the emojis for this client.
* @returns {Array<Object>}
* @public
* @method
* @async
*/
async fetchEmojis() {
return this.request.makeRequest("getClientEmojis", [this.user.id]);
}

/**
* Creates an emoji for this client.
* @param {Object} emoji The emoji to create.
* @param {String} emoji.name The name of the emoji.
* @param {String} emoji.image The image of the emoji (base64, should start with "data:image/png;base64,").
* @returns {Promise<void>}
* @public
* @method
* @async
* @throws {TypeError}
*/
async createEmoji({ name, image }) {
if (typeof name !== "string")
throw new TypeError(`GLUON: Name is not a string. Got ${typeof name}`);
if (typeof image !== "string")
throw new TypeError(`GLUON: Image is not a string. Got ${typeof image}`);

return this.request.makeRequest("createClientEmoji", [this.user.id], {
name,
image,
});
}

/**
* Sets the bot's status across all shards.
* @param {Object} status Status options.
Expand Down
20 changes: 20 additions & 0 deletions src/rest/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,24 @@ export default {
return HttpResponse.json(TEST_DATA.TEXT_CHANNEL);
},
},
getClientEmojis: {
path: (client_id) => {
return `/applications/${client_id}/emojis`;
},
method: "GET",
majorParams: [0],
mockResponse: ({ params } = {}) => {
return HttpResponse.json([TEST_DATA.EMOJI]);
},
},
postAddClientEmoji: {
path: (client_id) => {
return `/applications/${client_id}/emojis`;
},
method: "POST",
majorParams: [0],
mockResponse: ({ params } = {}) => {
return HttpResponse.json(TEST_DATA.EMOJI);
},
},
};
63 changes: 63 additions & 0 deletions test/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,69 @@ describe("Client", function () {
);
});
});
context("check fetchEmojis", function () {
it("should be a function", function () {
const client = new Client({
intents: INTENTS.GUILDS,
});
expect(client.fetchEmojis).to.be.a("function");
});
it("should call getGuildEmojis with the correct arguments", async function () {
const client = new Client({
intents: INTENTS.GUILDS,
});
client.request = { makeRequest: () => {} };
client.user = new User(client, TEST_DATA.CLIENT_USER);
const request = spy(client.request, "makeRequest");
await client.fetchEmojis();
expect(request).to.be.calledOnce;
expect(request).to.be.calledOnceWith("getClientEmojis", [
TEST_DATA.CLIENT_USER.id,
]);
});
});
context("check createEmoji", function () {
it("should be a function", function () {
const client = new Client({
intents: INTENTS.GUILDS,
});
expect(client.createEmoji).to.be.a("function");
});
it("should throw an error if name is not a string", async function () {
const client = new Client({
intents: INTENTS.GUILDS,
});
await expect(client.createEmoji({ name: 1 })).to.be.rejectedWith(
"GLUON: Name is not a string.",
);
});
it("should throw an error if image is not a string", async function () {
const client = new Client({
intents: INTENTS.GUILDS,
});
await expect(
client.createEmoji({ name: "test", image: 1 }),
).to.be.rejectedWith("GLUON: Image is not a string.");
});
it("should call createGuildEmoji with the correct arguments", async function () {
const client = new Client({
intents: INTENTS.GUILDS,
});
client.request = { makeRequest: () => {} };
client.user = new User(client, TEST_DATA.CLIENT_USER);
const request = spy(client.request, "makeRequest");
await client.createEmoji({ name: "test", image: "testImage" });
expect(request).to.be.calledOnce;
expect(request).to.be.calledOnceWith(
"createClientEmoji",
[TEST_DATA.CLIENT_USER.id],
{
name: "test",
image: "testImage",
},
);
});
});
context("check setStatus", function () {
it("should be a function", function () {
const client = new Client({
Expand Down

0 comments on commit 152e361

Please sign in to comment.