# Some general functions to develop new tricks
## Define `_mods`
Defines the `_mods` constant so different findBy/get functions dont cause errors trying defining the same constant.
**NECESSARY FOR ALL FINDBY/GET FUNCTIONS UNLESS STATED OTHERWISE.**
```js
const _mods = webpackChunkdiscord_app.push([[Symbol()],{},({c})=>Object.values(c)]);
webpackChunkdiscord_app.pop();
```
## `findByProps`
Gets a module by one (or more) of its properties.
```js
const findByProps = (...props) => {
for (let m of _mods) {
try {
if (!m.exports || m.exports === window) continue;
if (props.every((x) => m.exports?.[x])) return m.exports;
for (let ex in m.exports) {
if (props.every((x) => m.exports?.[ex]?.[x])) return m.exports[ex];
}
} catch {}
}
}
```
## `getStore`
Gets a store by its name.
```js
const getStore = (store) => {
return Object.values(
Object.values(_mods.find(x => x?.exports?.default?.getUsers).exports.default._dispatcher._actionHandlers)[3].nodes
).filter(s => s.name === store)[0];
};
```
## `getActionHandler`
Gets an ActionHandler by its store and name.
```js
const getActionHandler = (store, actionHandler) => {
let stores = Object.values(Object.values(_mods.find(x => x?.exports?.default?.getUsers).exports.default._dispatcher._actionHandlers)[3].nodes).filter(s => s.name === store);
let found;
for (var store of stores) {
if (!found && store.actionHandler[actionHandler]) found = store;
};
if (found) return found.actionHandler[actionHandler];
else return console.error(`${actionHandler} action handler could not found!`);
};
```
## `getAllFunctions`
Gets all functions of all modules.
```js
const getAllFunctions = () => {
return _mods.filter(m => typeof m?.exports?.Z === "object").map(m => Object.entries(m?.exports?.Z)
.filter(entry => typeof entry[1] === "function").map(entry => entry[0]));
};
```
## `searchFunctions`
Gets a Function by a name query.
```js
const searchFunctions = (search) => {
return _mods.filter(m => typeof m?.exports?.Z === "object")
.map(m => Object.entries(m?.exports?.Z).filter(entry => typeof entry[1] === "function" && entry[0].toLowerCase().includes(search))
.map(entry => entry[0])).filter(array => array.length !== 0);
};
```
## `searchStores`
Gets a store by a name query.
```js
const searchStores = (query) => {
return Object.fromEntries(_mods.find(x => x?.exports?.Z?.connectStores).Store.getAll()
.filter(store => store.getName().toLowerCase().includes(query)).map(matchingStore => [matchingStore.getName(), matchingStore]));
};
```
## `searchActionHandlers`
Gets an action handler by a name query.
```js
const searchActionHandlers = (query) => {
return Object.keys(Object.values(_mods.find(x => x?.exports?.default?.getUsers).exports.default._dispatcher._actionHandlers)[0])
.filter(key => key.toLowerCase().includes(query));
};
```
## `findModule`
equivelent to `_mods.find()`. Just a shortcut for lazy people
```js
const findModule = (func) => _mods.find(func)
```
**Or, better yet:**
```js
const getModules = () => webpackChunkdiscord_app.push([[Symbol()], {}, m => m])?.c ?? {}
const findModule = find => Object.values(getModules()).map(x => x?.exports?.default ?? x?.exports).filter(Boolean).find(find)
```
Thanks to [@kingdudely](https://gist.github.com/kingdudely)
# Discord Modules
May or may not be valid.
From: https://rauenzi.github.io/BDPluginLibrary/docs/modules_discordmodules.js.html
```js
React - findByProps("createElement", "cloneElement")
ReactDOM - findByProps("render", "findDOMNode")
GuildStore - findByProps("getGuild")
SortedGuildStore - findByProps("getSortedGuilds")
SelectedGuildStore - findByProps("getLastSelectedGuildId")
GuildSync - findByProps("getSyncedGuilds")
GuildInfo - findByProps("getAcronym")
GuildChannelsStore - findByProps("getChannels", "getDefaultChannel")
GuildMemberStore - findByProps("getMember")
MemberCountStore - findByProps("getMemberCounts")
GuildEmojiStore - findByProps("getEmojis")
GuildActions - findByProps("requestMembers")
GuildPermissions - findByProps("getGuildPermissions")
/* Channel Store & Actions */
ChannelStore - findByProps("getChannel", "getDMFromUserId")
SelectedChannelStore - findByProps("getLastSelectedChannelId")
ChannelActions - findByProps("selectChannel")
PrivateChannelActions - findByProps("openPrivateChannel")
/* Current User Info, State and Settings */
UserInfoStore - findByProps("getSessionId")
UserSettingsStore - findByProps("guildPositions")
StreamerModeStore - findByProps("hidePersonalInformation")
UserSettingsUpdater - findByProps("updateRemoteSettings")
OnlineWatcher - findByProps("isOnline")
CurrentUserIdle - findByProps("isIdle")
RelationshipStore - findByProps("isBlocked", "getFriendIDs")
RelationshipManager - findByProps("addRelationship")
MentionStore - findByProps("getMentions")
/* User Stores and Utils */
UserStore - findByProps("getCurrentUser", "getUser")
UserStatusStore - findByProps("getStatus", "getState")
UserTypingStore - findByProps("isTyping")
UserActivityStore - findByProps("getActivity")
UserNameResolver - findByProps("getName")
UserNoteStore - findByProps("getNote")
UserNoteActions - findByProps("updateNote")
/* Emoji Store and Utils */
EmojiInfo - findByProps("isEmojiDisabled")
EmojiUtils - findByProps("getGuildEmoji")
EmojiStore - findByProps("getByCategory", "EMOJI_NAME_RE")
/* Invite Store and Utils */
InviteStore - findByProps("getInvites")
InviteResolver - findByProps("resolveInvite")
InviteActions - findByProps("acceptInvite")
/* Discord Objects & Utils */
DiscordConstants - findByProps("Permissions", "ActivityTypes", "StatusTypes")
DiscordPermissions - findByProps("Permissions", "ActivityTypes", "StatusTypes").Permissions
Permissions - findByProps("computePermissions")
ColorConverter - findByProps("hex2int")
ColorShader - findByProps("darken")
ClassResolver - findByProps("getClass")
ButtonData - findByProps("ButtonSizes")
NavigationUtils - findByProps("transitionTo", "replaceWith", "getHistory")
KeybindStore - findByProps("keyToCode")
/* Discord Messages */
MessageStore - findByProps("getMessage", "getMessages")
ReactionsStore - findByProps("getReactions", "_dispatcher")
MessageActions - findByProps("jumpToMessage", "_sendMessage")
MessageQueue - findByProps("enqueue")
/* Experiments */
ExperimentStore - findByProps("getExperimentOverrides")
ExperimentsManager - findByProps("isDeveloper")
CurrentExperiment - findByProps("getExperimentId")
```
## Snippet API:
This is a snippet to get all of the functions and modules in one object.
Access them using `snippetApi`.
=> [`3-discord-cli-snippet-api.js`](#file-3-discord-cli-snippet-api-js)