add some comments and consistent structure
This commit is contained in:
parent
62b7679408
commit
6a5f185c80
|
@ -15,15 +15,21 @@ const twelveHour = new RegExp(`([0-9]{1,2}):([0-9]{1,2})\\s(AM|PM)`);
|
||||||
|
|
||||||
export default new class TwentyFourHour extends BuiltinModule {
|
export default new class TwentyFourHour extends BuiltinModule {
|
||||||
|
|
||||||
get settingPath() { return ['ui', 'default', '24-hour'] }
|
/* Getters */
|
||||||
get moduleName() { return 'TwentyFourHour' }
|
get moduleName() { return 'TwentyFourHour' }
|
||||||
|
|
||||||
|
get settingPath() { return ['ui', 'default', '24-hour'] }
|
||||||
|
|
||||||
|
/* Patches */
|
||||||
applyPatches() {
|
applyPatches() {
|
||||||
if (this.patches.length) return;
|
if (this.patches.length) return;
|
||||||
const { TimeFormatter } = Reflection.modules;
|
const { TimeFormatter } = Reflection.modules;
|
||||||
this.patch(TimeFormatter, 'calendarFormat', this.convertTimeStamps);
|
this.patch(TimeFormatter, 'calendarFormat', this.convertTimeStamps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert 12 hours timestamps to 24 hour timestamps
|
||||||
|
*/
|
||||||
convertTimeStamps(that, args, returnValue) {
|
convertTimeStamps(that, args, returnValue) {
|
||||||
const matched = returnValue.match(twelveHour);
|
const matched = returnValue.match(twelveHour);
|
||||||
if (!matched || matched.length !== 4) return;
|
if (!matched || matched.length !== 4) return;
|
||||||
|
|
|
@ -13,9 +13,11 @@ import { Reflection } from 'modules';
|
||||||
|
|
||||||
export default new class BlockedMessages extends BuiltinModule {
|
export default new class BlockedMessages extends BuiltinModule {
|
||||||
|
|
||||||
get settingPath() { return ['ui', 'default', 'blocked-messages'] }
|
/* Getters */
|
||||||
get moduleName() { return 'BlockedMessages' }
|
get moduleName() { return 'BlockedMessages' }
|
||||||
|
|
||||||
|
get settingPath() { return ['ui', 'default', 'blocked-messages'] }
|
||||||
|
|
||||||
async enabled(e) {
|
async enabled(e) {
|
||||||
const MessageListComponents = Reflection.module.byProps('BlockedMessageGroup');
|
const MessageListComponents = Reflection.module.byProps('BlockedMessageGroup');
|
||||||
MessageListComponents.OriginalBlockedMessageGroup = MessageListComponents.BlockedMessageGroup;
|
MessageListComponents.OriginalBlockedMessageGroup = MessageListComponents.BlockedMessageGroup;
|
||||||
|
@ -30,17 +32,22 @@ export default new class BlockedMessages extends BuiltinModule {
|
||||||
if (this.cancelBlockedMessages) this.cancelBlockedMessages();
|
if (this.cancelBlockedMessages) this.cancelBlockedMessages();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Methods */
|
||||||
static isBlocked(id) {
|
static isBlocked(id) {
|
||||||
const { RelationshipStore } = Reflection.modules;
|
const { RelationshipStore } = Reflection.modules;
|
||||||
return RelationshipStore.isBlocked(id);
|
return RelationshipStore.isBlocked(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Patches */
|
||||||
applyPatches() {
|
applyPatches() {
|
||||||
if (this.patches.length) return;
|
if (this.patches.length) return;
|
||||||
const { MessageActions } = Reflection.modules;
|
const { MessageActions } = Reflection.modules;
|
||||||
this.patch(MessageActions, 'receiveMessage', this.processMessage, 'instead');
|
this.patch(MessageActions, 'receiveMessage', this.processMessage, 'instead');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ignore blocked messages completely
|
||||||
|
*/
|
||||||
processMessage(that, args, originalFunction) {
|
processMessage(that, args, originalFunction) {
|
||||||
if (args[1] && args[1].author && args[1].author.id && BlockedMessages.isBlocked(args[1].author.id)) return;
|
if (args[1] && args[1].author && args[1].author.id && BlockedMessages.isBlocked(args[1].author.id)) return;
|
||||||
return originalFunction(...args);
|
return originalFunction(...args);
|
||||||
|
|
|
@ -15,6 +15,7 @@ import { Settings, Patcher, MonkeyPatch, Reflection, ReactComponents, DiscordApi
|
||||||
|
|
||||||
export default new class ColoredText extends BuiltinModule {
|
export default new class ColoredText extends BuiltinModule {
|
||||||
|
|
||||||
|
/* Getters */
|
||||||
get moduleName() { return 'ColoredText' }
|
get moduleName() { return 'ColoredText' }
|
||||||
|
|
||||||
get settingPath() { return ['ui', 'default', 'colored-text'] }
|
get settingPath() { return ['ui', 'default', 'colored-text'] }
|
||||||
|
@ -41,10 +42,12 @@ export default new class ColoredText extends BuiltinModule {
|
||||||
this.intensitySetting.off('setting-updated', this._intensityUpdated);
|
this.intensitySetting.off('setting-updated', this._intensityUpdated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Methods */
|
||||||
_intensityUpdated() {
|
_intensityUpdated() {
|
||||||
this.MessageContent.forceUpdateAll();
|
this.MessageContent.forceUpdateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Patches */
|
||||||
async applyPatches() {
|
async applyPatches() {
|
||||||
if (this.patches.length) return;
|
if (this.patches.length) return;
|
||||||
this.MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector });
|
this.MessageContent = await ReactComponents.getComponent('MessageContent', { selector: Reflection.resolve('container', 'containerCozy', 'containerCompact', 'edited').selector });
|
||||||
|
@ -52,6 +55,9 @@ export default new class ColoredText extends BuiltinModule {
|
||||||
this.MessageContent.forceUpdateAll();
|
this.MessageContent.forceUpdateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set markup text colour to match role colour
|
||||||
|
*/
|
||||||
injectColoredText(thisObject, args, returnValue) {
|
injectColoredText(thisObject, args, returnValue) {
|
||||||
const { TinyColor } = Reflection.modules;
|
const { TinyColor } = Reflection.modules;
|
||||||
const markup = Utils.findInReactTree(returnValue, m => m && m.props && m.props.className && m.props.className.includes('da-markup'));
|
const markup = Utils.findInReactTree(returnValue, m => m && m.props && m.props.className && m.props.className.includes('da-markup'));
|
||||||
|
|
Loading…
Reference in New Issue