Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Plugin = require('../plugin');
  2.  
  3. let getChannel, g_dc, g_cat, ha, disp, chanM, fm, reb, sv, cs, csp, ghp, gs, gsr, pf, sw = {},
  4.     g = {},
  5.     ai = {};
  6.  
  7. // copied from Discord's minified JS
  8. function N(e, o, l, n) {
  9.     let r;
  10.     r || (r = "function" == typeof Symbol && Symbol.for && Symbol.for("react.element") || 60103);
  11.     const t = e && e.defaultProps,
  12.         f = arguments.length - 3;
  13.     if (o || 0 === f || (o = {
  14.             children: void 0
  15.         }), o && t)
  16.         for (const e in t) void 0 === o[e] && (o[e] = t[e]);
  17.     else o || (o = t || {});
  18.     if (1 === f) o.children = n;
  19.     else if (f > 1) {
  20.         const e = new Array(f);
  21.         for (let o = 0; o < f; o++) e[o] = arguments[o + 3];
  22.         o.children = e
  23.     }
  24.     return {
  25.         $$typeof: r,
  26.         type: e,
  27.         key: void 0 === l ? null : "" + l,
  28.         ref: null,
  29.         props: o,
  30.         _owner: null
  31.     }
  32. }
  33.  
  34. module.exports = new Plugin({
  35.     name: 'Hidden Channels Fixed',
  36.     description: 'Shows hidden channels and lets you view server permissions. (Except it does it correctly)',
  37.     color: '',
  38.     author: 'Charm + some other guys base',
  39.  
  40.     load: async function () {
  41.         disp = window.EDApi.findModule("dispatch");
  42.         getChannel = window.EDApi.findModule('getChannel').getChannel;
  43.         sw = window.EDApi.findModule('switchItem');
  44.         g = window.EDApi.findModule(m => m.group && m.item);
  45.         ai = window.EDApi.findModule('actionIcon');
  46.  
  47.         const getUser = window.EDApi.findModule('getCurrentUser').getCurrentUser;
  48.         const getAllChannels = window.EDApi.findModule('getChannels').getChannels;
  49.         const can = window.EDApi.findModule('computePermissions').can;
  50.  
  51.         g_dc = window.EDApi.findModule('getDefaultChannel');
  52.         window.EDApi.monkeyPatch(g_dc, 'getChannels', b => {
  53.             const og = b.callOriginalMethod(b.methodArguments);
  54.             if (!b.methodArguments[0]) return og;
  55.             const hidden = [],
  56.                 allChans = getAllChannels();
  57.             for (const i in allChans) {
  58.                 if (allChans[i].guild_id === b.methodArguments[0]) {
  59.                     if (allChans[i].type !== 4 && !can(1024, getUser(), getChannel(allChans[i].id))) {
  60.                         hidden.push(allChans[i]);
  61.                     }
  62.                 }
  63.             }
  64.             og.HIDDEN = hidden;
  65.             return og;
  66.         });
  67.         chanM = window.EDApi.findModule(m => m.prototype && m.prototype.isRoleRequired);
  68.         chanM.prototype.isHidden = function () {
  69.             return [0, 4, 5].includes(this.type) && !can(1024, getUser(), this);
  70.         }
  71.  
  72.         g_cat = window.EDApi.findModule(m => m.getCategories && !m.EMOJI_NAME_RE);
  73.         window.EDApi.monkeyPatch(g_cat, 'getCategories', b => {
  74.             const og = b.callOriginalMethod(b.methodArguments);
  75.             const chs = g_dc.getChannels(b.methodArguments[0]);
  76.             chs.HIDDEN.forEach(c => {
  77.                 const result = og[c.parent_id || "null"].filter(item => item.channel.id === c.id);
  78.                 if (result.length) return; // already added
  79.                 og[c.parent_id || "null"].push({
  80.                     channel: c,
  81.                     index: 0
  82.                 })
  83.             });
  84.             return og;
  85.         });
  86.  
  87.         ha = window.EDApi.findModule('hasUnread').__proto__;
  88.         window.EDApi.monkeyPatch(ha, 'hasUnread', function (b) {
  89.             if (getChannel(b.methodArguments[0]) && getChannel(b.methodArguments[0]).isHidden())
  90.                 return false; // don't show hidden channels as unread.
  91.             return b.callOriginalMethod(b.methodArguments);
  92.         });
  93.         window.EDApi.monkeyPatch(ha, 'hasUnreadPins', function (b) {
  94.             if (getChannel(b.methodArguments[0]) && getChannel(b.methodArguments[0]).isHidden())
  95.                 return false; // don't show icon on hidden channel pins.
  96.             return b.callOriginalMethod(b.methodArguments);
  97.         });
  98.  
  99.         disp.subscribe("CHANNEL_SELECT", module.exports.dispatchSubscription);
  100.  
  101.         fm = window.EDApi.findModule("fetchMessages");
  102.         window.EDApi.monkeyPatch(fm, "fetchMessages", function (b) {
  103.             if (getChannel(b.methodArguments[0]) && getChannel(b.methodArguments[0]).isHidden()) return;
  104.             return b.callOriginalMethod(b.methodArguments);
  105.         });
  106.  
  107.         const clk = window.EDApi.findModuleByDisplayName("Clickable")
  108.         const icon = window.EDApi.findModuleByDisplayName("Icon");
  109.  
  110.         reb = window.EDApi.findModule(m => m.default && m.default.prototype && m.default.prototype.renderEditButton).default.prototype;
  111.         window.EDApi.monkeyPatch(reb, "renderEditButton", function (b) {
  112.             return N(clk, {
  113.                 className: ai.iconItem,
  114.                 onClick: function () {
  115.                     module.exports._editingGuild = null;
  116.                     module.exports._editingChannel = b.thisObject.props.channel.id;
  117.                     return b.thisObject.handleEditClick.apply(b.thisObject, arguments);
  118.                 },
  119.                 onMouseEnter: b.thisObject.props.onMouseEnter,
  120.                 onMouseLeave: b.thisObject.props.onMouseLeave
  121.             }, void 0, N(icon, {
  122.                 name: "Gear",
  123.                 width: 16,
  124.                 height: 16,
  125.                 className: ai.actionIcon
  126.             }));
  127.         });
  128.  
  129.         sv = window.EDApi.findModuleByDisplayName("SettingsView").prototype;
  130.         window.EDApi.monkeyPatch(sv, 'getPredicateSections', {
  131.             before: b => {
  132.                 const permSect = b.thisObject.props.sections.find(item => item.section === 'PERMISSIONS');
  133.                 if (permSect) permSect.predicate = () => true;
  134.             },
  135.             silent: true
  136.         });
  137.  
  138.         cs = window.EDApi.findModuleByDisplayName("FluxContainer(ChannelSettings)").prototype;
  139.         window.EDApi.monkeyPatch(cs, 'render', b => {
  140.             const __x = b.callOriginalMethod(b.methodArguments);
  141.             __x.props.canManageRoles = true;
  142.             return __x;
  143.         });
  144.  
  145.         csp = window.EDApi.findModuleByDisplayName("FluxContainer(ChannelSettingsPermissions)").prototype;
  146.         window.EDApi.monkeyPatch(csp, 'render', b => {
  147.             const __x = b.callOriginalMethod(b.methodArguments);
  148.             const chan = getChannel(__x.props.channel.id);
  149.             if (!chan || !chan.isHidden()) return __x;
  150.             __x.props.canSyncChannel = false;
  151.             __x.props.locked = true;
  152.             setTimeout(() => {
  153.                 document.querySelectorAll('.' + g.group).forEach(elem => elem.style = "opacity: 0.5; pointer-events: none;");
  154.             });
  155.             return __x;
  156.         });
  157.  
  158.         ghp = window.EDApi.findModuleByDisplayName("FluxContainer(GuildHeaderPopout)").prototype;
  159.         window.EDApi.monkeyPatch(ghp, 'render', b => {
  160.             const __x = b.callOriginalMethod(b.methodArguments);
  161.             __x.props.canAccessSettings = true;
  162.             return __x;
  163.         });
  164.  
  165.         gs = window.EDApi.findModuleByDisplayName("FluxContainer(GuildSettings)").prototype;
  166.         window.EDApi.monkeyPatch(gs, 'render', b => {
  167.             const __x = b.callOriginalMethod(b.methodArguments);
  168.             module.exports._editingChannel = null;
  169.             module.exports._editingGuild = __x.props.guild.id;
  170.             __x.props.canManageRoles = true;
  171.             return __x;
  172.         });
  173.  
  174.         const cancan = window.EDApi.findModule('can').can;
  175.         gsr = window.EDApi.findModuleByDisplayName("FluxContainer(GuildSettingsRoles)").prototype;
  176.         window.EDApi.monkeyPatch(gsr, 'render', b => {
  177.             const __x = b.callOriginalMethod(b.methodArguments);
  178.             const hasPerm = cancan(268435456, __x.props.guild);
  179.             if (hasPerm) return;
  180.             setTimeout(() => {
  181.                 document.querySelectorAll('.' + sw.switchItem).forEach(elem => elem.classList.add(sw.disabled));
  182.             });
  183.             return __x;
  184.         });
  185.  
  186.         const getGuild = window.EDApi.findModule('getGuild').getGuild;
  187.         pf = window.EDApi.findModuleByDisplayName("PermissionsForm").prototype;
  188.         window.EDApi.monkeyPatch(pf, 'render', b => {
  189.             const __x = b.callOriginalMethod(b.methodArguments);
  190.             const guild = module.exports._editingGuild ? getGuild(module.exports._editingGuild) : null;
  191.             const channel = module.exports._editingChannel ? getChannel(module.exports._editingChannel) : null;
  192.             if (!guild && !channel) return __x;
  193.             const hasPerm = cancan(268435456, guild || channel);
  194.             if (hasPerm) return;
  195.  
  196.             if (!__x.props.children || !__x.props.children[1]) return __x;
  197.             __x.props.children[1].forEach(item => {
  198.                 item.disabled = true;
  199.                 item.props.disabled = true;
  200.             });
  201.             return __x;
  202.         });
  203.     },
  204.     unload: function () {
  205.         g_dc.getChannels.unpatch();
  206.         g_cat.getCategories.unpatch();
  207.         ha.hasUnread.unpatch();
  208.         ha.hasUnreadPins.unpatch();
  209.         fm.fetchMessages.unpatch();
  210.         reb.renderEditButton.unpatch();
  211.  
  212.         for (const mod of [sv, cs, csp, ghp, gs, gsr, pf])
  213.             if (mod && mod.render && mod.render.unpatch) mod.render.unpatch();
  214.  
  215.         disp.unsubscribe("CHANNEL_SELECT", module.exports.dispatchSubscription);
  216.     },
  217.     dispatchSubscription: function (data) {
  218.         if (data.type !== "CHANNEL_SELECT") return;
  219.  
  220.         if (getChannel(data.channelId) && getChannel(data.channelId).isHidden()) {
  221.             setTimeout(module.exports.attachHiddenChanNotice);
  222.         }
  223.     },
  224.     attachHiddenChanNotice: function () {
  225.         const messagesWrapper = document.querySelector(`.${window.EDApi.findModule("messages").messagesWrapper}`);
  226.         if (!messagesWrapper) return;
  227.  
  228.         messagesWrapper.firstChild.style.display = "none"; // Remove messages shit.
  229.         messagesWrapper.parentElement.children[1].style.display = "none"; // Remove message box.
  230.         messagesWrapper.parentElement.parentElement.children[1].style.display = "none"; // Remove user list.
  231.  
  232.         const toolbar = document.querySelector("." + window.EDApi.findModule(m => {
  233.             if (m instanceof Window) return;
  234.             if (m.toolbar && m.selected) return m;
  235.         }).toolbar);
  236.  
  237.         toolbar.style.display = "none";
  238.  
  239.         const hiddenChannelNotif = document.createElement("div");
  240.  
  241.         // Class name modules
  242.         const txt = window.EDApi.findModule("h5");
  243.         const flx = window.EDApi.findModule("flex");
  244.  
  245.         hiddenChannelNotif.className = flx.flexCenter;
  246.         hiddenChannelNotif.style.width = "100%";
  247.  
  248.         hiddenChannelNotif.innerHTML = `
  249.         <div class="${flx.flex} ${flx.directionColumn} ${flx.alignCenter}">
  250.         <h2 class="${txt.h2} ${txt.defaultColor}">oh shit oh fuck.</h2>
  251.         <h5 class="${txt.h5} ${txt.defaultColor}">There is literally no way to display the contents here unless I have the token of a user with access to the channel in the first place.\nWhat are you expecting to find here, anyway? Anime tiddies? Fuck no.</h5>
  252.         </div>`;
  253.  
  254.         messagesWrapper.appendChild(hiddenChannelNotif);
  255.     }
  256. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement