Skip to content

Commit

Permalink
Merge pull request #62 from raphckrman/dev
Browse files Browse the repository at this point in the history
Channel user/role permission overrides and hide link previews!
  • Loading branch information
pakkographic authored Sep 29, 2023
2 parents ad19126 + c2fbbba commit 5a720d5
Show file tree
Hide file tree
Showing 17 changed files with 1,127 additions and 105 deletions.
199 changes: 116 additions & 83 deletions lib/gateway/GatewayHandler.ts

Large diffs are not rendered by default.

84 changes: 83 additions & 1 deletion lib/gateway/events/ChannelHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/** @module ChannelHandler */
import { GatewayEventHandler } from "./GatewayEventHandler";
import { GatewayEvent_ServerChannelCreated, GatewayEvent_ServerChannelDeleted, GatewayEvent_ServerChannelUpdated } from "../../Constants";
import {
GatewayEvent_ChannelArchived,
GatewayEvent_ChannelCategoryRolePermissionCreated,
GatewayEvent_ChannelCategoryUserPermissionCreated,
GatewayEvent_ChannelRestored,
GatewayEvent_ChannelRolePermissionCreated,
GatewayEvent_ChannelUserPermissionCreated,
GatewayEvent_ChannelUserPermissionDeleted,
GatewayEvent_ChannelUserPermissionUpdated,
GatewayEvent_ServerChannelCreated,
GatewayEvent_ServerChannelDeleted,
GatewayEvent_ServerChannelUpdated
} from "../../Constants";
import { AnyChannel } from "../../types/channel";

/** Internal component, emitting channel events. */
Expand Down Expand Up @@ -28,6 +40,76 @@ export class ChannelHandler extends GatewayEventHandler{
this.client.emit("channelDelete", ChannelComponent);
}

async channelRolePermissionCreated(data: GatewayEvent_ChannelRolePermissionCreated): Promise<void> {
const ChannelComponent = data.channelRolePermission;
this.client.emit("channelRolePermissionCreated", ChannelComponent);
}

async channelRolePermissionUpdated(data: GatewayEvent_ChannelRolePermissionCreated): Promise<void> {
const ChannelComponent = data.channelRolePermission;
this.client.emit("channelRolePermissionUpdated", ChannelComponent);
}

async channelRolePermissionDeleted(data: GatewayEvent_ChannelRolePermissionCreated): Promise<void> {
const ChannelComponent = data.channelRolePermission;
this.client.emit("channelRolePermissionDeleted", ChannelComponent);
}

async channelUserPermissionCreated(data: GatewayEvent_ChannelUserPermissionCreated): Promise<void> {
const ChannelComponent = data.channelUserPermission;
this.client.emit("channelUserPermissionCreated", ChannelComponent);
}

async channelUserPermissionUpdated(data: GatewayEvent_ChannelUserPermissionUpdated): Promise<void> {
const ChannelComponent = data.channelUserPermission;
this.client.emit("channelUserPermissionUpdated", ChannelComponent);
}

async channelUserPermissionDeleted(data: GatewayEvent_ChannelUserPermissionDeleted): Promise<void> {
const ChannelComponent = data.channelUserPermission;
this.client.emit("channelUserPermissionDeleted", ChannelComponent);
}

async channelCategoryUserPermissionCreated(data: GatewayEvent_ChannelCategoryUserPermissionCreated): Promise<void> {
const ChannelComponent = data.channelCategoryUserPermission;
this.client.emit("channelCategoryUserPermissionCreated", ChannelComponent);
}

async channelCategoryUserPermissionUpdated(data: GatewayEvent_ChannelCategoryUserPermissionCreated): Promise<void> {
const ChannelComponent = data.channelCategoryUserPermission;
this.client.emit("channelCategoryUserPermissionUpdated", ChannelComponent);
}

async channelCategoryUserPermissionDeleted(data: GatewayEvent_ChannelCategoryUserPermissionCreated): Promise<void> {
const ChannelComponent = data.channelCategoryUserPermission;
this.client.emit("channelCategoryUserPermissionDeleted", ChannelComponent);
}

async channelCategoryRolePermissionCreated(data: GatewayEvent_ChannelCategoryRolePermissionCreated): Promise<void> {
const ChannelComponent = data.channelCategoryRolePermission;
this.client.emit("channelCategoryRolePermissionCreated", ChannelComponent);
}

async channelCategoryRolePermissionUpdated(data: GatewayEvent_ChannelCategoryRolePermissionCreated): Promise<void> {
const ChannelComponent = data.channelCategoryRolePermission;
this.client.emit("channelCategoryRolePermissionUpdated", ChannelComponent);
}

async channelCategoryRolePermissionDeleted(data: GatewayEvent_ChannelCategoryRolePermissionCreated): Promise<void> {
const ChannelComponent = data.channelCategoryRolePermission;
this.client.emit("channelCategoryRolePermissionDeleted", ChannelComponent);
}

async channelArchive(data: GatewayEvent_ChannelArchived): Promise<void> {
const ChannelComponent = this.client.util.updateChannel(data.channel);
this.client.emit("channelArchive", ChannelComponent);
}

async channelRestore(data: GatewayEvent_ChannelRestored): Promise<void> {
const ChannelComponent = this.client.util.updateChannel(data.channel);
this.client.emit("channelRestore", ChannelComponent);
}

private async addGuildChannel(guildID: string, channelID: string): Promise<void> {
if (this.client.getChannel(guildID, channelID) !== undefined) return;
const channel = await this.client.rest.channels.getChannel(channelID).catch(err => this.client.emit("warn", `Cannot register channel to cache due to: (${String(err)})`));
Expand Down
21 changes: 19 additions & 2 deletions lib/gateway/events/GuildHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ import {
GatewayEvent_ServerMemberSocialLinkUpdated,
GatewayEvent_ServerMemberUnbanned,
GatewayEvent_ServerMemberUpdated,
GatewayEvent_ServerRolesUpdated
GatewayEvent_ServerRolesUpdated,
GatewayEvent_CategoryCreated
} from "../../Constants";
import { MemberUpdateInfo } from "../../structures/MemberUpdateInfo";
import { MemberRemoveInfo } from "../../structures/MemberRemoveInfo";
import { GuildGroup } from "../../structures/GuildGroup";
import { GuildCategory } from "../../structures/GuildCategory";

/** Internal component, emitting guild events. */
export class GuildHandler extends GatewayEventHandler {
Expand Down Expand Up @@ -127,6 +129,21 @@ export class GuildHandler extends GatewayEventHandler {
const guild = this.client.guilds.get(data.serverId);
const role = guild?.roles.update(new GuildRole(data.role, this.client)) ?? new GuildRole(data.role, this.client);
guild?.roles.delete(data.role.id);
this.client.emit("guildRoleCreate", role);
this.client.emit("guildRoleDelete", role);
}

guildCategoryCreate(data: GatewayEvent_CategoryCreated): void {
const category = new GuildCategory(data.category, this.client);
this.client.emit("guildCategoryCreate", category);
}

guildCategoryUpdate(data: GatewayEvent_CategoryCreated): void {
const category = new GuildCategory(data.category, this.client);
this.client.emit("guildCategoryUpdate", category);
}

guildCategoryDelete(data: GatewayEvent_CategoryCreated): void {
const category = new GuildCategory(data.category, this.client);
this.client.emit("guildCategoryDelete", category);
}
}
17 changes: 17 additions & 0 deletions lib/gateway/events/MessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { GatewayEventHandler } from "./GatewayEventHandler";
import { Message } from "../../structures/Message";
import { MessageReactionInfo } from "../../structures/MessageReactionInfo";
import {
GatewayEvent_ChannelMessagePinned,
GatewayEvent_ChannelMessageReactionCreated,
GatewayEvent_ChannelMessageReactionDeleted,
GatewayEvent_ChannelMessageReactionManyDeleted,
GatewayEvent_ChannelMessageUnpinned,
GatewayEvent_ChatMessageCreated,
GatewayEvent_ChatMessageDeleted,
GatewayEvent_ChatMessageUpdated
Expand Down Expand Up @@ -75,6 +77,21 @@ export class MessageHandler extends GatewayEventHandler {
this.client.emit("reactionBulkRemove", BulkRemoveInfo);
}

async messagePin(data: GatewayEvent_ChannelMessagePinned): Promise<void> {
if (this.client.params.waitForCaching) await this.addGuildChannel(data.serverId, data.message.channelId);
else void this.addGuildChannel(data.serverId, data.message.channelId);
const channel = this.client.getChannel<TextChannel>(data.serverId, data.message.channelId);
const MessageComponent = channel?.messages?.update(data.message) ?? new Message(data.message, this.client);
this.client.emit("messagePin", MessageComponent);
}

async messageUnpin(data: GatewayEvent_ChannelMessageUnpinned): Promise<void> {
if (this.client.params.waitForCaching) await this.addGuildChannel(data.serverId, data.message.channelId);
else void this.addGuildChannel(data.serverId, data.message.channelId);
const channel = this.client.getChannel<TextChannel>(data.serverId, data.message.channelId);
const MessageComponent = channel?.messages?.update(data.message) ?? new Message(data.message, this.client);
this.client.emit("messageUnpin", MessageComponent);
}

private async addGuildChannel(guildID: string, channelID: string): Promise<void> {
if (this.client.getChannel(guildID, channelID) !== undefined) return;
Expand Down
8 changes: 8 additions & 0 deletions lib/rest/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ export const CHANNEL_ANNOUNCEMENT_COMMENTS = (channelID: string, announcementID:
export const CHANNEL_ANNOUNCEMENT_COMMENT = (channelID: string, announcementID: string, commentID: number) => `/channels/${channelID}/announcements/${announcementID}/comments/${commentID}`;
export const CHANNEL_ANNOUNCEMENT_COMMENT_EMOTES = (channelID: string, announcementID: string, commentID: number) => `/channels/${channelID}/announcements/${announcementID}/comments/${commentID}/emotes`;
export const CHANNEL_ANNOUNCEMENT_COMMENT_EMOTE = (channelID: string, announcementID: string, commentID: number, emoteID: number) => `/channels/${channelID}/announcements/${announcementID}/comments/${commentID}/emotes/${emoteID}`;
export const CHANNEL_ROLE_PERMISSION = (serverID: string, channelID: string, roleID: number) => `/servers/${serverID}/channels/${channelID}/permissions/roles/${roleID}`;
export const CHANNEL_ROLE_MANY_PERMISSION = (serverID: string, channelID: string) => `/servers/${serverID}/channels/${channelID}/permissions/roles`;
export const CHANNEL_USER_PERMISSION = (serverID: string, channelID: string, userID: string) => `/servers/${serverID}/channels/${channelID}/permissions/users/${userID}`;
export const CHANNEL_USER_MANY_PERMISSION = (serverID: string, channelID: string) => `/servers/${serverID}/channels/${channelID}/permissions/users`;
export const CHANNEL_CATEGORY_USER_PERMISSION = (serverID: string, categoryID: number, userID: string) => `/servers/${serverID}/categories/${categoryID}/permissions/users/${userID}`;
export const CHANNEL_CATEGORY_USER_MANY_PERMISSION = (serverID: string, categoryID: number) => `/servers/${serverID}/categories/${categoryID}/permissions/users`;
export const CHANNEL_CATEGORY_ROLE_PERMISSION = (serverID: string, categoryID: number, roleID: number) => `/servers/${serverID}/categories/${categoryID}/permissions/roles/${roleID}`;
export const CHANNEL_CATEGORY_ROLE_MANY_PERMISSION = (serverID: string, categoryID: number) => `/servers/${serverID}/categories/${categoryID}/permissions/roles`;

export const MEMBER_NICKNAME = (guildID: string, memberID: string) => `/servers/${guildID}/members/${memberID}/nickname`;

Expand Down
Loading

0 comments on commit 5a720d5

Please sign in to comment.