change file name case on discord module stuff

pull/98/head
dperolio 2 years ago
parent 9cd440b1db
commit f39ab0e760
No known key found for this signature in database
GPG Key ID: 4191689562D51409

@ -5,18 +5,16 @@
* @namespace Discord
*/
import * as components from './Components';
import * as snowflake from './Snowflake';
import * as constants from './Constants';
import * as modules from './Modules';
import * as user from './User';
import * as components from './components';
import * as snowflakes from './snowflakes';
import * as constants from './constants';
import * as modules from './modules';
import * as users from './users';
export {
export default {
components,
snowflake,
snowflakes,
constants,
modules,
user
users
};
export default this;

@ -16,8 +16,8 @@ import { isUrl, assertString } from '@vizality/util/string';
import { log, warn, error } from '@vizality/util/logger';
import { getModule } from '@vizality/webpack';
import { Constants } from './Constants';
import snowflake from './Snowflake';
import constants from './constants';
import snowflake from './snowflakes';
/**
* @private
@ -33,7 +33,7 @@ const _error = (labels, ...message) => error({ labels, message });
export const actions = {
pie: () => {
try {
const CurrentUserId = getModule('getId')?.getId();
const CurrentUserId = getModule('getId').getId();
if (!CurrentUserId) {
return null;
}
@ -48,31 +48,31 @@ export const actions = {
* Gets the current user object.
* @returns {User|null}
*/
export const getCurrentUser = () => {
export function getCurrentUser () {
try {
const CurrentUserId = getModule('getId')?.getId();
if (!CurrentUserId) {
const currentUserId = getModule('getId').getId();
if (!currentUserId) {
return null;
}
return this.getUser(CurrentUserId);
return this.getUser(currentUserId);
} catch (err) {
return _error(_labels.concat('getCurrentUser'), err);
}
};
}
/**
* Gets the user object from a user ID.
* @param {snowflake} userId User ID
* @returns {User|void}
*/
export const getUser = userId => {
export function getUser (userId) {
try {
assertString(userId);
return getModule('getUser', 'getUsers')?.getUser(userId);
return getModule('getUser', 'getUsers').getUser(userId);
} catch (err) {
return _error(_labels.concat('getUser'), err);
}
};
}
/**
* Fetches the user object from a user ID. Unlike getUser, this will use an API call to
@ -80,54 +80,54 @@ export const getUser = userId => {
* @param {snowflake} userId User ID
* @returns {Promise<User|void>}
*/
export const fetchUser = async userId => {
export async function fetchUser (userId) {
try {
assertString(userId);
return getModule('getUser', 'fetchCurrentUser')?.getUser(userId);
return getModule('getUser', 'fetchCurrentUser').getUser(userId);
} catch (err) {
return _error(_labels.concat('fetchUser'), err);
}
};
}
/**
* Gets the user object from a user tag.
* @param {string} userTag User tag
* @returns {User|void}
*/
export const getUserByTag = userTag => {
export function getUserByTag (userTag) {
try {
assertString(userTag);
const username = userTag.slice(0, -5);
const discriminator = userTag.slice(-4);
return getModule('getUser', 'getUsers')?.findByTag(username, discriminator);
return getModule('getUser', 'getUsers').findByTag(username, discriminator);
} catch (err) {
return _error(_labels.concat('getUserByTag'), err);
}
};
}
/**
* Gets all of the currently cached user objects.
* @returns {Collection<snowflake, User>} All cached user objects
*/
export const getUsers = () => {
export function getUsers () {
try {
return getModule('getUser', 'getUsers')?.getUsers();
return getModule('getUser', 'getUsers').getUsers();
} catch (err) {
return _error(_labels.concat('getUsers'), err);
}
};
}
/**
* Gets all of the currently cached user IDs.
* @returns {Array<snowflake>|void} All cached user IDs
*/
export const getUserIds = () => {
export function getUserIds () {
try {
return getModule('getStatus', 'getUserIds')?.getUserIds();
return getModule('getStatus', 'getUserIds').getUserIds();
} catch (err) {
return _error(_labels.concat('getUserIds'), err);
}
};
}
/**
* Gets the user's avatar hash. @see {@link https://discord.com/developers/docs/reference#image-formatting-image-base-url|Discord}
@ -135,24 +135,24 @@ export const getUserIds = () => {
* @param {snowflake} userId User ID
* @returns {string|void}
*/
export const getAvatar = userId => {
export function getAvatar (userId) {
try {
assertString(userId);
return this.getUser(userId)?.avatar;
return this.getUser(userId).avatar;
} catch (err) {
return _error(_labels.concat('getAvatar'), err);
}
};
}
/**
* Gets the user avatar URL.
* @param {snowflake} [userId] User ID
* @returns {string|void}
*/
export const getAvatarUrl = userId => {
export function getAvatarUrl (userId) {
try {
assertString(userId);
const AvatarURL = this.getUser(userId)?.getAvatarURL();
const AvatarURL = this.getUser(userId).getAvatarURL();
/**
* Check if the avatar URL exists. If it's already a valid URL, skip directly to the
* return below. If it's not a valid URL already, make sure it starts with /
@ -164,35 +164,35 @@ export const getAvatarUrl = userId => {
} catch (err) {
return _error(_labels.concat('getAvatarUrl'), err);
}
};
}
/**
* Gets the user account creation date and time in local string format.
* @param {snowflake} userId User ID
* @returns {string|void}
*/
export const getCreatedAt = userId => {
export function getCreatedAt (userId) {
try {
assertString(userId);
return snowflake.getTimestamp(userId)?.toLocaleString();
return snowflake.getTimestamp(userId).toLocaleString();
} catch (err) {
return _error(_labels.concat('getCreatedAt'), err);
}
};
}
/**
* Gets the user account creation timestamp.
* @param {snowflake} userId User ID
* @returns {string|void}
*/
export const getCreatedTimestamp = userId => {
export function getCreatedTimestamp (userId) {
try {
assertString(userId);
return snowflake.getTimestamp(userId);
} catch (err) {
return _error(_labels.concat('getCreatedTimestamp'), err);
}
};
}
/**
* Gets the user discriminator (4 digit indentifier).
@ -200,212 +200,218 @@ export const getCreatedTimestamp = userId => {
* @param {snowflake} userId User ID
* @returns {string|void}
*/
export const getDiscriminator = userId => {
export function getDiscriminator (userId) {
try {
assertString(userId);
return this.getUser(userId)?.discriminator;
return this.getUser(userId).discriminator;
} catch (err) {
return _error(_labels.concat('getDiscriminator'), err);
}
};
}
/**
* Gets the last message the user sent (that's visible to your client).
* @param {snowflake} userId User ID
* @returns {Message|void}
*/
export const getLastMessage = userId => {
export function getLastMessage (userId) {
// @todo: Not sure how to check for this yet.
return void 0;
};
}
/**
* Gets the user note contents.
* @param {snowflake} userId User ID
* @returns {string|void}
*/
export const getNote = userId => {
export function getNote (userId) {
try {
assertString(userId);
return getModule('getNote')?.getNote(userId)?.note;
return getModule('getNote').getNote(userId).note;
} catch (err) {
return _error(_labels.concat('getNote'), err);
}
};
}
/**
* Gets the user tag, which is a combination of the username and discriminator.
* @param {snowflake} userId User ID
* @returns {string|void}
*/
export const getTag = userId => {
export function getTag (userId) {
try {
assertString(userId);
return this.getUser(userId)?.tag;
return this.getUser(userId).tag;
} catch (err) {
return _error(_labels.concat('getTag'), err);
}
};
}
/**
* Gets the user username.
* @param {snowflake} userId User ID
* @returns {string|void}
*/
export const getUsername = userId => {
export function getUsername (userId) {
try {
assertString(userId);
return this.getUser(userId)?.username;
return this.getUser(userId).username;
} catch (err) {
return _error(_labels.concat('getUsername'), err);
}
};
}
/**
* Checks if the user has an animated avatar.
* @param {snowflake} userId User ID
* @returns {boolean} Whether the user has an animated avatar
*/
export const hasAnimatedAvatar = userId => {
export function hasAnimatedAvatar (userId) {
try {
assertString(userId);
const User = this.getUser(userId);
const ImageResolver = getModule('getUserAvatarURL', 'getGuildIconURL', 'hasAnimatedGuildIcon');
return ImageResolver?.hasAnimatedAvatar(User);
return ImageResolver.hasAnimatedAvatar(User);
} catch (err) {
return _error(_labels.concat('hasAnimatedAvatar'), err);
}
};
}
/**
* Checks if the user has a non-default avatar.
* @param {snowflake} userId User ID
* @returns {boolean} Whether the user has a non-default avatar
*/
export const hasAvatar = userId => {
export function hasAvatar (userId) {
try {
assertString(userId);
return Boolean(this.getUser(userId)?.avatar);
return Boolean(this.getUser(userId).avatar);
} catch (err) {
return _error(_labels.concat('hasAvatar'), err);
}
};
}
/**
* Checks if the user has a Nitro (premium) subscription.
* @param {snowflake} userId User ID
* @returns {Promise<boolean>} Whether the user has an active Nitro subscription
*/
export const hasNitro = userId => {
export function hasNitro (userId) {
try {
return new Promise(async resolve => {
const result = (await getModule('getAPIBaseURL'))?.get({
url: `${Constants.Endpoints.USER_PROFILE(userId)}`
const result = (await getModule('getAPIBaseURL')).get({
url: `${constants.Endpoints.USER_PROFILE(userId)}`
});
resolve(Boolean(result?.body?.premium_since));
resolve(!!result.body.premium_since);
});
} catch (err) {
return _error(_labels.concat('hasNitro'), err);
}
};
}
/**
* Checks if the user is a bot.
* @param {snowflake} userId User ID
* @returns {boolean} Whether the user is a bot
*/
export const isBot = userId => {
export function isBot (userId) {
try {
assertString(userId);
return this.getUser(userId)?.bot;
return this.getUser(userId).bot;
} catch (err) {
return _error(_labels.concat('isBot'), err);
}
};
}
/**
* Checks if the user is a bug hunter.
* @param {snowflake} userId User ID
* @returns {boolean} Whether the user is a bug hunter
*/
export const isBugHunter = userId => {
export function isBugHunter (userId) {
try {
assertString(userId);
return Boolean(
this.getUser(userId)?.hasFlag(Constants.UserFlags.BUG_HUNTER_LEVEL_1) ||
this.getUser(userId)?.hasFlag(Constants.UserFlags.BUG_HUNTER_LEVEL_2)
this.getUser(userId).hasFlag(constants.UserFlags.BUG_HUNTER_LEVEL_1) ||
this.getUser(userId).hasFlag(constants.UserFlags.BUG_HUNTER_LEVEL_2)
);
} catch (err) {
return _error(_labels.concat('isBugHunter'), err);
}
};
}
/**
* Checks if the user is a Discord partner.
* @param {snowflake} userId User ID
* @returns {boolean} Whether the user is a Discord partner
*/
export const isPartner = userId => {
export function isPartner (userId) {
try {
assertString(userId);
return this.getUser(userId)?.hasFlag(Constants.UserFlags.PARTNER);
return this.getUser(userId).hasFlag(constants.UserFlags.PARTNER);
} catch (err) {
return _error(_labels.concat('isPartner'), err);
}
};
}
/**
* Checks if the user is a Discord staff member.
* @param {snowflake} userId User ID
* @returns {boolean} Whether the user is a Discord staff member
*/
export const isStaff = userId => {
export function isStaff (userId) {
try {
assertString(userId);
return this.getUser(userId)?.hasFlag(Constants.UserFlags.STAFF);
return this.getUser(userId).hasFlag(constants.UserFlags.STAFF);
} catch (err) {
return _error(_labels.concat('isStaff'), err);
}
};
}
/**
* Checks if the user is a system user.
* @param {snowflake} userId User ID
* @returns {boolean} Whether the user is a system user
*/
export const isSystemUser = userId => {
export function isSystemUser (userId) {
try {
assertString(userId);
return this.getUser(userId)?.system;
return this.getUser(userId).system;
} catch (err) {
return _error(_labels.concat('isSystemUser'), err);
}
};
}
/**
* Checks if the user is a verified bot.
* @param {snowflake} userId User ID
* @returns {boolean} Whether the user is a verified bot
*/
export const isVerifiedBot = userId => {
export function isVerifiedBot (userId) {
try {
assertString(userId);
return this.getUser(userId)?.hasFlag(Constants.UserFlags.VERIFIED_BOT);
return this.getUser(userId).hasFlag(constants.UserFlags.VERIFIED_BOT);
} catch (err) {
return _error(_labels.concat('isVerifiedBot'), err);
}
};
}
/**
* Checks if the user is a verified bot developer.
* @param {snowflake} userId User ID
* @returns {boolean} Whether the user is a verified bot developer
*/
export const isVerifiedBotDev = userId => {
export function isVerifiedBotDev (userId) {
try {
assertString(userId);
return this.getUser(userId)?.hasFlag(Constants.UserFlags.VERIFIED_DEVELOPER);
return this.getUser(userId).hasFlag(constants.UserFlags.VERIFIED_DEVELOPER);
} catch (err) {
return _error(_labels.concat('isVerifiedBotDev'), err);
}
};
}
/**
* Export the current user object as a property, as means of providing an alternate method
* of accessing it.
*/
export const current = this.getCurrentUser();
Loading…
Cancel
Save