// Module ID: 5419 // Function ID: 5420 // Name: LinkUtils // Dependencies: [2064, 2086, 4709, 1085, 2071, 5075, 2] // Exports: canViewChannel, isAccessibleChannelPath, tryParseChannelPath, tryParseDiceRollLink, tryParseEventDetailsPath, tryParseUserProfilePath // Module 5419 (LinkUtils) import ChannelConstants from "ChannelConstants" /* 2071 */; import RegexUtilsDefault from "RegexUtils" /* 5075 */; import ChannelStore from "ChannelStore" /* 2064 */; import GuildStore from "GuildStore" /* 2086 */; import PermissionStore from "PermissionStore" /* 4709 */; import Constants from "Constants" /* 1085 */; import size from "module_2" /* 2 */; const ME = Constants.ME; const Permissions = Constants.Permissions; const arr = Array.from(ChannelConstants.StaticChannelRoutes); const mapped = arr.map((item) => { const obj = RegexUtilsDefault; return obj.escape(item); }); const joined = mapped.join("|"); const regExp = new RegExp("^/channels/(\\d+|" + ME + ")(?:/)?(\\d+|" + joined + ")?"); const regExp1 = new RegExp("^/channels/(\\d+|" + ME + ")(?:/)(\\d+|" + joined + ")(?:/)(\\d+)"); const regExp2 = new RegExp("^/channels/(\\d+)(?:/)(\\d+)(?:/threads/)(\\d+)(?:/)(\\d+)"); const regExp3 = new RegExp("^/channels/(\\d+|" + ME + ")(?:/)(\\d+)/roll-dice(?:/(\\d+)d(\\d+))?$"); const regExp4 = new RegExp("^/guild-stages/(\\d+)(?:/)?(\\d+)?"); const re12 = /^\/users\/(\d+)\/?$/; const regExp5 = new RegExp("^/events/(\\d+)(?:/)(\\d+)?((?:/)(\\d+))?"); const regExp6 = new RegExp("^https://(?:(?:canary\\.|ptb\\.)?discord(?:app)?.com|staging\\.discord\\.co)/channels/(\\d+|" + ME + ")(?:/(\\d+|[a-zA-Z-]+))?(?:/(\\d+|[a-zA-Z-]+))?"); const regExp7 = new RegExp("^https://(?:(?:canary\\.|ptb\\.)?discord(?:app)?.com|staging\\.discord\\.co)/channels/(\\d+)(?:/)(\\d+)(?:/threads/)(\\d+)(?:/)(\\d+)"); const result = size.fileFinishedImporting("modules/links/LinkUtils.tsx"); export const CHANNEL_OR_MESSAGES_URL_RE = regExp6; export const MEDIA_POST_URL_RE = regExp7; export const tryParseChannelPath = function tryParseChannelPath(pathname) { if (null == pathname) { return null; } else { const match = pathname.match(regExp1); if (null != match) { if (match.length > 3) { return { guildId: match[1], channelId: match[2], messageId: match[3] }; } } const match1 = pathname.match(regExp2); if (null != match1) { if (match1.length > 4) { return { guildId: match1[1], channelId: match1[2], threadId: match1[3], messageId: match1[4] }; } } const match2 = pathname.match(regExp); if (null != match2) { let tmp5; if (match2.length > 1) { tmp5 = { guildId: match2[1], channelId: match2[2] }; const obj = { guildId: match2[1], channelId: match2[2] }; } return tmp5; } const match3 = pathname.match(regExp4); tmp5 = null; } }; export const tryParseEventDetailsPath = function tryParseEventDetailsPath(pathname) { if (null == pathname) { return null; } else { const match = pathname.match(regExp5); let tmp2 = null; if (null != match) { tmp2 = null; if (match.length > 1) { tmp2 = { guildId: match[1], guildEventId: match[2], recurrenceId: match[4] }; const obj = { guildId: match[1], guildEventId: match[2], recurrenceId: match[4] }; } } return tmp2; } }; export const tryParseUserProfilePath = function tryParseUserProfilePath(pathname) { let tmp = null; if (null != pathname) { const match = pathname.match(re12); let tmp4; if (match != null) { tmp4 = match[1]; } if (tmp4 == null) { tmp4 = null; } tmp = tmp4; } return tmp; }; export const canViewChannel = function canViewChannel(channel) { const canResult = channel.isPrivate() || PermissionStore.can(Permissions.VIEW_CHANNEL, channel); return canResult; }; export const isAccessibleChannelPath = function isAccessibleChannelPath(arg0) { let channelId; let guildId; ({ guildId, channelId } = arg0); if (null == GuildStore.getGuild(guildId)) { if (guildId !== ME) { return false; } } if (null == channelId) { return true; } else { const channel = ChannelStore.getChannel(channelId); let tmp3 = null != channel; if (tmp3) { tmp3 = channel.isPrivate() || PermissionStore.can(Permissions.VIEW_CHANNEL, channel); const canResult = channel.isPrivate() || PermissionStore.can(Permissions.VIEW_CHANNEL, channel); } return tmp3; } }; export const tryParseDiceRollLink = function tryParseDiceRollLink(pathname) { let num2; let num5; if (null == pathname) { return null; } else { const match = pathname.match(regExp3); let tmp = null; if (null != match) { tmp = null; if (match.length > 2) { const obj = { guildId: match[1], channelId: match[2], diceCount: num2, diceSides: num5 }; num2 = 1; if (5 === match.length) { const _parseInt = parseInt; num2 = parseInt(match[3], 10); } num5 = 6; if (5 === match.length) { const _parseInt2 = parseInt; num5 = parseInt(match[4], 10); } tmp = obj; } } return tmp; } };