Big commit

This commit is contained in:
Jiiks 2018-08-20 05:05:01 +03:00
parent de0651bb47
commit fc6481acae
6 changed files with 107 additions and 39 deletions

View File

@ -68,7 +68,8 @@ export default class DiscordApi {
static get Message() { return Message }
/**
* @returns {List} A list of loaded guilds.
* A list of loaded guilds.
* @type {List<Guild>}
*/
static get guilds() {
const guilds = Modules.GuildStore.getGuilds();
@ -76,7 +77,8 @@ export default class DiscordApi {
}
/**
* @returns {List} A list of loaded channels.
* A list of loaded channels.
* @member {List<Channel>}
*/
static get channels() {
const channels = Modules.ChannelStore.getChannels();
@ -84,7 +86,8 @@ export default class DiscordApi {
}
/**
* @returns {List} A list of loaded users.
* A list of loaded users.
* @type {List<User>}
*/
static get users() {
const users = Modules.UserStore.getUsers();
@ -92,14 +95,16 @@ export default class DiscordApi {
}
/**
* @returns {Object} An object mapping guild IDs to their member counts.
* An object mapping guild IDs to their member counts.
* @type {Object}
*/
static get memberCounts() {
return Modules.MemberCountStore.getMemberCounts();
}
/**
* @returns {List} A list of guilds in the order they appear in the server list.
* A list of guilds in the order they appear in the server list.
* @type {List<Guild>}
*/
static get sortedGuilds() {
const guilds = Modules.SortedGuildStore.getSortedGuilds();
@ -107,14 +112,16 @@ export default class DiscordApi {
}
/**
* @returns {Array} An array of guild IDs in the order they appear in the server list.
* An array of guild IDs in the order they appear in the server list.
* @type {Number[]}
*/
static get guildPositions() {
return Modules.SortedGuildStore.guildPositions;
}
/**
* @returns {Guild} The currently selected guild.
* The currently selected guild.
* @type {Guild}
*/
static get currentGuild() {
const guild = Modules.GuildStore.getGuild(Modules.SelectedGuildStore.getGuildId());
@ -122,7 +129,8 @@ export default class DiscordApi {
}
/**
* @returns {Channel} The currently selected channel.
* The currently selected channel.
* @type {Channel}
*/
static get currentChannel() {
const channel = Modules.ChannelStore.getChannel(Modules.SelectedChannelStore.getChannelId());
@ -130,7 +138,8 @@ export default class DiscordApi {
}
/**
* @returns {User} The current user.
* The current user.
* @type {User}
*/
static get currentUser() {
const user = Modules.UserStore.getCurrentUser();
@ -138,13 +147,16 @@ export default class DiscordApi {
}
/**
* @returns {List} A list of the current user's friends.
* A list of the current user's friends.
* @type {List<User>}
*/
static get friends() {
const friends = Modules.RelationshipStore.getFriendIDs();
return List.from(friends, id => User.fromId(id));
}
/**
* User settings
*/
static get UserSettings() {
return UserSettings;
}
@ -161,40 +173,42 @@ export class UserSettings {
}
/**
* @returns {String} The user's current status. Either "online", "idle", "dnd" or "invisible".
* The user's current status. Either "online", "idle", "dnd" or "invisible".
* @type {String}
*/
static get status() { return Modules.UserSettingsStore.status }
/**
* The user's selected explicit content filter level.
* 0 == off, 1 == everyone except friends, 2 == everyone
* Configurable in the privacy and safety panel.
* @returns {Number} 0 == off, 1 == everyone except friends, 2 == everyone
* @type {Number}
*/
static get explicitContentFilter() { return Modules.UserSettingsStore.explicitContentFilter }
/**
* @returns {Boolean} Whether to disallow direct messages from server members by default.
* Whether to disallow direct messages from server members by default.
* @type {Boolean}
*/
static get defaultGuildsRestricted() { return Modules.UserSettingsStore.defaultGuildsRestricted }
/**
* An array of guilds to disallow direct messages from their members.
* This is bypassed if the member is has another mutual guild with this disabled, or the member is friends with the current user.
* Configurable in each server's privacy settings.
* @returns {Array} An array of guilds to disallow direct messages from their members.
* @type {Guild[]}
*/
static get restrictedGuildIds() { return Modules.UserSettingsStore.restrictedGuilds }
/**
* @returns {List} List of restricted guilds
*/
static get restrictedGuilds() {
return List.from(this.restrictedGuildIds, id => Guild.fromId(id) || id);
}
/**
* An array of flags specifying who should be allowed to add the current user as a friend.
* If everyone is checked, this will only have one item, "all". Otherwise it has either "mutual_friends", "mutual_guilds", both or neither.
* Configurable in the privacy and safety panel.
* @returns {Array} An array of flags specifying who should be allowed to add the current user as a friend.
* @type {Array}
*/
static get friendSourceFlags() { return Object.keys(Modules.UserSettingsStore.friendSourceFlags) }
static get friendSourceEveryone() { return this.friendSourceFlags.include('all') }
@ -203,99 +217,116 @@ export class UserSettings {
static get friendSourceAnyone() { return this.friendSourceFlags.length > 0 }
/**
* Whether to automatically add accounts from other platforms running on the user's computer.
* Configurable in the connections panel.
* @returns {Boolean} Whether to automatically add accounts from other platforms running on the user's computer.
* @type {Boolean}
*/
static get detectPlatformAccounts() { return Modules.UserSettingsStore.detectPlatformAccounts }
/**
* The number of seconds Discord will wait for activity before sending mobile push notifications.
* Configurable in the notifications panel.
* @returns {Number} The number of seconds Discord will wait for activity before sending mobile push notifications.
* @type {Number}
*/
static get afkTimeout() { return Modules.UserSettingsStore.afkTimeout }
/**
* Whether to display the currently running game as a status message.
* Configurable in the games panel.
* @returns {Boolean} Whether to display the currently running game as a status message.
* @type {Boolean}
*/
static get showCurrentGame() { return Modules.UserSettingsStore.showCurrentGame }
/**
* Whether to show images uploaded directly to Discord.
* Configurable in the text and images panel.
* @returns {Boolean} Whether to show images uploaded directly to Discord.
* @type {Boolean}
*/
static get inlineAttachmentMedia() { return Modules.UserSettingsStore.inlineAttachmentMedia }
/**
* Whether to show images linked in Discord.
* Configurable in the text and images panel.
* @returns {Boolean} Whether to show images linked in Discord.
* @type {Boolean}
*/
static get inlineEmbedMedia() { return Modules.UserSettingsStore.inlineEmbedMedia }
/**
* Whether to automatically play GIFs when the Discord window is active without having to hover the mouse over the image.
* Configurable in the text and images panel.
* @returns {Boolean} Whether to automatically play GIFs when the Discord window is active without having to hover the mouse over the image.
* @type {Boolean}
*/
static get autoplayGifs() { return Modules.UserSettingsStore.gifAutoPlay }
/**
* Whether to show content from HTTP[s] links as embeds.
* Configurable in the text and images panel.
* @returns {Boolean} Whether to show content from HTTP[s] links as embeds.
* @type {Boolean}
*/
static get showEmbeds() { return Modules.UserSettingsStore.renderEmbeds }
/**
* Whether to show a message's reactions.
* Configurable in the text and images panel.
* @returns {Boolean} Whether to show a message's reactions.
* @type {Boolean}
*/
static get showReactions() { return Modules.UserSettingsStore.renderReactions }
/**
* Whether to play animated emoji.
* Configurable in the text and images panel.
* @returns {Boolean} Whether to play animated emoji.
* @type {Boolean}
*/
static get animateEmoji() { return Modules.UserSettingsStore.animateEmoji }
/**
* Whether to convert ASCII emoticons to emoji.
* Configurable in the text and images panel.
* @returns {Boolean} Whether to convert ASCII emoticons to emoji.
* @type {Boolean}
*/
static get convertEmoticons() { return Modules.UserSettingsStore.convertEmoticons }
/**
* Whether to allow playing text-to-speech messages.
* Configurable in the text and images panel.
* @returns {Boolean} Whether to allow playing text-to-speech messages.
* @type {Boolean}
*/
static get allowTts() { return Modules.UserSettingsStore.enableTTSCommand }
/**
* The user's selected theme. Either "dark" or "light".
* Configurable in the appearance panel.
* @returns {String} The user's selected theme. Either "dark" or "light".
* @type {String}
*/
static get theme() { return Modules.UserSettingsStore.theme }
/**
* Whether the user has enabled compact mode.
* `true` if compact mode is enabled, `false` if cozy mode is enabled.
* Configurable in the appearance panel.
* @returns {Boolean} Whether the user has enabled compact mode. `true` if compact mode is enabled, `false` if cozy mode is enabled.
* @type {Boolean}
*/
static get displayCompact() { return Modules.UserSettingsStore.messageDisplayCompact }
/**
* Whether the user has enabled developer mode.
* Currently only adds a "Copy ID" option to the context menu on users, guilds and channels.
* Configurable in the appearance panel.
* @returns {Boolean} Whether the user has enabled developer mode.
* @type {Boolean}
*/
static get developerMode() { return Modules.UserSettingsStore.developerMode }
/**
* The user's selected language code.
* Configurable in the language panel.
* @returns {String} The user's selected language code.
* @type {String}
*/
static get locale() { return Modules.UserSettingsStore.locale }
/**
* The user's timezone offset in hours.
* This is not configurable.
* @returns {Number} The user's timezone offset in hours.
* @type {Number}
*/
static get timezoneOffset() { return Modules.UserSettingsStore.timezoneOffset }
}

View File

@ -1,4 +1,4 @@
/**
/*
* BetterDiscord Channel Struct
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
@ -16,6 +16,9 @@ import { User, GuildMember } from './user';
const channels = new WeakMap();
/**
* Class representing a Discord Channel
*/
export class Channel {
constructor(data) {
@ -86,6 +89,7 @@ export class Channel {
/**
* A list of messages in this channel.
* @type {List<Message>}
*/
get messages() {
const messages = Modules.MessageStore.getMessages(this.id).toArray();
@ -126,6 +130,7 @@ export class Channel {
/**
* Whether this channel is currently selected.
* @type {Boolean}
*/
get isSelected() {
return DiscordApi.currentChannel === this;

View File

@ -1,4 +1,4 @@
/**
/*
* BetterDiscord Guild Struct
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
@ -16,6 +16,9 @@ import { GuildMember } from './user';
const roles = new WeakMap();
/**
* Class representing a Discord Role
*/
export class Role {
constructor(data, guild_id) {
if (roles.has(data)) return roles.get(data);
@ -47,6 +50,9 @@ export class Role {
const emojis = new WeakMap();
/**
* Class representing a Discord Emoji
*/
export class Emoji {
constructor(data) {
if (emojis.has(data)) return emojis.get(data);
@ -72,6 +78,9 @@ export class Emoji {
const guilds = new WeakMap();
/**
* Class representing a Discord Guild
*/
export class Guild {
constructor(data) {

View File

@ -15,6 +15,9 @@ import { User } from './user';
const reactions = new WeakMap();
/**
* Class representing a Discord Reaction
*/
export class Reaction {
constructor(data, message_id, channel_id) {
if (reactions.has(data)) return reactions.get(data);
@ -49,6 +52,9 @@ export class Reaction {
const embeds = new WeakMap();
/**
* Class representing a Discord Embed
*/
export class Embed {
constructor(data, message_id, channel_id) {
if (embeds.has(data)) return embeds.get(data);
@ -88,6 +94,9 @@ export class Embed {
const messages = new WeakMap();
/**
* Class representing a Discord Message
*/
export class Message {
constructor(data) {
@ -170,6 +179,9 @@ export class Message {
}
/**
* Class representing a default Discord Message
*/
export class DefaultMessage extends Message {
get webhookId() { return this.discordObject.webhookId }
get type() { return 'DEFAULT' }

View File

@ -1,4 +1,4 @@
/**
/*
* BetterDiscord User Struct
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
@ -16,6 +16,9 @@ import { Channel } from './channel';
const users = new WeakMap();
/**
* Class representing a Discord user
*/
export class User {
constructor(data) {
@ -141,6 +144,9 @@ export class User {
const guild_members = new WeakMap();
/**
* Class representing a Discord Guild Member
*/
export class GuildMember {
constructor(data, guild_id) {
if (guild_members.has(data)) return guild_members.get(data);

View File

@ -1,4 +1,4 @@
/**
/*
* BetterDiscord List
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
@ -8,6 +8,11 @@
* LICENSE file in the root directory of this source tree.
*/
/**
* Class representing a list.
* @extends Array
*/
export default class List extends Array {
get(...filters) {