aboutsummaryrefslogtreecommitdiff
path: root/src/lib/extensions/discord.js/BushMessageManager.ts
blob: 80b7a217d60a46e6e656fc1d07acd943b2c994d6 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { BushMessageResolvable, BushTextBasedChannel, type BushMessage } from '#lib';
import {
	CachedManager,
	MessageManager,
	type BaseFetchOptions,
	type ChannelLogsQueryOptions,
	type Collection,
	type EmojiIdentifierResolvable,
	type MessageEditOptions,
	type MessagePayload,
	type Snowflake
} from 'discord.js';
import type { RawMessageData } from 'discord.js/typings/rawDataTypes';

/**
 * Manages API methods for Messages and holds their cache.
 */
export declare class BushMessageManager
	extends CachedManager<Snowflake, BushMessage, BushMessageResolvable>
	implements MessageManager
{
	public constructor(channel: BushTextBasedChannel, iterable?: Iterable<RawMessageData>);

	/**
	 * The channel that the messages belong to
	 */
	public channel: BushTextBasedChannel;

	/**
	 * The cache of Messages
	 */
	public get cache(): Collection<Snowflake, BushMessage>;

	/**
	 * Publishes a message in an announcement channel to all channels following it, even if it's not cached.
	 * @param message The message to publish
	 */
	public crosspost(message: BushMessageResolvable): Promise<BushMessage>;

	/**
	 * Deletes a message, even if it's not cached.
	 * @param message The message to delete
	 */
	public delete(message: BushMessageResolvable): Promise<void>;

	/**
	 * Edits a message, even if it's not cached.
	 * @param message The message to edit
	 * @param options The options to edit the message
	 */
	public edit(message: BushMessageResolvable, options: string | MessagePayload | MessageEditOptions): Promise<BushMessage>;

	/**
	 * Gets a message, or messages, from this channel.
	 * <info>The returned Collection does not contain reaction users of the messages if they were not cached.
	 * Those need to be fetched separately in such a case.</info>
	 * @param message The id of the message to fetch, or query parameters.
	 * @param options Additional options for this fetch
	 * @example
	 * // Get message
	 * channel.messages.fetch('99539446449315840')
	 *   .then(message => console.log(message.content))
	 *   .catch(console.error);
	 * @example
	 * // Get messages
	 * channel.messages.fetch({ limit: 10 })
	 *   .then(messages => console.log(`Received ${messages.size} messages`))
	 *   .catch(console.error);
	 * @example
	 * // Get messages and filter by user id
	 * channel.messages.fetch()
	 *   .then(messages => console.log(`${messages.filter(m => m.author.id === '84484653687267328').size} messages`))
	 *   .catch(console.error);
	 */
	public fetch(message: Snowflake, options?: BaseFetchOptions): Promise<BushMessage>;
	public fetch(options?: ChannelLogsQueryOptions, cacheOptions?: BaseFetchOptions): Promise<Collection<Snowflake, BushMessage>>;

	/**
	 * Fetches the pinned messages of this channel and returns a collection of them.
	 * <info>The returned Collection does not contain any reaction data of the messages.
	 * Those need to be fetched separately.</info>
	 * @param {} [cache=true] Whether to cache the message(s)
	 * @example
	 * // Get pinned messages
	 * channel.messages.fetchPinned()
	 *   .then(messages => console.log(`Received ${messages.size} messages`))
	 *   .catch(console.error);
	 */
	public fetchPinned(cache?: boolean): Promise<Collection<Snowflake, BushMessage>>;

	/**
	 * Adds a reaction to a message, even if it's not cached.
	 * @param message The message to react to
	 * @param emoji The emoji to react with
	 */
	public react(message: BushMessageResolvable, emoji: EmojiIdentifierResolvable): Promise<void>;

	/**
	 * Pins a message to the channel's pinned messages, even if it's not cached.
	 * @param message The message to pin
	 */
	public pin(message: BushMessageResolvable): Promise<void>;

	/**
	 * Unpins a message from the channel's pinned messages, even if it's not cached.
	 * @param message The message to unpin
	 */
	public unpin(message: BushMessageResolvable): Promise<void>;
}