Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Text in Guild Voice Channels #1298

Merged
merged 21 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const {
StageInstance,
StoreChannel,
TextChannel,
TextVoiceChannel,
ThreadChannel,
ThreadMember,
UnavailableGuild,
Expand Down
84 changes: 58 additions & 26 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ declare namespace Eris {
type AnyChannel = AnyGuildChannel | PrivateChannel;
type AnyGuildChannel = GuildTextableChannel | AnyVoiceChannel | CategoryChannel | StoreChannel;
type AnyThreadChannel = NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel | ThreadChannel;
type AnyVoiceChannel = VoiceChannel | StageChannel;
type GuildTextableChannel = TextChannel | NewsChannel;
type AnyVoiceChannel = TextVoiceChannel | StageChannel;
type GuildTextableChannel = TextChannel | TextVoiceChannel | NewsChannel;
type GuildTextableWithThread = GuildTextableChannel | AnyThreadChannel;
type InviteChannel = InvitePartialChannel | Exclude<AnyGuildChannel, CategoryChannel | AnyThreadChannel>;
type PossiblyUncachedTextable = Textable | Uncached;
Expand All @@ -66,8 +66,8 @@ declare namespace Eris {
type GuildTextChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_TEXT" | "GUILD_NEWS">];
type GuildThreadChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_NEWS_THREAD" | "GUILD_PRIVATE_THREAD" | "GUILD_PUBLIC_THREAD">];
type GuildPublicThreadChannelTypes = Exclude<GuildThreadChannelTypes, Constants["ChannelTypes"]["GUILD_PRIVATE_THREAD"]>;
type GuildVoiceChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_VOICE" | "GUILD_STAGE">];
type PrivateChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "DM" | "GROUP_DM">];
type TextVoiceChannelTypes = Constants["ChannelTypes"][keyof Pick<Constants["ChannelTypes"], "GUILD_VOICE" | "GUILD_STAGE">];

// Command
type CommandGenerator = CommandGeneratorFunction | MessageContent | MessageContent[] | CommandGeneratorFunction[];
Expand Down Expand Up @@ -293,10 +293,12 @@ declare namespace Eris {
before?: string;
limit?: number;
}
interface GuildTextable extends Textable {
interface GuildPinnable extends Pinnable {
lastPinTimestamp: number | null;
topic?: string | null;
}
interface GuildTextable extends Textable {
rateLimitPerUser: number;
topic: string | null;
createWebhook(options: { name: string; avatar?: string | null }, reason?: string): Promise<Webhook>;
deleteMessages(messageIDs: string[], reason?: string): Promise<void>;
getWebhooks(): Promise<Webhook[]>;
Expand All @@ -316,6 +318,11 @@ declare namespace Eris {
type: number;
user_limit?: number;
}
interface Pinnable {
getPins(): Promise<Message[]>;
pinMessage(messageID: string): Promise<void>;
unpinMessage(messageID: string): Promise<void>;
}
interface PurgeChannelOptions {
after?: string;
before?: string;
Expand All @@ -339,14 +346,12 @@ declare namespace Eris {
getMessages(options?: GetMessagesOptions): Promise<Message<this>[]>;
/** @deprecated */
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message[]>;
getPins(): Promise<Message[]>;
pinMessage(messageID: string): Promise<void>;
removeMessageReaction(messageID: string, reaction: string, userID?: string): Promise<void>;
sendTyping(): Promise<void>;
unpinMessage(messageID: string): Promise<void>;
unsendMessage(messageID: string): Promise<void>;
}
interface ThreadTextable extends Textable {
// @ts-ignore ts(2430) - ThreadTextable can't properly extend Textable because of getMessageReaction deprecated overload
interface ThreadTextable extends Textable, Pinnable {
lastPinTimestamp?: number;
deleteMessages(messageIDs: string[], reason?: string): Promise<void>;
getMembers(): Promise<ThreadMember[]>;
Expand Down Expand Up @@ -621,13 +626,6 @@ declare namespace Eris {
topic: string | null;
type: GuildTextChannelTypes;
}
interface OldGuildVoiceChannel extends OldGuildChannel {
bitrate: number;
rtcRegion: string | null;
type: GuildVoiceChannelTypes;
userLimit: number;
videoQualityMode: VideoQualityMode;
}
interface OldMember {
avatar: string | null;
communicationDisabledUntil: number | null;
Expand Down Expand Up @@ -665,6 +663,13 @@ declare namespace Eris {
privacyLevel: StageInstancePrivacyLevel;
topic: string;
}
interface OldTextVoiceChannel extends OldGuildChannel {
bitrate: number;
rtcRegion: string | null;
type: TextVoiceChannelTypes;
userLimit: number;
videoQualityMode: VideoQualityMode;
}
interface OldThread {
name: string;
rateLimitPerUser: number;
Expand All @@ -691,7 +696,7 @@ declare namespace Eris {
channelPinUpdate: [channel: TextableChannel, timestamp: number, oldTimestamp: number];
channelRecipientAdd: [channel: GroupChannel, user: User];
channelRecipientRemove: [channel: GroupChannel, user: User];
channelUpdate: [channel: AnyGuildChannel, oldChannel: OldGuildChannel | OldGuildTextChannel | OldGuildVoiceChannel]
channelUpdate: [channel: AnyGuildChannel, oldChannel: OldGuildChannel | OldGuildTextChannel | OldTextVoiceChannel]
| [channel: GroupChannel, oldChannel: OldGroupChannel];
connect: [id: number];
debug: [message: string, id?: number];
Expand Down Expand Up @@ -2134,7 +2139,7 @@ declare namespace Eris {
name: string,
type: Constants["ChannelTypes"]["GUILD_VOICE"],
options?: CreateChannelOptions
): Promise<VoiceChannel>;
): Promise<TextVoiceChannel>;
createChannel(
guildID: string,
name: string,
Expand Down Expand Up @@ -2180,7 +2185,7 @@ declare namespace Eris {
type: Constants["ChannelTypes"]["GUILD_VOICE"],
reason?: string,
options?: CreateChannelOptions | string
): Promise<VoiceChannel>;
): Promise<TextVoiceChannel>;
/** @deprecated */
createChannel(
guildID: string,
Expand Down Expand Up @@ -2676,7 +2681,7 @@ declare namespace Eris {
bulkEditCommands(commands: ApplicationCommandStructure[]): Promise<ApplicationCommand[]>;
createChannel(name: string): Promise<TextChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_TEXT"], options?: CreateChannelOptions): Promise<TextChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_VOICE"], options?: CreateChannelOptions): Promise<VoiceChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_VOICE"], options?: CreateChannelOptions): Promise<TextVoiceChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_CATEGORY"], options?: CreateChannelOptions): Promise<CategoryChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_NEWS"], options?: CreateChannelOptions | string): Promise<NewsChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_STORE"], options?: CreateChannelOptions | string): Promise<StoreChannel>;
Expand All @@ -2685,7 +2690,7 @@ declare namespace Eris {
/** @deprecated */
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_TEXT"], reason?: string, options?: CreateChannelOptions | string): Promise<TextChannel>;
/** @deprecated */
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_VOICE"], reason?: string, options?: CreateChannelOptions | string): Promise<VoiceChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_VOICE"], reason?: string, options?: CreateChannelOptions | string): Promise<TextVoiceChannel>;
/** @deprecated */
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_CATEGORY"], reason?: string, options?: CreateChannelOptions | string): Promise<CategoryChannel>;
/** @deprecated */
Expand Down Expand Up @@ -2882,6 +2887,33 @@ declare namespace Eris {
toJSON(props?: string[]): JSONCache;
}

export class TextVoiceChannel extends VoiceChannel implements GuildTextable {
lastMessageID: string;
messages: Collection<Message<this>>;
rateLimitPerUser: number;
addMessageReaction(messageID: string, reaction: string): Promise<void>;
/** @deprecated */
addMessageReaction(messageID: string, reaction: string, userID: string): Promise<void>;
createMessage(content: MessageContent, file?: FileContent | FileContent[]): Promise<Message<this>>;
createWebhook(options: { name: string; avatar?: string | null }, reason?: string): Promise<Webhook>;
deleteMessage(messageID: string, reason?: string): Promise<void>;
deleteMessages(messageIDs: string[], reason?: string): Promise<void>;
editMessage(messageID: string, content: MessageContentEdit): Promise<Message<this>>;
getMessage(messageID: string): Promise<Message<this>>;
getMessageReaction(messageID: string, reaction: string, options?: GetMessageReactionOptions): Promise<User[]>;
/** @deprecated */
getMessageReaction(messageID: string, reaction: string, limit?: number, before?: string, after?: string): Promise<User[]>;
getMessages(options?: GetMessagesOptions): Promise<Message<this>[]>;
/** @deprecated */
getMessages(limit?: number, before?: string, after?: string, around?: string): Promise<Message[]>;
getWebhooks(): Promise<Webhook[]>;
purge(options: PurgeChannelOptions): Promise<number>;
removeMessageReaction(messageID: string, reaction: string, userID?: string): Promise<void>;
removeMessageReactionEmoji(messageID: string, reaction: string): Promise<void>;
removeMessageReactions(messageID: string): Promise<void>;
sendTyping(): Promise<void>;
unsendMessage(messageID: string): Promise<void>;
}
export class Interaction extends Base {
acknowledged: boolean;
applicationID: string;
Expand Down Expand Up @@ -3122,7 +3154,7 @@ declare namespace Eris {
}

// News channel rate limit is always 0
export class NewsChannel extends TextChannel {
export class NewsChannel extends TextChannel implements GuildPinnable {
rateLimitPerUser: 0;
type: Constants["ChannelTypes"]["GUILD_NEWS"];
createInvite(options?: CreateInviteOptions, reason?: string): Promise<Invite<"withMetadata", this>>;
Expand Down Expand Up @@ -3175,7 +3207,7 @@ declare namespace Eris {
stop(e: Error, source: Duplex): void;
}

export class PrivateChannel extends Channel implements Textable {
export class PrivateChannel extends Channel implements Textable, Pinnable {
lastMessageID: string;
messages: Collection<Message<this>>;
recipient: User;
Expand Down Expand Up @@ -3410,13 +3442,13 @@ declare namespace Eris {
edit(options: Omit<EditChannelOptions, "icon" | "ownerID">, reason?: string): Promise<this>;
}

export class TextChannel extends GuildChannel implements GuildTextable, Invitable {
export class TextChannel extends GuildChannel implements GuildTextable, Invitable, GuildPinnable {
defaultAutoArchiveDuration: AutoArchiveDuration;
lastMessageID: string;
lastPinTimestamp: number | null;
messages: Collection<Message<this>>;
rateLimitPerUser: number;
topic: string | null;
topic?: string | null;
type: GuildTextChannelTypes;
constructor(data: BaseData, client: Client, messageLimit: number);
addMessageReaction(messageID: string, reaction: string): Promise<void>;
Expand Down Expand Up @@ -3547,7 +3579,7 @@ declare namespace Eris {
export class VoiceChannel extends GuildChannel implements Invitable {
bitrate: number;
rtcRegion: string | null;
type: GuildVoiceChannelTypes;
type: TextVoiceChannelTypes;
userLimit: number;
videoQualityMode: VideoQualityMode;
voiceMembers: Collection<Member>;
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Eris.StageChannel = require("./lib/structures/StageChannel");
Eris.StageInstance = require("./lib/structures/StageInstance");
Eris.StoreChannel = require("./lib/structures/StoreChannel");
Eris.TextChannel = require("./lib/structures/TextChannel");
Eris.TextVoiceChannel = require("./lib/structures/TextVoiceChannel");
Eris.ThreadChannel = require("./lib/structures/ThreadChannel");
Eris.ThreadMember = require("./lib/structures/ThreadMember");
Eris.UnavailableGuild = require("./lib/structures/UnavailableGuild");
Expand Down
10 changes: 5 additions & 5 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class Client extends EventEmitter {
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @arg {String} [options.topic] The topic of the channel (text channels only)
* @arg {Number} [options.userLimit] The channel user limit (voice channels only)
* @returns {Promise<CategoryChannel | TextChannel | VoiceChannel>}
* @returns {Promise<CategoryChannel | TextChannel | TextVoiceChannel>}
*/
createChannel(guildID, name, type, reason, options = {}) {
if(typeof options === "string") { // This used to be parentID, back-compat
Expand Down Expand Up @@ -1248,7 +1248,7 @@ class Client extends EventEmitter {
* @arg {Number} [options.userLimit] The channel user limit (guild voice channels only)
* @arg {Number} [options.videoQualityMode] The camera video quality mode of the channel (guild voice channels only). `1` is auto, `2` is 720p
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise<CategoryChannel | GroupChannel | TextChannel | VoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>}
* @returns {Promise<CategoryChannel | GroupChannel | TextChannel | TextVoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>}
*/
editChannel(channelID, options, reason) {
return this.requestHandler.request("PATCH", Endpoints.CHANNEL(channelID), true, {
Expand Down Expand Up @@ -2147,7 +2147,7 @@ class Client extends EventEmitter {
/**
* Get a Channel object from a channel ID
* @arg {String} channelID The ID of the channel
* @returns {CategoryChannel | GroupChannel | PrivateChannel | TextChannel | VoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel}
* @returns {CategoryChannel | GroupChannel | PrivateChannel | TextChannel | TextVoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel}
*/
getChannel(channelID) {
if(!channelID) {
Expand Down Expand Up @@ -2661,7 +2661,7 @@ class Client extends EventEmitter {
/**
* Get a channel's data via the REST API. REST mode is required to use this endpoint.
* @arg {String} channelID The ID of the channel
* @returns {Promise<CategoryChannel | GroupChannel | PrivateChannel | TextChannel | VoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>}
* @returns {Promise<CategoryChannel | GroupChannel | PrivateChannel | TextChannel | TextVoiceChannel | NewsChannel | NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>}
*/
getRESTChannel(channelID) {
if(!this.options.restMode) {
Expand Down Expand Up @@ -2689,7 +2689,7 @@ class Client extends EventEmitter {
/**
* Get a guild's channels via the REST API. REST mode is required to use this endpoint.
* @arg {String} guildID The ID of the guild
* @returns {Promise<Array<CategoryChannel> | Array<TextChannel> | Array<VoiceChannel> | Array<NewsChannel>>}
* @returns {Promise<Array<CategoryChannel> | Array<TextChannel> | Array<TextVoiceChannel> | Array<NewsChannel>>}
*/
getRESTGuildChannels(guildID) {
if(!this.options.restMode) {
Expand Down
14 changes: 7 additions & 7 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ class Shard extends EventEmitter {
* Fired when a guild member switches voice channels
* @event Client#voiceChannelSwitch
* @prop {Member} member The member
* @prop {VoiceChannel | StageChannel} newChannel The new voice channel
* @prop {VoiceChannel | StageChannel} oldChannel The old voice channel
* @prop {TextVoiceChannel | StageChannel} newChannel The new voice channel
* @prop {TextVoiceChannel | StageChannel} oldChannel The old voice channel
*/
oldChannel.voiceMembers.remove(member);
this.emit("voiceChannelSwitch", newChannel.voiceMembers.add(member, guild), newChannel, oldChannel);
Expand All @@ -791,7 +791,7 @@ class Shard extends EventEmitter {
* Fired when a guild member joins a voice channel. This event is not fired when a member switches voice channels, see `voiceChannelSwitch`
* @event Client#voiceChannelJoin
* @prop {Member} member The member
* @prop {VoiceChannel | StageChannel} newChannel The voice channel
* @prop {TextVoiceChannel | StageChannel} newChannel The voice channel
*/
this.emit("voiceChannelJoin", newChannel.voiceMembers.add(member, guild), newChannel);
}
Expand All @@ -801,7 +801,7 @@ class Shard extends EventEmitter {
* Fired when a guild member leaves a voice channel. This event is not fired when a member switches voice channels, see `voiceChannelSwitch`
* @event Client#voiceChannelLeave
* @prop {Member?} member The member
* @prop {VoiceChannel | StageChannel} oldChannel The voice channel
* @prop {TextVoiceChannel | StageChannel} oldChannel The voice channel
*/
this.emit("voiceChannelLeave", member, oldChannel);
}
Expand Down Expand Up @@ -1500,7 +1500,7 @@ class Shard extends EventEmitter {
/**
* Fired when a channel is created
* @event Client#channelCreate
* @prop {TextChannel | VoiceChannel | CategoryChannel | StoreChannel | NewsChannel | GuildChannel} channel The channel
* @prop {TextChannel | TextVoiceChannel | CategoryChannel | StoreChannel | NewsChannel | GuildChannel} channel The channel
*/
this.emit("channelCreate", channel);
} else {
Expand Down Expand Up @@ -1571,7 +1571,7 @@ class Shard extends EventEmitter {
/**
* Fired when a channel is updated
* @event Client#channelUpdate
* @prop {TextChannel | VoiceChannel | CategoryChannel | StoreChannel | NewsChannel | GuildChannel | PrivateChannel} channel The updated channel
* @prop {TextChannel | TextVoiceChannel | CategoryChannel | StoreChannel | NewsChannel | GuildChannel | PrivateChannel} channel The updated channel
* @prop {Object} oldChannel The old channel data
* @prop {Number} oldChannel.bitrate The bitrate of the channel (voice channels only)
* @prop {String} oldChannel.name The name of the channel
Expand All @@ -1598,7 +1598,7 @@ class Shard extends EventEmitter {
/**
* Fired when a channel is deleted
* @event Client#channelDelete
* @prop {PrivateChannel | TextChannel | NewsChannel | VoiceChannel | CategoryChannel} channel The channel
* @prop {PrivateChannel | TextChannel | NewsChannel | TextVoiceChannel | CategoryChannel} channel The channel
*/
this.emit("channelDelete", channel);
}
Expand Down
Loading