mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +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 { Model } from "./Base.ts";
|
||||||
import type { Snowflake } from "../util/Snowflake.ts";
|
import type { Snowflake } from "../util/Snowflake.ts";
|
||||||
import type { Session } from "../session/Session.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 type { GetInvite } from "../util/Routes.ts";
|
||||||
import {
|
import {
|
||||||
DefaultMessageNotificationLevels,
|
DefaultMessageNotificationLevels,
|
||||||
@ -56,7 +62,7 @@ export interface CreateGuildBan {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @link https://discord.com/developers/docs/resources/guild#modify-guild-member
|
* @link https://discord.com/developers/docs/resources/guild#modify-guild-member
|
||||||
* */
|
*/
|
||||||
export interface ModifyGuildMember {
|
export interface ModifyGuildMember {
|
||||||
nick?: string;
|
nick?: string;
|
||||||
roles?: Snowflake[];
|
roles?: Snowflake[];
|
||||||
@ -68,11 +74,11 @@ export interface ModifyGuildMember {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @link https://discord.com/developers/docs/resources/guild#begin-guild-prune
|
* @link https://discord.com/developers/docs/resources/guild#begin-guild-prune
|
||||||
* */
|
*/
|
||||||
export interface BeginGuildPrune {
|
export interface BeginGuildPrune {
|
||||||
days?: number;
|
days?: number;
|
||||||
computePruneCount?: boolean;
|
computePruneCount?: boolean;
|
||||||
includeRoles?: Snowflake[];
|
includeRoles?: Snowflake[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,7 +117,7 @@ export class Guild extends BaseGuild implements Model {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 'null' would reset the nickname
|
* 'null' would reset the nickname
|
||||||
* */
|
*/
|
||||||
async editBotNickname(options: { nick: string | null; reason?: string }) {
|
async editBotNickname(options: { nick: string | null; reason?: string }) {
|
||||||
const result = await this.session.rest.runMethod<{ nick?: string } | undefined>(
|
const result = await this.session.rest.runMethod<{ nick?: string } | undefined>(
|
||||||
this.session.rest,
|
this.session.rest,
|
||||||
@ -286,8 +292,10 @@ export class Guild extends BaseGuild implements Model {
|
|||||||
mute: options.mute,
|
mute: options.mute,
|
||||||
deaf: options.deaf,
|
deaf: options.deaf,
|
||||||
channel_id: options.channelId,
|
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);
|
return new Member(this.session, member, this.id);
|
||||||
|
@ -73,7 +73,11 @@ export class Member implements Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async edit(options: ModifyGuildMember): Promise<Member> {
|
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;
|
return member;
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,22 @@ export class Message implements Model {
|
|||||||
return `https://discord.com/channels/${this.guildId ?? "@me"}/${this.channelId}/${this.id}`;
|
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 */
|
/** Edits the current message */
|
||||||
async edit({ content, allowedMentions, flags }: EditMessage): Promise<Message> {
|
async edit({ content, allowedMentions, flags }: EditMessage): Promise<Message> {
|
||||||
const message = await this.session.rest.runMethod(
|
const message = await this.session.rest.runMethod(
|
||||||
|
@ -107,6 +107,14 @@ export class TextChannel extends GuildChannel {
|
|||||||
Routes.CHANNEL_TYPING(this.id),
|
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;
|
export default TextChannel;
|
||||||
|
@ -7,12 +7,12 @@ import GuildChannel from "./GuildChannel.ts";
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @link https://discord.com/developers/docs/topics/gateway#update-voice-state
|
* @link https://discord.com/developers/docs/topics/gateway#update-voice-state
|
||||||
* */
|
*/
|
||||||
export interface UpdateVoiceState {
|
export interface UpdateVoiceState {
|
||||||
guildId: string;
|
guildId: string;
|
||||||
channelId?: string;
|
channelId?: string;
|
||||||
selfMute: boolean;
|
selfMute: boolean;
|
||||||
selfDeaf: boolean;
|
selfDeaf: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class VoiceChannel extends GuildChannel {
|
export class VoiceChannel extends GuildChannel {
|
||||||
@ -36,7 +36,7 @@ export class VoiceChannel extends GuildChannel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This function was gathered from Discordeno it may not work
|
* This function was gathered from Discordeno it may not work
|
||||||
* */
|
*/
|
||||||
async connect(options?: UpdateVoiceState) {
|
async connect(options?: UpdateVoiceState) {
|
||||||
const shardId = calculateShardId(this.session.gateway, BigInt(super.guildId));
|
const shardId = calculateShardId(this.session.gateway, BigInt(super.guildId));
|
||||||
const shard = this.session.gateway.manager.shards.get(shardId);
|
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`;
|
return `/channels/${channelId}/messages/${messageId}/threads`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function CHANNEL_PINS(channelId: Snowflake) {
|
|
||||||
return `/channels/${channelId}/pins`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** used to send messages */
|
/** used to send messages */
|
||||||
export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions) {
|
export function CHANNEL_MESSAGES(channelId: Snowflake, options?: GetMessagesOptions) {
|
||||||
let url = `/channels/${channelId}/messages?`;
|
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
|
* @link https://discord.com/developers/docs/resources/guild#get-guild-prune-count
|
||||||
* */
|
*/
|
||||||
export interface GetGuildPruneCountQuery {
|
export interface GetGuildPruneCountQuery {
|
||||||
days?: number;
|
days?: number;
|
||||||
includeRoles?: Snowflake | Snowflake[];
|
includeRoles?: Snowflake | Snowflake[];
|
||||||
@ -173,3 +169,11 @@ export function GUILD_PRUNE(guildId: Snowflake, options?: GetGuildPruneCountQuer
|
|||||||
|
|
||||||
return url;
|
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