mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 21:16:09 +00:00
feat: Message.pin/unpin TextChannel.pinMessage/unpinMessage
This commit is contained in:
parent
6e57f95a4d
commit
486fcbe289
@ -1,7 +1,13 @@
|
||||
import type { Model } from "./Base.ts";
|
||||
import type { Snowflake } from "../util/Snowflake.ts";
|
||||
import type { Session } from "../session/Session.ts";
|
||||
import type { DiscordEmoji, DiscordGuild, DiscordMemberWithUser, DiscordInviteMetadata, DiscordRole } from "../vendor/external.ts";
|
||||
import type {
|
||||
DiscordEmoji,
|
||||
DiscordGuild,
|
||||
DiscordInviteMetadata,
|
||||
DiscordMemberWithUser,
|
||||
DiscordRole,
|
||||
} from "../vendor/external.ts";
|
||||
import type { GetInvite } from "../util/Routes.ts";
|
||||
import {
|
||||
DefaultMessageNotificationLevels,
|
||||
@ -56,7 +62,7 @@ export interface CreateGuildBan {
|
||||
|
||||
/**
|
||||
* @link https://discord.com/developers/docs/resources/guild#modify-guild-member
|
||||
* */
|
||||
*/
|
||||
export interface ModifyGuildMember {
|
||||
nick?: string;
|
||||
roles?: Snowflake[];
|
||||
@ -68,11 +74,11 @@ export interface ModifyGuildMember {
|
||||
|
||||
/**
|
||||
* @link https://discord.com/developers/docs/resources/guild#begin-guild-prune
|
||||
* */
|
||||
*/
|
||||
export interface BeginGuildPrune {
|
||||
days?: number;
|
||||
computePruneCount?: boolean;
|
||||
includeRoles?: Snowflake[];
|
||||
days?: number;
|
||||
computePruneCount?: boolean;
|
||||
includeRoles?: Snowflake[];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -110,8 +116,8 @@ export class Guild extends BaseGuild implements Model {
|
||||
emojis: GuildEmoji[];
|
||||
|
||||
/**
|
||||
* 'null' would reset the nickname
|
||||
* */
|
||||
* 'null' would reset the nickname
|
||||
*/
|
||||
async editBotNickname(options: { nick: string | null; reason?: string }) {
|
||||
const result = await this.session.rest.runMethod<{ nick?: string } | undefined>(
|
||||
this.session.rest,
|
||||
@ -286,8 +292,10 @@ export class Guild extends BaseGuild implements Model {
|
||||
mute: options.mute,
|
||||
deaf: options.deaf,
|
||||
channel_id: options.channelId,
|
||||
communication_disabled_until: options.communicationDisabledUntil ? new Date(options.communicationDisabledUntil).toISOString() : undefined,
|
||||
}
|
||||
communication_disabled_until: options.communicationDisabledUntil
|
||||
? new Date(options.communicationDisabledUntil).toISOString()
|
||||
: undefined,
|
||||
},
|
||||
);
|
||||
|
||||
return new Member(this.session, member, this.id);
|
||||
|
@ -73,7 +73,11 @@ export class Member implements Model {
|
||||
}
|
||||
|
||||
async edit(options: ModifyGuildMember): Promise<Member> {
|
||||
const member = await Guild.prototype.editMember.call({ id: this.guildId, session: this.session }, this.user.id, options);
|
||||
const member = await Guild.prototype.editMember.call(
|
||||
{ id: this.guildId, session: this.session },
|
||||
this.user.id,
|
||||
options,
|
||||
);
|
||||
|
||||
return member;
|
||||
}
|
||||
|
@ -87,6 +87,22 @@ export class Message implements Model {
|
||||
return `https://discord.com/channels/${this.guildId ?? "@me"}/${this.channelId}/${this.id}`;
|
||||
}
|
||||
|
||||
async pin() {
|
||||
await this.session.rest.runMethod<undefined>(
|
||||
this.session.rest,
|
||||
"PUT",
|
||||
Routes.CHANNEL_PIN(this.channelId, this.id),
|
||||
);
|
||||
}
|
||||
|
||||
async unpin() {
|
||||
await this.session.rest.runMethod<undefined>(
|
||||
this.session.rest,
|
||||
"DELETE",
|
||||
Routes.CHANNEL_PIN(this.channelId, this.id),
|
||||
);
|
||||
}
|
||||
|
||||
/** Edits the current message */
|
||||
async edit({ content, allowedMentions, flags }: EditMessage): Promise<Message> {
|
||||
const message = await this.session.rest.runMethod(
|
||||
|
@ -107,6 +107,14 @@ export class TextChannel extends GuildChannel {
|
||||
Routes.CHANNEL_TYPING(this.id),
|
||||
);
|
||||
}
|
||||
|
||||
async pinMessage(messageId: Snowflake) {
|
||||
await Message.prototype.pin.call({ id: messageId, channelId: this.id, session: this.session });
|
||||
}
|
||||
|
||||
async unpinMessage(messageId: Snowflake) {
|
||||
await Message.prototype.unpin.call({ id: messageId, channelId: this.id, session: this.session });
|
||||
}
|
||||
}
|
||||
|
||||
export default TextChannel;
|
||||
|
@ -7,12 +7,12 @@ import GuildChannel from "./GuildChannel.ts";
|
||||
|
||||
/**
|
||||
* @link https://discord.com/developers/docs/topics/gateway#update-voice-state
|
||||
* */
|
||||
*/
|
||||
export interface UpdateVoiceState {
|
||||
guildId: string;
|
||||
channelId?: string;
|
||||
selfMute: boolean;
|
||||
selfDeaf: boolean;
|
||||
guildId: string;
|
||||
channelId?: string;
|
||||
selfMute: boolean;
|
||||
selfDeaf: boolean;
|
||||
}
|
||||
|
||||
export class VoiceChannel extends GuildChannel {
|
||||
@ -36,7 +36,7 @@ export class VoiceChannel extends GuildChannel {
|
||||
|
||||
/**
|
||||
* This function was gathered from Discordeno it may not work
|
||||
* */
|
||||
*/
|
||||
async connect(options?: UpdateVoiceState) {
|
||||
const shardId = calculateShardId(this.session.gateway, BigInt(super.guildId));
|
||||
const shard = this.session.gateway.manager.shards.get(shardId);
|
||||
|
@ -46,10 +46,6 @@ export function MESSAGE_CREATE_THREAD(channelId: Snowflake, messageId: Snowflake
|
||||
return `/channels/${channelId}/messages/${messageId}/threads`;
|
||||
}
|
||||
|
||||
export function CHANNEL_PINS(channelId: Snowflake) {
|
||||
return `/channels/${channelId}/pins`;
|
||||
}
|
||||
|
||||
/** used to send messages */
|
||||
export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions) {
|
||||
let url = `/channels/${channelId}/messages?`;
|
||||
@ -159,7 +155,7 @@ export function USER_NICK(guildId: Snowflake) {
|
||||
|
||||
/**
|
||||
* @link https://discord.com/developers/docs/resources/guild#get-guild-prune-count
|
||||
* */
|
||||
*/
|
||||
export interface GetGuildPruneCountQuery {
|
||||
days?: number;
|
||||
includeRoles?: Snowflake | Snowflake[];
|
||||
@ -173,3 +169,11 @@ export function GUILD_PRUNE(guildId: Snowflake, options?: GetGuildPruneCountQuer
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
export function CHANNEL_PIN(channelId: Snowflake, messageId: Snowflake) {
|
||||
return `/channels/${channelId}/pins/${messageId}`;
|
||||
}
|
||||
|
||||
export function CHANNEL_PINS(channelId: Snowflake) {
|
||||
return `/channels/${channelId}/pins`;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user