mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import type { RESTGetAPIChannelMessageReactionUsersQuery } from 'discord-api-types/v10';
|
|
import { User } from '../../structures';
|
|
import { encodeEmoji, resolveEmoji } from '../../structures/extra/functions';
|
|
import type { EmojiResolvable } from '../types/resolvables';
|
|
import { BaseShorter } from './base';
|
|
|
|
export class ReactionShorter extends BaseShorter {
|
|
async add(messageId: string, channelId: string, emoji: EmojiResolvable): Promise<void> {
|
|
const rawEmoji = await resolveEmoji(emoji, this.client.cache);
|
|
|
|
if (!rawEmoji) {
|
|
throw new Error('Emoji no resolvable');
|
|
}
|
|
|
|
return this.client.proxy.channels(channelId).messages(messageId).reactions(encodeEmoji(rawEmoji))('@me').put({});
|
|
}
|
|
|
|
async delete(messageId: string, channelId: string, emoji: EmojiResolvable, userId = '@me'): Promise<void> {
|
|
const rawEmoji = await resolveEmoji(emoji, this.client.cache);
|
|
|
|
if (!rawEmoji) {
|
|
throw new Error('Emoji no resolvable');
|
|
}
|
|
|
|
return this.client.proxy.channels(channelId).messages(messageId).reactions(encodeEmoji(rawEmoji))(userId).delete();
|
|
}
|
|
|
|
async fetch(
|
|
messageId: string,
|
|
channelId: string,
|
|
emoji: EmojiResolvable,
|
|
query?: RESTGetAPIChannelMessageReactionUsersQuery,
|
|
): Promise<User[]> {
|
|
const rawEmoji = await resolveEmoji(emoji, this.client.cache);
|
|
|
|
if (!rawEmoji) {
|
|
throw new Error('Emoji no resolvable');
|
|
}
|
|
|
|
return this.client.proxy
|
|
.channels(channelId)
|
|
.messages(messageId)
|
|
.reactions(encodeEmoji(rawEmoji))
|
|
.get({ query })
|
|
.then(u => u.map(user => new User(this.client, user)));
|
|
}
|
|
|
|
async purge(messageId: string, channelId: string, emoji?: EmojiResolvable): Promise<void> {
|
|
if (!emoji) {
|
|
return this.client.proxy.channels(channelId).messages(messageId).reactions.delete();
|
|
}
|
|
const rawEmoji = await resolveEmoji(emoji, this.client.cache);
|
|
|
|
if (!rawEmoji) {
|
|
throw new Error('Emoji no resolvable');
|
|
}
|
|
|
|
return this.client.proxy.channels(channelId).messages(messageId).reactions(encodeEmoji(rawEmoji)).delete();
|
|
}
|
|
}
|