94 lines
3.1 KiB
TypeScript
94 lines
3.1 KiB
TypeScript
// Metro module 4381 (f4382).
|
|
import ChannelStore from "../../stores/ChannelStore";
|
|
import GuildStore from "../../stores/GuildStore";
|
|
import PermissionStore from "../../stores/PermissionStore";
|
|
import { ME, Permissions } from "../../Constants";
|
|
import { StaticChannelRoutes } from "../channel/ChannelConstants";
|
|
import RegexUtils from "../../utils/RegexUtils";
|
|
let c2598_7, c2598_8, c2598_9, c2598_10, c2598_11, c2598_12;
|
|
const r12 = Array.from(StaticChannelRoutes).map((item) => RegexUtils.escape(item)).join("|");
|
|
c2598_7 = new RegExp(`^/channels/(\\d+|${ME})(?:/)?(\\d+|${r12})?`);
|
|
c2598_8 = new RegExp(`^/channels/(\\d+|${ME})(?:/)(\\d+|${r12})(?:/)(\\d+)`);
|
|
c2598_9 = new RegExp("^/channels/(\\d+)(?:/)(\\d+)(?:/threads/)(\\d+)(?:/)(\\d+)");
|
|
c2598_10 = new RegExp(`^/channels/(\\d+|${ME})(?:/)(\\d+)/roll-dice(?:/(\\d+)d(\\d+))?\$`);
|
|
c2598_11 = new RegExp("^/guild-stages/(\\d+)(?:/)?(\\d+)?");
|
|
c2598_12 = new RegExp("^/events/(\\d+)(?:/)(\\d+)?((?:/)(\\d+))?");
|
|
const regExp = new RegExp(`^https://(?:(?:canary\\.|ptb\\.)?discord(?:app)?.com|staging\\.discord\\.co)/channels/(\\d+|${ME})(?:/(\\d+|[a-zA-Z-]+))?(?:/(\\d+|[a-zA-Z-]+))?`);
|
|
const regExp2 = new RegExp("^https://(?:(?:canary\\.|ptb\\.)?discord(?:app)?.com|staging\\.discord\\.co)/channels/(\\d+)(?:/)(\\d+)(?:/threads/)(\\d+)(?:/)(\\d+)");
|
|
export { regExp as CHANNEL_OR_MESSAGES_URL_RE };
|
|
export { regExp2 as MEDIA_POST_URL_RE };
|
|
export function tryParseChannelPath(a0) {
|
|
let r22;
|
|
if (a0 == null) {
|
|
return null;
|
|
}
|
|
const r9 = a0.match(c2598_8);
|
|
if (r9 != null && r9.length > 3) {
|
|
return {
|
|
guildId: r9[1],
|
|
channelId: r9[2],
|
|
messageId: r9[3]
|
|
};
|
|
}
|
|
const r12 = a0.match(c2598_9);
|
|
if (r12 != null && r12.length > 4) {
|
|
return {
|
|
guildId: r12[1],
|
|
channelId: r12[2],
|
|
threadId: r12[3],
|
|
messageId: r12[4]
|
|
};
|
|
}
|
|
const r16 = a0.match(c2598_7);
|
|
if (r16 != null && r16.length > 1) {
|
|
let channelId = r16[2];
|
|
if (channelId == null) {
|
|
channelId = void 0;
|
|
}
|
|
r22 = {
|
|
guildId: r16[1],
|
|
channelId
|
|
};
|
|
} else {
|
|
a0.match(c2598_11);
|
|
r22 = null;
|
|
}
|
|
return r22;
|
|
}
|
|
export function tryParseEventDetailsPath(a0) {
|
|
if (a0 == null) {
|
|
return null;
|
|
}
|
|
const r8 = a0.match(c2598_12);
|
|
return r8 != null ? r8.length > 1 ? {
|
|
guildId: r8[1],
|
|
guildEventId: r8[2],
|
|
recurrenceId: r8[4]
|
|
} : null : null;
|
|
}
|
|
export function canViewChannel(a0) {
|
|
return !!a0.isPrivate() || PermissionStore.can(Permissions.VIEW_CHANNEL, a0);
|
|
}
|
|
export function isAccessibleChannelPath({ guildId, channelId }) {
|
|
if (GuildStore.getGuild(guildId) == null && guildId !== ME) {
|
|
return false;
|
|
}
|
|
if (channelId == null) {
|
|
return true;
|
|
}
|
|
const channel = ChannelStore.getChannel(channelId);
|
|
return channel != null && (!!channel.isPrivate() || PermissionStore.can(Permissions.VIEW_CHANNEL, channel));
|
|
}
|
|
export function tryParseDiceRollLink(a0) {
|
|
if (a0 == null) {
|
|
return null;
|
|
}
|
|
const r7 = a0.match(c2598_10);
|
|
return r7 != null ? r7.length > 2 ? {
|
|
guildId: r7[1],
|
|
channelId: r7[2],
|
|
diceCount: r7.length === 5 ? parseInt(r7[3], 10) : 1,
|
|
diceSides: r7.length === 5 ? parseInt(r7[4], 10) : 6
|
|
} : null : null;
|
|
}
|