const cheerio = require('cheerio'); const {defaultPermissions} = require('../util/default.json'); const Lang = require('./i18n.js'); const {settingsData, createNotice} = require('./util.js'); const forms = { settings: require('./settings.js').get, verification: require('./verification.js').get, rcscript: require('./rcscript.js').get }; const DiscordOauth2 = require('discord-oauth2'); const oauth = new DiscordOauth2( { clientId: process.env.bot, clientSecret: process.env.secret, redirectUri: process.env.dashboard } ); const file = require('fs').readFileSync('./dashboard/index.html'); /** * Let a user view settings * @param {import('http').ServerResponse} res - The server response * @param {String} state - The user state * @param {URL} reqURL - The used url * @param {String} [action] - The action the user made * @param {String[]} [actionArgs] - The arguments for the action */ function dashboard_guilds(res, state, reqURL, action, actionArgs) { reqURL.pathname = reqURL.pathname.replace( /^(\/(?:guild\/\d+(?:\/(?:settings|verification|rcscript)(?:\/(?:\d+|new))?)?)?)(?:\/.*)?$/, '$1' ); var args = reqURL.pathname.split('/'); args = reqURL.pathname.split('/'); var settings = settingsData.get(state); if ( reqURL.searchParams.get('owner') && process.env.owner.split('|').includes(settings.user.id) ) { args[0] = 'owner'; } var dashboardLang = new Lang(settings.user.locale); var $ = cheerio.load(file); $('head title').text(dashboardLang.get('general.title')); $('.channel#settings div').text(dashboardLang.get('general.settings')); $('.channel#verification div').text(dashboardLang.get('general.verification')); $('.channel#rcscript div').text(dashboardLang.get('general.rcscript')); $('#selector span').text(dashboardLang.get('general.selector')); $('#support span').text(dashboardLang.get('general.support')); $('#logout').attr('alt', dashboardLang.get('general.logout')); $('.guild#invite a').attr('alt', dashboardLang.get('general.invite')); $('.guild#refresh a').attr('alt', dashboardLang.get('general.refresh')); if ( process.env.READONLY ) createNotice($, 'readonly', dashboardLang); if ( action ) createNotice($, action, dashboardLang, actionArgs); $('head').append( $('