New message event
This commit is contained in:
parent
605e869413
commit
aa3226ce43
|
@ -21,7 +21,12 @@ export default class {
|
||||||
static observe() {
|
static observe() {
|
||||||
Events.on('server-switch', this.injectAll.bind(this));
|
Events.on('server-switch', this.injectAll.bind(this));
|
||||||
Events.on('channel-switch', this.injectAll.bind(this));
|
Events.on('channel-switch', this.injectAll.bind(this));
|
||||||
Events.on('new-message', e => console.log(e)); // TODO
|
Events.on('discord:MESSAGE_CREATE', e => {
|
||||||
|
// Assume that it's the last one for now since the event doesn't give the element
|
||||||
|
const query = document.querySelectorAll('.markup:not(.mutable)');
|
||||||
|
if (!query) return;
|
||||||
|
this.injectMarkup(query[query.length - 1], true);
|
||||||
|
}); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
static injectAll() {
|
static injectAll() {
|
||||||
|
@ -60,6 +65,7 @@ export default class {
|
||||||
if (cn.className && cn.className.includes('mutable')) cc = cn;
|
if (cn.className && cn.className.includes('mutable')) cc = cn;
|
||||||
}
|
}
|
||||||
if (cc) sibling.parentElement.removeChild(cc);
|
if (cc) sibling.parentElement.removeChild(cc);
|
||||||
|
if (markup === true) markup = this.cloneMarkup(sibling);
|
||||||
markup.clone = this.injectEmotes(markup.clone);
|
markup.clone = this.injectEmotes(markup.clone);
|
||||||
sibling.parentElement.insertBefore(markup.clone, sibling);
|
sibling.parentElement.insertBefore(markup.clone, sibling);
|
||||||
sibling.classList.add('shadow');
|
sibling.classList.add('shadow');
|
||||||
|
|
|
@ -28,7 +28,7 @@ class BetterDiscord {
|
||||||
window.bdmodals = Modals;
|
window.bdmodals = Modals;
|
||||||
window.bdlogs = Logger;
|
window.bdlogs = Logger;
|
||||||
window.emotes = EmoteModule;
|
window.emotes = EmoteModule;
|
||||||
|
EmoteModule.observe();
|
||||||
DOM.injectStyle(BdCss, 'bdmain');
|
DOM.injectStyle(BdCss, 'bdmain');
|
||||||
Events.on('global-ready', this.globalReady.bind(this));
|
Events.on('global-ready', this.globalReady.bind(this));
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
import EventListener from './eventlistener';
|
import EventListener from './eventlistener';
|
||||||
import { Utils } from 'common';
|
import { Utils } from 'common';
|
||||||
import Events from './events';
|
import Events from './events';
|
||||||
|
import WebpackModules from './webpackmodules';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
MESSAGE_CREATE
|
MESSAGE_CREATE
|
||||||
|
@ -23,6 +24,10 @@ import {
|
||||||
*/
|
*/
|
||||||
export default class extends EventListener {
|
export default class extends EventListener {
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this.hook();
|
||||||
|
}
|
||||||
|
|
||||||
bindings() {
|
bindings() {
|
||||||
this.hook = this.hook.bind(this);
|
this.hook = this.hook.bind(this);
|
||||||
}
|
}
|
||||||
|
@ -33,9 +38,19 @@ export default class extends EventListener {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
hook() {}
|
hook() {
|
||||||
|
const self = this;
|
||||||
|
const orig = this.eventsModule.prototype.emit;
|
||||||
|
this.eventsModule.prototype.emit = function (...args) {
|
||||||
|
orig.call(this, ...args);
|
||||||
|
self.wsc = this;
|
||||||
|
self.emit(...args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
get eventsModule() {}
|
get eventsModule() {
|
||||||
|
return WebpackModules.getModuleByPrototypes(['setMaxListeners', 'emit']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Discord emit overload
|
* Discord emit overload
|
||||||
|
@ -58,7 +73,7 @@ export default class extends EventListener {
|
||||||
dispatch(e, d) {
|
dispatch(e, d) {
|
||||||
|
|
||||||
Events.emit('raw-event', { type: e, data: d });
|
Events.emit('raw-event', { type: e, data: d });
|
||||||
|
let evt = null;
|
||||||
switch (e) {
|
switch (e) {
|
||||||
case this.actions.READ:
|
case this.actions.READ:
|
||||||
Events.emit('discord-ready');
|
Events.emit('discord-ready');
|
||||||
|
@ -74,7 +89,7 @@ export default class extends EventListener {
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case this.actions.MESSAGE_CREATE:
|
case this.actions.MESSAGE_CREATE:
|
||||||
Events.emit('discord-event', { type: e, data: new MESSAGE_CREATE(d) });
|
evt = { type: e, data: new MESSAGE_CREATE(d) };
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
Events.emit('discord-event', {
|
Events.emit('discord-event', {
|
||||||
|
@ -86,6 +101,7 @@ export default class extends EventListener {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (evt !== null) Events.emit(`discord:${evt.type}`, evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue