you can change emoji prefix, ain't that wacky ?

This commit is contained in:
Jean Ouina 2020-09-17 12:06:02 +02:00
parent 76416383d7
commit 15bb21733e
11 changed files with 420 additions and 42 deletions

File diff suppressed because one or more lines are too long

View File

@ -55,7 +55,8 @@ export const settings = {
"Enable Lightcord Servers": {id: "lightcord-5", info: "Enable Lightcord's servers. Disabling this will disable custom badges.", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
"Disable typing": {id: "lightcord-7", info: "Don't let other see you're typing.", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord"},
"Lightcord Tabs": {id: "lightcord-8", info: "Allows you to launch multiple instances of Lightcord in the same window.", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord", experimental: true},
"Use Notification Shim": {id: "lightcord-10", info: "Basically don't use Windows's Notifications.", implemented: true, hidden: process.platform !== "win32", cat: "lightcord", category: "Lightcord", experimental: false},
"Use Notification Shim": {id: "lightcord-10", info: "Basically don't use Windows's Notifications.", implemented: true, hidden: process.platform !== "win32", cat: "lightcord", category: "Lightcord"},
"Emoji Prefix": {id: "lightcord-11", info: "Change the prefix used for free nitros emojis. Please put only one character. Default: .", implemented: true, hidden: false, cat: "lightcord", category: "Lightcord", default: "."},
/** Lightcord Window */
"Always-on-Top": {id: "lightcord-3", info: "Enable the window's Always-on-Top mode, where Lightcord stays on top of other applications.", implemented: true, hidden: false, cat: "lightcord", category: "Window"},

View File

@ -1,5 +1,6 @@
import BDV2 from "./v2";
import Utils from "./utils";
import { settings } from "../0globals";
const Constants = {
EmojiRegex: /<a?\.(\w+)\.(\d+)>/g
@ -13,6 +14,7 @@ let EmojiModuleQuery = BDModules.get(e => e.default && e.default.queryEmojiResul
let Messages = BDModules.get(e => e.default && e.default.Messages && e.default.Messages.EMOJI_MATCHING)[0]
let guildModule = BDModules.get(e => e.default && e.default.getGuild && e.default.getGuilds && !e.default.isFetching)[0]
let emojiSearch = BDModules.get(e => e.default && e.default.getDisambiguatedEmojiContext)
const appSettings = Lightcord.Api.settings
export default new class EmojiModule {
constructor(){
@ -28,6 +30,13 @@ export default new class EmojiModule {
if(!guildModule)guildModule = await window.Lightcord.Api.ensureExported(e => e.default && e.default.getGuild && e.default.getGuilds && !e.default.isFetching)
if(!emojiSearch)emojiSearch = await window.Lightcord.Api.ensureExported(e => e.default && e.default.getDisambiguatedEmojiContext)
const setting = settings["Emoji Prefix"]
const getValue = () => {
const value = appSettings.get("BD_"+setting.id, setting.default)
if(typeof value !== "string")return setting.default
return value
}
if(AutocompleteModule && AutoCompletionTemplates && EmojiModuleQuery && Messages && guildModule && emojiSearch){
console.log(`Patching getAutocompleteOptions of AutoCompletionTemplates`, AutoCompletionTemplates)
const getAutocompleteOptions = AutoCompletionTemplates.getAutocompleteOptions
@ -35,7 +44,7 @@ export default new class EmojiModule {
const value = getAutocompleteOptions.call(this, ...arguments)
value.LIGHTCORD_EMOJIS = {
matches(arg1, arg2){
let condition = arg2.length > 1 && "." === arg1
let condition = arg2.length > 1 && getValue() === arg1
setEmojiUsable(condition)
return condition
},
@ -48,11 +57,11 @@ export default new class EmojiModule {
return {
emoji: e,
key: e.id || e.uniqueName || e.name,
sentinel: ".",
sentinel: getValue(),
guild: null != e.guildId ? guildModule.default.getGuild(e.guildId) : null
}
}), (function(e) {
return "." + e + "."
return getValue() + e + getValue()
}))
},
getPlainText(id, guild){
@ -137,7 +146,7 @@ export default new class EmojiModule {
if(!CustomEmojiModule)CustomEmojiModule = BDModules.get(e => e.CustomEmoji)[0]
return React.createElement(CustomEmojiModule.CustomEmoji, {
emoji: {
name: `.${emoji.name}.`,
name: `${getValue()}${emoji.name}${getValue()}`,
emojiId: emoji.id,
animated: emoji.animated,
jumboable: arr.length === 1 && content.length === 1

View File

@ -31,6 +31,7 @@ import tooltipWrap from "../ui/tooltipWrap";
import History from "../ui/icons/history";
import core from "./core";
import popoutWindow from "./popoutWindow";
import TextInputSetting from "../ui/TextInputSetting";
class BDSidebarHeader extends React.PureComponent {
render(){
@ -113,7 +114,7 @@ export default new class V2_SettingsPanel {
}
updateSettings(id, enabled, sidebar) {
if(!["lightcord-8", "no_window_bound", "enable_glasstron", "lightcord-10"].includes(id))settingsCookie[id] = enabled;
if(!["lightcord-8", "no_window_bound", "enable_glasstron", "lightcord-10", "lightcord-11"].includes(id))settingsCookie[id] = enabled;
if (id == "bda-gs-2") {
if (enabled) DOM.addClass(document.body, "bd-minimal");
@ -255,6 +256,18 @@ export default new class V2_SettingsPanel {
appSettings.save()
DiscordNative.app.relaunch()
}
if(id === "lightcord-11"){
let appSettings = window.Lightcord.Api.settings
if(!enabled){
appSettings.delete("BD_"+id)
appSettings.save()
return
}
appSettings.set("BD_"+id, enabled)
appSettings.save()
return
}
this.saveSettings();
}
@ -315,13 +328,21 @@ export default new class V2_SettingsPanel {
BDV2.react.createElement("h2", {className: "ui-form-title h2 margin-reset margin-bottom-20"}, section.title),
section.settings.map(setting => {
let isChecked = settingsCookie[setting.id]
let value = appSettings.get("BD_"+setting.id, setting.default || "")
if(setting.id === "lightcord-8")isChecked = appSettings.get("isTabs", false);
if(setting.id === "no_window_bound")isChecked = appSettings.get("NO_WINDOWS_BOUND", false)
if(setting.id === "enable_glasstron")isChecked = appSettings.get("GLASSTRON", true)
if(setting.id === "lightcord-10")isChecked = !appSettings.get("DEFAULT_NOTIFICATIONS", true)
let returnValue = BDV2.react.createElement(Switch, {id: setting.id, key: setting.id, data: setting, checked: isChecked, onChange: (id, checked) => {
this.onChange(id, checked, sidebar);
}})
let returnValue
if(["lightcord-11"].includes(setting.id)){
returnValue = BDV2.react.createElement(TextInputSetting, {id: setting.id, key: setting.id, data: setting, value, placeholder: setting.default || null, onChange: (id, value) => {
this.onChange(id, value, sidebar);
}})
}else{
returnValue = BDV2.react.createElement(Switch, {id: setting.id, key: setting.id, data: setting, checked: isChecked, onChange: (id, checked) => {
this.onChange(id, checked, sidebar);
}})
}
if(setting.id == "lightcord-8" && isChecked){
return [
returnValue,

View File

@ -0,0 +1,49 @@
import BDV2 from "../modules/v2";
import TextInput from "./components/textinput";
let classnames = []
function getClassName(name){
let className = classnames.find(e => e.startsWith(name+"-"))
if(className)return className
className = BDModules.get(e => e[name])[0][name]
classnames.push(className)
return className
}
export default class TextInputSetting extends BDV2.reactComponent {
constructor(props) {
super(props);
this.onChange = this.onChange.bind(this);
}
onChange(value) {
this.props.onChange(this.props.id, value);
}
render() {
let {text, info} = this.props.data;
if(this.props.data.experimental){
if(!classnames.find(e => e.startsWith("beta-"))){
classnames.push(BDModules.get(e => e.beta && (!e.container && !e.userSettingsVoice))[0].beta)
}
info = [
info,
<sup className={getClassName("beta")}>(EXPERIMENTAL)</sup>
]
}
return <div className={"ui-flex flex-vertical flex-justify-start flex-align-stretch flex-nowrap ui-switch-item"}>
<div className={"ui-flex flex-horizontal flex-justify-start flex-align-stretch flex-nowrap"}>
<h3 key="title" className="ui-form-title h3 margin-reset margin-reset ui-flex-child">
{text}
</h3>
<TextInput key="input" onChange={this.onChange} value={this.props.value} placeholder={this.props.placeholder||null} />
</div>
<div className="ui-form-text style-description margin-top-4" style={{
flex: "1 1 auto"
}}>
{info}
</div>
</div>
}
}

View File

@ -0,0 +1,28 @@
import BDV2 from "../../modules/v2";
const React = BDV2.React;
export default class TextInput extends React.Component {
constructor(props) {
super(props);
this.state = {value: this.props.value};
this.onChange = this.onChange.bind(this);
this.emitChange = this.emitChange.bind(this);
this.input = <Lightcord.Api.Components.inputs.TextInput.original ref={console.log} onChange={this.onChange} value={this.state.value} placeholder={this.props.placeholder} onBlur={this.emitChange}/>
}
onChange(value) {
console.log(value, this.props)
if (this.props.disabled) return;
this.props.onChange(value);
this.setState({value: value});
}
emitChange(){
console.log(`Should emit changes.`)
}
render() {
return this.input
}
}

View File

@ -24,10 +24,10 @@ export default class SwitchItem extends BDV2.reactComponent {
render() {
let {text, info} = this.props.data;
if(!classnames.find(e => e.startsWith("beta-"))){
classnames.push(BDModules.get(e => e.beta && (!e.container && !e.userSettingsVoice))[0].beta)
}
if(this.props.data.experimental){
if(!classnames.find(e => e.startsWith("beta-"))){
classnames.push(BDModules.get(e => e.beta && (!e.container && !e.userSettingsVoice))[0].beta)
}
info = [
info,
React.createElement("sup", {className: getClassName("beta")}, "(EXPERIMENTAL)")

File diff suppressed because one or more lines are too long

View File

@ -79,4 +79,42 @@ function setReq(){
}catch(e){
req = undefined
}
}
}
class DangerousWebpackloader {
get modules(){
if(req){
return Object.values(req.c).filter((e:any) => e && e.exports)
}else{
setReq()
if(req){
return Object.values(req.c).filter((e:any) => e && e.exports)
}else{
return []
}
}
}
get(ids, modules?){
if(typeof ids === "function"){
return (modules || this.modules).map((mdl) => {
if(mdl && typeof mdl.exports !== "undefined"){
return mdl.exports
}else{
return null
}
}).filter(e => e).filter(ids)
}else if(Array.isArray(ids)){
modules = modules || this.modules
return ids.map(id => this.get(id, modules))
}else{
modules = modules || this.modules
let module = modules.filter(e => !!e).find(e => e.i === ids)
if(!module)return undefined
return module.exports
}
}
get default(){
return this
}
}
export const dangerousBDModules = new DangerousWebpackloader()

View File

@ -1,2 +1,2 @@
export const isNative:boolean = typeof window.BDModules === "undefined"
export const isImported:boolean = typeof window.BDModules !== "undefined"
export const isNative:boolean = typeof window.BDModules !== "undefined"
export const isImported:boolean = typeof window.BDModules === "undefined"

View File

@ -2,6 +2,7 @@ import Utils from "./Utils"
import Notices, { notices } from "../components/private/Notices"
import { isNative } from "./environnement";
import WebpackLoader from "./WebpackLoader";
import { dangerousBDModules } from "./BDModules";
export function patch(){
/** START NOTICE */
@ -66,13 +67,14 @@ export function patch(){
UserPopoutComponent.prototype.render = function(){
const returnValue = render.call(this, ...arguments)
try{
console.log(returnValue)
returnValue.props.children.props["data-user-id"] = this.props.user.id
}catch(e){
console.error(e)
}
return returnValue
}
})
}).catch(console.error)
/** END USERPOPOUT PATCH*/
/** START USERPROFILE PATCH */
@ -94,13 +96,14 @@ export function patch(){
const returnValue = render.call(this, ...arguments)
console.log(returnValue)
try{
console.log(returnValue)
returnValue.props.children.props["data-user-id"] = this.props.user.id
}catch(e){
console.error(e)
}
return returnValue
}
})
}).catch(console.error)
/** END USERPROFILE PATCH */
/** START WEBHOOK PATCH */
@ -212,7 +215,10 @@ function getModule(filter: (mod:any) => boolean):Promise<any>{
let hasCompletedLogin = false
let loginPromise:Promise<void>
let AuthenticationStore = dangerousBDModules.get(e => e.default && e.default.isAuthenticated)
AuthenticationStore = AuthenticationStore[0] && AuthenticationStore[0].default
function awaitLogin():Promise<void>{
if(AuthenticationStore && AuthenticationStore.isAuthenticated())return Promise.resolve()
if(hasCompletedLogin)return Promise.resolve()
if(loginPromise)return loginPromise