mirror of
https://github.com/NovaGM/ModuleBuilder.git
synced 2024-08-15 00:23:33 +00:00
[PCCompat] Rewrite to use seperate global dir and object, other structural changes
This commit is contained in:
parent
2584ce03c5
commit
61c94f40d3
8 changed files with 130 additions and 126 deletions
33
moduleWrappers/powercord/global/commands.js
Normal file
33
moduleWrappers/powercord/global/commands.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
const sendMessage = goosemodScope.webpackModules.findByProps('sendMessage', 'receiveMessage').sendMessage;
|
||||
const getChannelId = goosemod.webpackModules.findByProps('getChannelId').getChannelId;
|
||||
|
||||
export const registerCommand = ({ command, alias, description, usage, executor }) => {
|
||||
// TODO: implement alias
|
||||
|
||||
goosemodScope.patcher.commands.add(command, description,
|
||||
async ( { args: [ { text } ] } ) => {
|
||||
const out = await executor(text.split(' ')); // Run original executor func (await incase it's an async function)
|
||||
|
||||
if (!out.send) {
|
||||
goosemodScope.patcher.internalMessage(out.result); // PC impl. sends internal message when out.send === false, so we also do the same via our previous Patcher API function
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// When send is true, we send it as a message via sendMessage
|
||||
|
||||
sendMessage(getChannelId(), {
|
||||
content: out.result,
|
||||
|
||||
tts: false,
|
||||
invalidEmojis: [],
|
||||
validNonShortcutEmojis: []
|
||||
});
|
||||
}, [
|
||||
{ type: 3, required: false, name: 'args', description: 'Arguments for PC command' } // Argument for any string for compat. with PC's classical commands
|
||||
]);
|
||||
};
|
||||
|
||||
export const unregisterCommand = (command) => {
|
||||
goosemodScope.patcher.commands.remove(command);
|
||||
};
|
11
moduleWrappers/powercord/global/index.js
Normal file
11
moduleWrappers/powercord/global/index.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
import * as commands from './commands.js';
|
||||
import * as notices from './notices.js';
|
||||
import * as settings from './settings.js';
|
||||
|
||||
export default {
|
||||
api: {
|
||||
commands,
|
||||
notices,
|
||||
settings
|
||||
}
|
||||
};
|
5
moduleWrappers/powercord/global/notices.js
Normal file
5
moduleWrappers/powercord/global/notices.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
export const sendToast = (_id, { header, content, type, buttons }) => {
|
||||
// TODO: implement full toast in future instead of just small current GM toast
|
||||
|
||||
goosemodScope.showToast(content);
|
||||
};
|
39
moduleWrappers/powercord/global/settings.js
Normal file
39
moduleWrappers/powercord/global/settings.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
import * as Settings from '../util/settings';
|
||||
|
||||
export const registerSettings = (id, { label, render, category }) => {
|
||||
const { React } = goosemodScope.webpackModules.common;
|
||||
|
||||
const SettingsView = goosemodScope.webpackModules.findByDisplayName('SettingsView');
|
||||
|
||||
const FormTitle = goosemodScope.webpackModules.findByDisplayName('FormTitle');
|
||||
const FormSection = goosemodScope.webpackModules.findByDisplayName('FormSection');
|
||||
|
||||
goosemodScope.patcher.inject(id, SettingsView.prototype, 'getPredicateSections', (_, sections) => {
|
||||
if (!sections.find(c => c.section === 'changelog')) return sections;
|
||||
|
||||
const dividers = sections.filter(c => c.section === 'DIVIDER');
|
||||
|
||||
const finalLabel = typeof label === 'function' ? label() : label;
|
||||
|
||||
sections.splice(sections.indexOf(dividers[dividers.length - 2]) - 2, 0,
|
||||
{
|
||||
section: finalLabel,
|
||||
label: finalLabel,
|
||||
predicate: () => { },
|
||||
element: () => React.createElement(FormSection, { },
|
||||
React.createElement(FormTitle, { tag: 'h2' }, finalLabel),
|
||||
|
||||
render({
|
||||
...Settings.settingStores[category]
|
||||
})
|
||||
)
|
||||
}
|
||||
);
|
||||
|
||||
return sections;
|
||||
});
|
||||
};
|
||||
|
||||
export const unregisterSettings = (id) => {
|
||||
goosemodScope.patcher.uninject(id);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue