Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/structs/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import { EventEmitter } from "events";
import { STATUS_CODES } from "http";

import type {
APIOptions,
Snowflake,
UserSource,
Project,
PartialVote,
PaginatedVotes,
Announcement,
AnnouncementType,
APIOptions,
Method,
MetricsPayload,
PaginatedVotes,
PartialVote,
Project,
ProjectPayload,
Snowflake,
UserSource,
} from "../typings.js";

/** The API version to use */
Expand Down Expand Up @@ -198,7 +199,7 @@ export class Api extends EventEmitter {
* @returns {Promise<void>}
*/
public async postCommands(commands: APIApplicationCommand[]): Promise<void> {
await this._request("POST", "/projects/@me/commands", commands);
await this._request("PUT", "/projects/@me/commands", commands);
}

/**
Expand All @@ -222,16 +223,18 @@ export class Api extends EventEmitter {
*
* @param {string} title The announcement title. Must be between 3 and 100 characters.
* @param {string} content The announcement body text. Must be between 10 and 2,000 characters.
* @param {AnnouncementType} category The category to publish the announcement under. Defaults to `announcement` when omitted.
* @returns {Promise<Announcement>} The created announcement.
*/
public async postAnnouncement(
title: string,
content: string,
category?: AnnouncementType,
): Promise<Announcement> {
const announcement = await this._request(
"POST",
"/projects/@me/announcements",
{ title, content },
{ title, content, category },
);

return {
Expand Down
1 change: 1 addition & 0 deletions src/structs/Webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export class Webhook {
votedAt: new Date(body.data.created_at),
expiresAt: new Date(body.data.expires_at),
project: this._formatPartialProject(body.data.project),
query: body.data.query,
user: this._formatUser(body.data.user),
} as VoteCreatePayload;

Expand Down
5 changes: 5 additions & 0 deletions src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export type Platform = "discord" | "roblox";
/** A project's type */
export type ProjectType = "bot" | "server" | "game";

/** An announcement's type */
export type AnnouncementType = "announcement" | "event" | "new_feature";

/** A locale for a project's payload */
export type Locale =
| "en"
Expand Down Expand Up @@ -155,6 +158,8 @@ export interface VoteCreatePayload {
expiresAt: Date;
/** The project that received this vote */
project: PartialProject;
/** The parsed query parameters appended to the `/:id/vote` page URL */
query: Record<string, string>;
/** The user who voted for this project */
user: User;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/mocks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ export const VOTE_CREATE_PAYLOAD = {
platform: "discord",
platform_id: "160105994217586689"
},
query: {
key1: "value",
key2: "value2"
},
user: {
id: "160105994217586689",
platform_id: "160105994217586689",
Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const endpoints: MockEndpoint[] = [
},
{
pattern: "/api/v1/projects/@me/commands",
method: "POST",
method: "PUT",
data: ""
},
{
Expand Down