-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
ListChannel.ts
79 lines (72 loc) · 2.06 KB
/
ListChannel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Collection } from "@discordjs/collection";
import type { ListItemPayload, ListItemSummaryPayload } from "@guildedjs/api";
import { Channel } from "./Channel";
/**
* Represents a list channel in Guilded.
*
* @extends Channel
*/
export class ListChannel extends Channel {
/**
* The list items in this channel.
*/
readonly items = new Collection<string, ListItemPayload | ListItemSummaryPayload>();
/**
* Creates a list item in this channel.
*
* @param message - The message of the new list item.
* @param note - Optional note for the new list item.
* @returns A Promise that resolves with the newly created list item payload.
*/
createItem(message: string, note?: string): Promise<ListItemPayload> {
return this.client.lists.create(this.id, {
message,
note: note
? {
content: note,
}
: undefined,
});
}
/**
* Fetches a list item by its ID.
*
* @param itemId - The ID of the list item to fetch.
* @returns A Promise that resolves with the list item payload.
*/
async getItem(itemId: string): Promise<ListItemPayload> {
const data = await this.client.lists.fetch(this.id, itemId);
this.items.set(data.id, data);
return data;
}
/**
* Fetches all list items in this channel.
*
* @returns A Promise that resolves with an array of list item summary payloads.
*/
async getItems(): Promise<ListItemSummaryPayload[]> {
const data = await this.client.lists.fetchMany(this.id);
for (const item of data) {
this.items.set(item.id, item);
}
return data;
}
/**
* Completes a list item.
*
* @param itemId - The ID of the list item to complete.
* @returns A Promise that resolves when the list item is completed.
*/
completeItem(itemId: string): Promise<void> {
return this.client.lists.complete(this.id, itemId);
}
/**
* Uncompletes a list item.
*
* @param itemId - The ID of the list item to uncomplete.
* @returns A Promise that resolves when the list item is uncompleted.
*/
uncompleteItem(itemId: string): Promise<void> {
return this.client.lists.uncomplete(this.id, itemId);
}
}