Update some Discord module stuff, update JSDoc stuff

pull/2/head
BakedPVP 4 years ago
parent 131f346d47
commit e0f792f5dc

@ -239,7 +239,7 @@
"jsdoc/check-tag-names": [ "warn" ],
"jsdoc/check-types": [ "warn" ],
"jsdoc/implements-on-classes": [ "warn" ],
"jsdoc/newline-after-description": [ "warn" ],
"jsdoc/newline-after-description": [ "warn"],
"jsdoc/no-undefined-types": [ "warn" ],
"jsdoc/require-hyphen-before-param-description": [ "warn" ],
"jsdoc/require-jsdoc": [ "warn" ],
@ -249,7 +249,6 @@
"jsdoc/require-param-type": [ "warn" ],
"jsdoc/require-returns": [ "warn" ],
"jsdoc/require-returns-check": [ "warn" ],
"jsdoc/require-returns-description": [ "warn" ],
"jsdoc/require-returns-type": [ "warn" ],
"jsdoc/valid-types": [ "warn" ]
},

@ -15,9 +15,9 @@ const { readFileSync, writeFileSync, existsSync, mkdirSync } = require('fs');
* the watcher if you no longer need the compiler. When watch events are emitted, the compiler
* should be re-used if a recompile is performed.
*
* @property {String} file File to compile
* @property {String} cacheDir Path where cached files will go
* @property {String} watcherEnabled Whether the file watcher is enabled or not
* @property {string} file File to compile
* @property {string} cacheDir Path where cached files will go
* @property {string} watcherEnabled Whether the file watcher is enabled or not
* @abstract
*/
class Compiler extends Events {
@ -54,7 +54,8 @@ class Compiler extends Events {
/**
* Arbitrary configuration for the compiler. Useless if not implemented in the _compile method.
* *NOTE*: Will fire "src-update" if the watcher is enabled and at least one compilation has been performed.
* @param {Object} options Options for the compiler
*
* @param {object} options Options for the compiler
*/
setCompileOptions (options) {
// @todo: finish this
@ -63,7 +64,8 @@ class Compiler extends Events {
/**
* Compiles the file (if necessary), and perform cache-related operations.
* @returns {Promise<String>|String} Compilation result
*
* @returns {Promise<string>|string} Compilation result
*/
compile () {
// Attemt to fetch from cache
@ -128,9 +130,10 @@ class Compiler extends Events {
}
/**
* Lists all files involved during the compilation (parent file + imported files)
* Only applicable if files are concatenated during compilation (e.g. scss files)
* @returns {Promise<String[]>|String[]}
* Lists all files involved during the compilation (parent file + imported files).
* Only applicable if files are concatenated during compilation (e.g. scss files).
*
* @returns {Promise<string[]>|string[]}
*/
listFiles () {
return [ this.file ];
@ -139,7 +142,8 @@ class Compiler extends Events {
/**
* Computes the hash corresponding to the file we're compiling.
* MUST take into account imported files (if any) and always return the same hash for the same given file.
* @returns {Promise<String|null>|String|null} Cache key, or null if cache isn't available
*
* @returns {Promise<string|null>|string|null} Cache key, or null if cache isn't available
*/
computeCacheKey () {
const files = this.listFiles();
@ -162,7 +166,8 @@ class Compiler extends Events {
/**
* Computes the hash of a given file
* @param {String} file File path
*
* @param {string} file File path
*/
computeFileHash (file) {
if (!existsSync(file)) {
@ -177,15 +182,16 @@ class Compiler extends Events {
}
/**
* Compiles the file. Should NOT perform any cache-related actions
* @returns {Promise<String>} Compilation results.
* Compiles the file. Should NOT perform any cache-related actions.
*
* @returns {Promise<string>} Compilation results.
*/
_compile () {
throw new Error('Not implemented');
}
/**
* @returns {String} Compiler metadata (compiler used, version)
* @returns {string} Compiler metadata (compiler used, version)
*/
get _metadata () {
return '';

@ -1,13 +1,12 @@
const { VIZALITY_FOLDER } = require('@constants');
const { promises: { readFile }, existsSync, statSync } = require('fs');
const { join, dirname } = require('path');
const Compiler = require('./compiler');
const sass = require('sass');
/**
* SCSS compiler
* @extends {Compiler}
* SCSS compiler.
* @class
* @augments Compiler
*/
class SCSS extends Compiler {
async listFiles () {
@ -46,8 +45,9 @@ class SCSS extends Compiler {
/**
* Resolve dependencies imported in SCSS files.
* @param {String} file File to crawl
* @returns {Promise<String[]>}
*
* @param {string} file File to crawl
* @returns {Promise<string[]>}
*/
async _resolveDeps (file, resolvedFiles = []) {
const scss = await readFile(file, 'utf8');

@ -15,7 +15,7 @@ const getCreatedAt = (guildId = '') => {
// Check if the guild ID is a valid string
if (typeof guildId !== 'string') {
return error(_module, _submodule, null, `Guild ID must be a valid string.`);
return error(_module, _submodule, null, `Guild ID '${guildId}' is not a valid string.`);
}
// If no server ID specified, use the currently selected server's ID

@ -6,9 +6,12 @@ const { getModule } = require('@webpack');
* @returns {?string} Server ID
*/
const getCurrentGuildId = () => {
const CurrentGuildId = getModule('getLastSelectedGuildId').getGuildId();
return CurrentGuildId;
try {
const CurrentGuildModule = getModule('getLastSelectedGuildId');
return CurrentGuildModule.getGuildId();
} catch (err) {
// Fail silently
}
};
module.exports = getCurrentGuildId;

@ -3,41 +3,45 @@ const isValidId = require('../../utility/isValidId');
const getGuild = require('../getGuild');
/**
* Gets the specified role's data object. If no server ID is specified,
* tries to get the currently selected server's role's data object.
* Gets the specified role's data object.
* If only 1 argument is specified, it will be assumed to be the role ID,
* and it will attempt to retreive the role object from the currently selected guild.
*
* @param {string} roleId - Role ID
* @param {string} [guildId] - Server ID
* @returns {object|undefined} Role data object
* @param {string} guildId - Guild ID | Role ID (if role ID argument not specified)
* @param {?string} [roleId] - Role ID
* @returns {(object|undefined)} Role object
*/
const getRole = (roleId, guildId = '') => {
const _module = 'Module';
const getRole = (guildId, roleId) => {
const _submodule = 'Discord:Guild:Role:getRole';
// Check if the role ID is a valid string
if (typeof roleId !== 'string') {
return error(_module, _submodule, null, 'Role ID must be a valid string.');
if (arguments.length === 1) {
roleId = guildId;
/*
* Set guildID to empty an string here; it will be replaced with
* the current guild's ID (if there is one) through getValidId
*/
guildId = '';
}
// Check if the guild ID is a valid string
if (typeof guildId !== 'string') {
return error(_module, _submodule, null, 'Guild ID must be a valid string.');
}
// Check if the role ID is a valid string
if (!isValidId(roleId, 'role', _submodule)) return;
// If no server ID specified, use the currently selected server's ID
if (!guildId) {
guildId = getCurrentGuildId();
/*
* If guild ID is an empty string, get the current guild's ID,
* else return the guild ID argument value
*/
guildId = getValidId(guildId, 'guild', _submodule);
// Check if there is a currently selected server
if (!guildId) {
return error(_module, _submodule, null, 'You did not specify a server ID and you do not currently have a server selected.');
}
// Check if the guild ID is a valid string
if (!isValidId(guildId, 'guild', _submodule)) return;
try {
const Roles = getGuild(guildId).roles;
const Role = Roles[roleId];
return Role;
} catch (err) {
// Fail silently
}
const Roles = getGuild(guildId).roles;
const Role = Roles[roleId];
return Role;
};
module.exports = getRole;

@ -3,34 +3,30 @@ const isValidId = require('../../utility/isValidId');
const getGuild = require('../getGuild');
/**
* Gets all of the specified server's role data objects. If no server ID is specified,
* tries to get the currently selected server's role data objects.
* Gets all of the specified server's role data objects.
* If no server ID is specified, tries to get the currently selected server's role data objects.
*
* @param {string} [guildId] - Server ID
* @returns {object|undefined} All of the role data objects for the server or undefined
* @returns {(object|undefined)} All of the role data objects for the server or undefined
*/
const getRoles = (guildId = '') => {
const _module = 'Module';
const _submodule = 'Discord:Guild:Role:getRoles';
// Check if the guild ID is a valid string
if (typeof guildId !== 'string') {
return error(_module, _submodule, null, 'Guild ID must be a valid string.');
}
/*
* If guild ID is an empty string, return the current guild's ID,
* else return the guild ID argument value
*/
guildId = getValidId(guildId, 'guild', _submodule);
// If no server ID specified, use the currently selected server's ID
if (!guildId) {
guildId = getCurrentGuildId();
// Check if the guild ID is a valid string
if (!isValidId(guildId, 'guild', _submodule)) return;
// Check if there is a currently selected server
if (!guildId) {
return error(_module, _submodule, null, 'You did not specify a server ID and you do not currently have a server selected.');
}
try {
const Roles = getGuild(guildId).roles;
return Roles;
} catch (err) {
// Fail silently
}
const Roles = getGuild(guildId).roles;
return Roles;
};
module.exports = getRoles;

@ -5,27 +5,25 @@ const getGuild = require('../getGuild');
const Permissions = require('../../module/permissions');
// @todo Try to clean this file up.
/**
* Checks if a role of a server has specified permission(s).
*
* @param {string} guildId - Server ID
* @param {string} roleId - Role ID
* @param {...string} permissions - Permission type
* @returns {boolean} Whether the role has the specified permissions or not
* @returns {boolean} Does the role have the specified permission(s)?
*/
const hasPermission = (guildId, roleId, ...permissions) => {
const _module = 'Module';
const _submodule = 'Discord:Guild:Role:hasPermission';
// Check if the guild ID is a valid string
if (typeof guildId !== 'string') {
return error(_module, _submodule, null, 'Guild ID must be a valid string.');
}
if (!isValidId(guildId, 'guild', _submodule)) return;
// Check if the role ID is a valid string
if (typeof roleId !== 'string') {
return error(_module, _submodule, null, 'Role ID must be a valid string.');
}
if (!isValidId(roleId, 'role', _submodule)) return;
if (isEmpty(permissions)) {
return error(_module, _submodule, null, `No permission type specified. Here's a list of valid permission types:\n`, Object.keys(Permissions));

@ -1,12 +1,6 @@
const { logger: { warn } } = require('@utilities');
/* const currentWebContents = require('electron').remote.getCurrentWebContents(); */
const _getRoutes = require('./_getRoutes');
const getCurrentRoute = () => {
const module = 'Module';
const submodule = 'Discord:routes:getCurrentRoute';
const routes = _getRoutes();
/* const historyRoute = currentWebContents.history[currentWebContents.history.length - 2]; */

@ -12,7 +12,7 @@ const getSetting = (setting) => {
const settings = getModule('renderEmbeds', 'renderReactions', 'renderSpoilers');
const moreSettings = getModule('darkSidebar', 'fontScale', 'fontSize');
/**
/*
* @todo: Add `friendSourceFlags` and `restrictedGuilds`
*/
switch (setting) {

@ -19,7 +19,7 @@ const setNote = (userId, note) => {
// Check if the user note is a valid string
if (typeof note !== 'string') {
return error(_module, _submodule, null, `Note must be a valid string.`);
return error(_module, _submodule, null, `Note '${note}' is not a valid string.`);
}
try {

@ -47,7 +47,7 @@ const hasActivityOfType = (userId, ...activityTypes) => {
for (let activity of activityTypes) {
// Check if the activity type is a valid string or number
if (typeof activity !== 'string' && typeof activity !== 'number') {
return error(_module, _submodule, null, `Activity type must be a string or number. Here's a list of valid activity types:\n`, Object.values(ActivityTypes));
return error(_module, _submodule, null, `Activity type '${activity}' is not a valid string or number. Here's a list of valid activity types:\n`, Object.values(ActivityTypes));
}
// If it's a string value, let's convert it over to the corresponding number value

@ -18,7 +18,7 @@ const getAvatarString = (userId = '') => {
*/
userId = getValidId(userId, 'user', _submodule);
// Check if the ID is a valid string
// Check if the user ID is a valid string
if (!isValidId(userId, 'user', _submodule)) return;
try {

@ -16,7 +16,7 @@ const getUserByTag = (userTag = '') => {
// Check if the user ID is a valid string
if (typeof userTag !== 'string') {
return error(_module, _submodule, null, `User ID must be a valid string.`);
return error(_module, _submodule, null, `User tag '${userTag}' is not a valid string.`);
}
// If no user tag specified, use the current user's tag

Loading…
Cancel
Save