2018-03-12 03:42:06 +01:00
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
import { List, InsufficientPermissions } from 'structs';
|
|
|
|
import { User, Channel, Guild, Message } from 'discordstructs';
|
|
|
|
import { WebpackModules } from './webpackmodules';
|
2018-02-14 16:26:48 +01:00
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
export const Modules = {
|
2018-03-12 03:42:06 +01:00
|
|
|
_getModule(name) {
|
2018-03-14 13:19:46 +01:00
|
|
|
const foundModule = WebpackModules.getModuleByName(name);
|
2018-03-12 03:42:06 +01:00
|
|
|
if (!foundModule) return null;
|
|
|
|
delete this[name];
|
|
|
|
return this[name] = foundModule;
|
|
|
|
},
|
2018-04-14 01:23:18 +02:00
|
|
|
|
2018-03-14 13:19:46 +01:00
|
|
|
get ChannelSelector() { return this._getModule('ChannelSelector'); },
|
|
|
|
get MessageActions() { return this._getModule('MessageActions'); },
|
|
|
|
get MessageParser() { return this._getModule('MessageParser'); },
|
|
|
|
get MessageStore() { return this._getModule('MessageStore'); },
|
|
|
|
get EmojiUtils() { return this._getModule('EmojiUtils'); },
|
|
|
|
get PermissionUtils() { return this._getModule('Permissions'); },
|
|
|
|
get SortedGuildStore() { return this._getModule('SortedGuildStore'); },
|
|
|
|
get PrivateChannelActions() { return this._getModule('PrivateChannelActions'); },
|
|
|
|
get GuildMemberStore() { return this._getModule('GuildMemberStore'); },
|
|
|
|
get GuildChannelsStore() { return this._getModule('GuildChannelsStore'); },
|
|
|
|
get MemberCountStore() { return this._getModule('MemberCountStore'); },
|
|
|
|
get GuildActions() { return this._getModule('GuildActions'); },
|
|
|
|
get NavigationUtils() { return this._getModule('NavigationUtils'); },
|
|
|
|
get GuildPermissions() { return this._getModule('GuildPermissions'); },
|
|
|
|
get DiscordConstants() { return this._getModule('DiscordConstants'); },
|
|
|
|
get ChannelStore() { return this._getModule('ChannelStore'); },
|
|
|
|
get GuildStore() { return this._getModule('GuildStore'); },
|
|
|
|
get SelectedGuildStore() { return this._getModule('SelectedGuildStore'); },
|
|
|
|
get SelectedChannelStore() { return this._getModule('SelectedChannelStore'); },
|
|
|
|
get UserStore() { return this._getModule('UserStore'); },
|
|
|
|
get RelationshipStore() { return this._getModule('RelationshipStore'); },
|
|
|
|
get RelationshipManager() { return this._getModule('RelationshipManager'); },
|
2018-04-14 16:15:03 +02:00
|
|
|
get UserStatusStore() { return this._getModule('UserStatusStore'); },
|
2018-03-12 03:42:06 +01:00
|
|
|
|
|
|
|
get DiscordPermissions() { return this.DiscordConstants.Permissions; }
|
|
|
|
};
|
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
export default class DiscordApi {
|
2018-03-12 03:42:06 +01:00
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
static get modules() { return Modules }
|
|
|
|
static get User() { return User }
|
|
|
|
static get Channel() { return Channel }
|
|
|
|
static get Guild() { return Guild }
|
|
|
|
static get Message() { return Message }
|
2018-02-14 16:26:48 +01:00
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
/**
|
|
|
|
* A list of loaded guilds.
|
|
|
|
*/
|
|
|
|
static get guilds() {
|
|
|
|
const guilds = Modules.GuildStore.getGuilds();
|
|
|
|
return List.from(Object.entries(guilds), ([i, g]) => new Guild(g));
|
2018-03-12 03:42:06 +01:00
|
|
|
}
|
2018-02-14 16:26:48 +01:00
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
/**
|
|
|
|
* A list of loaded channels.
|
|
|
|
*/
|
2018-02-14 16:26:48 +01:00
|
|
|
static get channels() {
|
2018-03-12 03:42:06 +01:00
|
|
|
const channels = Modules.ChannelStore.getChannels();
|
2018-04-14 01:23:18 +02:00
|
|
|
return List.from(Object.entries(channels), ([i, c]) => Channel.from(c));
|
2018-03-12 03:42:06 +01:00
|
|
|
}
|
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
/**
|
|
|
|
* A list of loaded users.
|
|
|
|
*/
|
2018-03-12 03:42:06 +01:00
|
|
|
static get users() {
|
|
|
|
const users = Modules.UserStore.getUsers();
|
2018-04-14 01:23:18 +02:00
|
|
|
return List.from(Object.entries(users), ([i, u]) => new User(u));
|
2018-03-12 03:42:06 +01:00
|
|
|
}
|
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
/**
|
|
|
|
* An object mapping guild IDs to their member counts.
|
|
|
|
*/
|
2018-03-12 03:42:06 +01:00
|
|
|
static get memberCounts() {
|
|
|
|
return Modules.MemberCountStore.getMemberCounts();
|
|
|
|
}
|
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
/**
|
|
|
|
* A list of guilds in the order they appear in the server list.
|
|
|
|
*/
|
2018-03-12 03:42:06 +01:00
|
|
|
static get sortedGuilds() {
|
|
|
|
const guilds = Modules.SortedGuildStore.getSortedGuilds();
|
2018-04-14 01:23:18 +02:00
|
|
|
return List.from(guilds, g => new Guild(g));
|
2018-03-12 03:42:06 +01:00
|
|
|
}
|
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
/**
|
|
|
|
* An array of guild ID in the order they appear in the server list.
|
|
|
|
*/
|
2018-03-12 03:42:06 +01:00
|
|
|
static get guildPositions() {
|
|
|
|
return Modules.SortedGuildStore.guildPositions;
|
|
|
|
}
|
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
/**
|
|
|
|
* The currently selected guild.
|
|
|
|
*/
|
2018-03-12 03:42:06 +01:00
|
|
|
static get currentGuild() {
|
2018-04-14 01:23:18 +02:00
|
|
|
const guild = Modules.GuildStore.getGuild(Modules.SelectedGuildStore.getGuildId());
|
|
|
|
if (guild) return new Guild(guild);
|
2018-03-12 03:42:06 +01:00
|
|
|
}
|
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
/**
|
|
|
|
* The currently selected channel.
|
|
|
|
*/
|
2018-03-12 03:42:06 +01:00
|
|
|
static get currentChannel() {
|
2018-03-14 13:19:46 +01:00
|
|
|
const channel = Modules.ChannelStore.getChannel(Modules.SelectedChannelStore.getChannelId());
|
2018-04-14 01:23:18 +02:00
|
|
|
if (channel) return Channel.from(channel);
|
2018-03-12 03:42:06 +01:00
|
|
|
}
|
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
/**
|
|
|
|
* The current user.
|
|
|
|
*/
|
2018-03-12 03:42:06 +01:00
|
|
|
static get currentUser() {
|
2018-04-14 01:23:18 +02:00
|
|
|
const user = Modules.UserStore.getCurrentUser();
|
|
|
|
if (user) return new User(user);
|
2018-03-12 03:42:06 +01:00
|
|
|
}
|
|
|
|
|
2018-04-14 01:23:18 +02:00
|
|
|
/**
|
|
|
|
* A list of the current user's friends.
|
|
|
|
*/
|
2018-03-12 03:42:06 +01:00
|
|
|
static get friends() {
|
|
|
|
const friends = Modules.RelationshipStore.getFriendIDs();
|
2018-04-14 01:23:18 +02:00
|
|
|
return List.from(friends, id => User.fromId(id));
|
2018-02-14 16:26:48 +01:00
|
|
|
}
|
2018-03-21 00:24:31 +01:00
|
|
|
|
2018-02-14 16:26:48 +01:00
|
|
|
}
|