Merge pull request #234 from JsSucks/builtins

Add several builtins
This commit is contained in:
Alexei Stukov 2018-08-22 14:29:18 +03:00 committed by GitHub
commit c1af0c6115
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 283 additions and 3 deletions

View File

@ -0,0 +1,37 @@
/**
* BetterDiscord 24 Hour Timestamps Module
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import BuiltinModule from './BuiltinModule';
import { Patcher, MonkeyPatch, WebpackModules, ReactComponents } from 'modules';
const twelveHour = new RegExp(`([0-9]{1,2}):([0-9]{1,2})\\s(AM|PM)`);
export default new class TwentyFourHour extends BuiltinModule {
get settingPath() {
return ['ui', 'default', '24-hour'];
}
async enabled(e) {
if (Patcher.getPatchesByCaller('BD:TwentyFourHour').length) return;
const TimeFormatter = WebpackModules.getModuleByName('TimeFormatter');
MonkeyPatch('BD:TwentyFourHour', TimeFormatter).after('calendarFormat', (thisObject, args, returnValue) => {
const matched = returnValue.match(twelveHour);
if (!matched || matched.length != 4) return;
if (matched[3] == 'AM') return returnValue.replace(matched[0], `${matched[1] == '12' ? '00' : matched[1].padStart(2, '0')}:${matched[2]}`)
return returnValue.replace(matched[0], `${parseInt(matched[1]) + 12}:${matched[2]}`)
});
}
disabled(e) {
Patcher.unpatchAll('BD:TwentyFourHour');
}
}

View File

@ -0,0 +1,49 @@
/**
* BetterDiscord Blocked Messages Module
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import BuiltinModule from './BuiltinModule';
import { Patcher, MonkeyPatch, WebpackModules, ReactComponents } from 'modules';
export default new class BlockedMessages extends BuiltinModule {
get settingPath() {
return ['ui', 'default', 'blocked-messages'];
}
static isBlocked(id) {
const RelationshipStore = WebpackModules.getModuleByName('RelationshipStore');
return RelationshipStore.isBlocked(id);
}
async enabled(e) {
if (Patcher.getPatchesByCaller('BD:BlockedMessages').length) return;
const MessageActions = WebpackModules.getModuleByName('MessageActions');
MonkeyPatch('BD:BlockedMessages', MessageActions).instead('receiveMessage', this.processMessage);
const MessageListComponents = WebpackModules.getModuleByProps(['BlockedMessageGroup']);
MessageListComponents.OriginalBlockedMessageGroup = MessageListComponents.BlockedMessageGroup;
MessageListComponents.BlockedMessageGroup = () => {return null;};
this.cancelBlockedMessages = () => {
MessageListComponents.BlockedMessageGroup = MessageListComponents.OriginalBlockedMessageGroup;
delete MessageListComponents.OriginalBlockedMessageGroup;
}
}
processMessage(thisObject, args, originalFunction) {
if (args[1] && args[1].author && args[1].author.id && BlockedMessages.isBlocked(args[1].author.id)) return;
return originalFunction(...args);
}
disabled(e) {
Patcher.unpatchAll('BD:BlockedMessages');
if (this.cancelBlockedMessages) this.cancelBlockedMessages();
}
}

View File

@ -0,0 +1,68 @@
/**
* BetterDiscord Colored Text Module
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import BuiltinModule from './BuiltinModule';
import { Utils } from 'common';
import { Settings, Patcher, MonkeyPatch, WebpackModules, ReactComponents, DiscordApi } from 'modules';
export default new class ColoredText extends BuiltinModule {
constructor() {
super();
this._intensityUpdated = this._intensityUpdated.bind(this);
this.injectColoredText = this.injectColoredText.bind(this);
}
get settingPath() {
return ['ui', 'default', 'colored-text'];
}
get intensityPath() {
return ['ui', 'advanced', 'colored-text-intensity'];
}
get intensitySetting() {
return Settings.getSetting(...this.intensityPath);
}
get intensity() {
return 100 - this.intensitySetting.value;
}
_intensityUpdated() {
this.MessageContent.forceUpdateAll();
}
async enabled(e) {
if (Patcher.getPatchesByCaller('BD:ColoredText').length) return;
this.intensitySetting.on('setting-updated', this._intensityUpdated);
this.MessageContent = await ReactComponents.getComponent('MessageContent', { selector: WebpackModules.getSelector('container', 'containerCozy', 'containerCompact', 'edited') });
MonkeyPatch('BD:ColoredText', this.MessageContent.component.prototype).after('render', this.injectColoredText);
this.MessageContent.forceUpdateAll();
}
injectColoredText(thisObject, args, returnValue) {
const TinyColor = WebpackModules.getModuleByName('TinyColor');
const markup = Utils.findInReactTree(returnValue, m => m && m.props && m.props.className && m.props.className.includes('da-markup'));
const roleColor = thisObject.props.message.colorString;
if (markup && roleColor) markup.props.style = {color: TinyColor.mix(roleColor, this.defaultColor, this.intensity)};
}
get defaultColor() {
return DiscordApi.UserSettings.theme == 'light' ? '#747f8d' : '#dcddde';
}
disabled(e) {
Patcher.unpatchAll('BD:ColoredText');
this.intensitySetting.off('setting-updated', this._intensityUpdated);
}
}

View File

@ -0,0 +1,30 @@
/**
* BetterDiscord Kill Clyde Module
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import BuiltinModule from './BuiltinModule';
import { Patcher, MonkeyPatch, WebpackModules } from 'modules';
export default new class KillClyde extends BuiltinModule {
get settingPath() {
return ['ui', 'default', 'kill-clyde'];
}
async enabled(e) {
if (Patcher.getPatchesByCaller('BD:KillClyde').length) return;
const MessageActions = WebpackModules.getModuleByName('MessageActions');
MonkeyPatch('BD:KillClyde', MessageActions).instead('sendBotMessage', void 0);
}
disabled(e) {
Patcher.unpatchAll('BD:KillClyde');
}
}

View File

@ -3,6 +3,11 @@ import { default as ReactDevtoolsModule } from './ReactDevtoolsModule';
import { default as VueDevtoolsModule } from './VueDevToolsModule';
import { default as TrackingProtection } from './TrackingProtection';
import { default as E2EE } from './E2EE';
import { default as ColoredText } from './ColoredText';
import { default as TwentyFourHour } from './24Hour';
import { default as KillClyde } from './KillClyde';
import { default as BlockedMessages } from './BlockedMessages';
import { default as VoiceDisconnect } from './VoiceDisconnect';
export default class {
static initAll() {
@ -11,5 +16,10 @@ export default class {
VueDevtoolsModule.init();
TrackingProtection.init();
E2EE.init();
ColoredText.init();
TwentyFourHour.init();
KillClyde.init();
BlockedMessages.init();
VoiceDisconnect.init();
}
}

View File

@ -0,0 +1,33 @@
/**
* BetterDiscord Voice Disconnect Timestamps Module
* Copyright (c) 2015-present Jiiks/JsSucks - https://github.com/Jiiks / https://github.com/JsSucks
* All rights reserved.
* https://betterdiscord.net
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import BuiltinModule from './BuiltinModule';
import { WebpackModules } from 'modules';
export default new class VoiceDisconnect extends BuiltinModule {
get settingPath() {
return ['core', 'default', 'voice-disconnect'];
}
async enabled(e) {
window.addEventListener('beforeunload', this.listener);
}
listener() {
const VoiceChannelActions = WebpackModules.getModuleByName('VoiceChannelActions');
VoiceChannelActions.selectVoiceChannel(null, null);
}
disabled(e) {
window.removeEventListener('beforeunload', this.listener);
}
}

View File

@ -4,3 +4,8 @@ export { default as VueDevtoolsModule } from './VueDevToolsModule';
export { default as TrackingProtection } from './TrackingProtection';
export { default as BuiltinManager } from './Manager';
export { default as E2EE } from './E2EE';
export { default as ColoredText } from './ColoredText';
export { default as TwentyFourHour } from './24Hour';
export { default as KillClyde } from './KillClyde';
export { default as BlockedMessages } from './BlockedMessages';
export { default as VoiceDisconnect } from './VoiceDisconnect';

View File

@ -12,8 +12,7 @@
"type": "bool",
"text": "Voice Disconnect",
"hint": "Disconnect from voice server when Discord closes",
"value": false,
"disabled": true
"value": false
},
{
"id": "menu-keybind",
@ -100,6 +99,52 @@
"text": "Enable Toasts",
"hint": "Allows plugins to show toasts.",
"value": true
},
{
"id": "colored-text",
"type": "bool",
"text": "Colored Text",
"hint": "Colors messages to match the user's role color.",
"value": false
},
{
"id": "24-hour",
"type": "bool",
"text": "24 Hour Timestamps",
"hint": "Replaces 12 hour timestamps with proper ones.",
"value": false
},
{
"id": "kill-clyde",
"type": "bool",
"text": "Kill Clyde",
"hint": "Prevents Clyde from sending you error messages.",
"value": false
},
{
"id": "blocked-messages",
"type": "bool",
"text": "Prevent Blocked Messages",
"hint": "Hides blocked messages in chat and even hides the new message notification.",
"value": false
}
]
},
{
"id": "advanced",
"name": "Advanced",
"type": "drawer",
"settings": [
{
"id": "colored-text-intensity",
"type": "slider",
"text": "Colored Text Intensity",
"hint": "Intensity of the colored text setting.",
"value": 100,
"min": 0,
"max": 100,
"step": 1,
"unit": "%"
}
]
}

View File

@ -36,6 +36,7 @@ const KnownModules = {
ChannelActions: Filters.byProperties(['selectChannel']),
PrivateChannelActions: Filters.byProperties(['openPrivateChannel']),
ChannelSelector: Filters.byProperties(['selectGuild', 'selectChannel']),
VoiceChannelActions: Filters.byProperties(['selectVoiceChannel']),
/* Current User Info, State and Settings */
UserInfoStore: Filters.byProperties(['getToken']),
@ -44,7 +45,7 @@ const KnownModules = {
UserSettingsUpdater: Filters.byProperties(['updateRemoteSettings']),
OnlineWatcher: Filters.byProperties(['isOnline']),
CurrentUserIdle: Filters.byProperties(['getIdleTime']),
RelationshipStore: Filters.byProperties(['isBlocked']),
RelationshipStore: Filters.byProperties(['isBlocked', 'isFriend']),
RelationshipManager: Filters.byProperties(['addRelationship']),
MentionStore: Filters.byProperties(['getMentions']),
@ -73,6 +74,7 @@ const KnownModules = {
Permissions: Filters.byProperties(['getHighestRole']),
ColorConverter: Filters.byProperties(['hex2int']),
ColorShader: Filters.byProperties(['darken']),
TinyColor: Filters.byPrototypeFields(['toRgb']),
ClassResolver: Filters.byProperties(['getClass']),
ButtonData: Filters.byProperties(['ButtonSizes']),
IconNames: Filters.byProperties(['IconNames']),
@ -135,6 +137,7 @@ const KnownModules = {
Moment: Filters.byProperties(['parseZone']),
LocationManager: Filters.byProperties(['createLocation']),
Timestamps: Filters.byProperties(['fromTimestamp']),
TimeFormatter: Filters.byProperties(['dateFormat']),
/* Strings and Utils */
Strings: Filters.byProperties(['TEXT', 'TEXTAREA_PLACEHOLDER']),