Last active
January 30, 2022 20:43
-
-
Save Modder4869/761a6c44ca93e7580a7a73ba0d643019 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//META{"name":"showAllGuildsMsg"}*// | |
class showAllGuildsMsg { | |
getName() { | |
return "showAllGuildMsg"; | |
} // Name of your plugin to show on the plugins page | |
getDescription() { | |
return "raw discord messages without specfic channel"; | |
} // Description to show on the plugins page | |
getVersion() { | |
return "0.0.1"; | |
} // Current version. I recommend following semantic versioning <http://semver.org/> (e.g. 0.0.1) | |
getAuthor() { | |
return "Modder4869, square"; | |
} // Your name | |
load() { | |
this.init(); | |
} | |
init() { | |
this.css = ` | |
@import url('https://fonts.googleapis.com/css?family=Ubuntu'); | |
#rawChatlog { | |
overflow-y: scroll; | |
display: table-row-group; | |
min-height: 200px; | |
background-color: #36393f; | |
word-break: break-word; | |
} | |
#rawChatlog .rawChatMsg { | |
user-select: all; | |
} | |
#rawChatlog .rawChatMsg * { | |
padding: 0 .1ch; | |
} | |
#rawChatlog .rawChatMsg.edited::after { | |
content: " (edited)"; | |
opacity: .5; | |
font-size: .7; | |
} | |
#rawChatlog .serverName { | |
font-wight: bold; | |
color: #99aab5; | |
font-family: 'Ubuntu', sans-serif; | |
user-select: all; | |
} | |
#rawChatlog .serverName::before {content: "in: ";} | |
#rawChatlog .serverName::after {content: ",";} | |
#rawChatlog .channelName { | |
color:#72767d; | |
} | |
#rawChatlog .channelName:hover { | |
color: #b9bbbe; | |
cursor: pointer; | |
text-decoration: underline; | |
} | |
#rawChatlog .channelName::before {content: "#";} | |
#rawChatlog .messageText { | |
color: #747f8d; | |
font-family: Helvetica Neue; | |
user-select: all; | |
} | |
#rawChatlog .username { | |
color: #43b581; | |
user-select: all; | |
} | |
`; | |
} | |
start() { | |
if ("undefined" === typeof ZeresPluginLibrary) return BdApi.alert("Library Missing", `The library plugin needed for ${this.getName()} is missing.<br /><br /> <a href="https://betterdiscord.net/ghdl?url=https://raw.githubusercontent.com/rauenzi/BDPluginLibrary/master/release/0PluginLibrary.plugin.js" target="_blank">Click here to download the library!</a>`); | |
ZLibrary.PluginUpdater.checkForUpdate(this.getName(), this.getVersion(), "LINK_TO_RAW_CODE"); | |
this.modal = document.createElement("div"); | |
this.modal.id = "rawChatlog"; | |
this.msgsMap = new Map(); | |
this.navigator = BdApi.findModuleByProps("transitionTo"); | |
this.NotificationStore = BdApi.findModuleByProps("isGuildOrCategoryOrChannelMuted"); | |
BdApi.injectCSS(this.getName(), this.css); | |
this.inject(); | |
this.onSwitch(); | |
} | |
inject() { | |
this.ws = BdApi.findModuleByProps("dispatch"); | |
ZLibrary.Patcher.before(this.getName(), this.ws, "dispatch",(t, a, r) => { | |
var ev = a[0]; | |
if ("MESSAGE_CREATE" === ev.type || "MESSAGE_UPDATE" === ev.type) this.processMessageEvent(ev); | |
// return false; | |
// console.log(a[0]) | |
// }); | |
// // if (this.ws) this.ws.setInterceptor(ev => { | |
// if ("MESSAGE_CREATE" === ev.type || "MESSAGE_UPDATE" === ev.type) this.processMessageEvent(ev); | |
// // return false; | |
// }); | |
// } | |
})} | |
stop() { | |
ZLibrary.Patcher.unpatchAll(this.getName()) | |
BdApi.clearCSS(this.getName(), this.css); | |
this.eject(); | |
this.modal.remove(); | |
delete this.modal; | |
this.msgsMap.clear(); | |
delete this.msgsMap; | |
delete this.navigator; | |
delete this.NotificationStore; | |
} | |
eject() { | |
// if (this.ws) this.ws.setInterceptor(null); | |
delete this.ws; | |
} | |
onSwitch() { | |
if (!document.getElementById("rawChatlog")) { | |
var chat = document.querySelector('.chat-3bRxxu'); | |
if (chat) { | |
chat.appendChild(this.modal); | |
this.modal.scrollTop = this.modal.scrollHeight - this.modal.clientHeight; | |
} | |
} | |
} | |
processMessageEvent(ev) { | |
var elem, first, {message, type} = ev; | |
var channel = ZLibrary.DiscordModules.ChannelStore.getChannel(message.channel_id); | |
if (!message.author) { | |
message = ZLibrary.DiscordModules.MessageStore.getMessage(channel.id, message.id); | |
if (!message || !message.author) return; | |
} | |
if ( | |
this.NotificationStore.isGuildOrCategoryOrChannelMuted(channel.guild_id, message.channel_id) || | |
message.author && ZLibrary.DiscordModules.RelationshipStore.isBlocked(message.author.id) | |
) return; | |
if ("MESSAGE_UPDATE" === type && (elem = this.msgsMap.get(message.id))) { | |
this.updateMessageElement(elem, message, channel, true); | |
return; | |
} | |
if (this.msgsMap.get(message.id) || "SENDING" === message.state) return; | |
elem = this.createMessageElement(); | |
if (false === this.updateMessageElement(elem, message, channel, "MESSAGE_UPDATE" === type)) return; | |
var scrollPos = (this.modal.scrollHeight === this.modal.clientHeight ? this.modal.clientHeight : this.modal.scrollTop) | |
&& (this.modal.scrollTop + this.modal.clientHeight) / this.modal.scrollHeight; | |
this.modal.appendChild(elem); | |
this.modal.scrollTop = scrollPos && scrollPos * this.modal.scrollHeight - this.modal.clientHeight; | |
this.msgsMap.set(message.id, elem); | |
if (this.modal.children.length >= 50) { | |
first = this.modal.firstChild; | |
this.msgsMap.delete(first.getAttribute("data-id")); | |
first.remove(); | |
} | |
} | |
createMessageElement() { | |
var elem = document.createElement("div"); | |
elem.className = "rawChatMsg"; | |
elem.innerHTML = ` | |
<span class="serverName"></span> | |
<span class="channelName"></span> | |
<span class="username"></span> | |
<span class="messageText .markup-2BOw-j"></span>`; | |
return elem; | |
} | |
updateMessageElement(elem, message, channel, edited) { | |
try { | |
elem.children[0].textContent = ZLibrary.DiscordModules.GuildStore.getGuild(channel.guild_id).name; | |
elem.children[1].textContent = channel.name; | |
elem.children[2].textContent = message.author.username + "#" + message.author.discriminator; | |
elem.children[3].textContent = message.content; | |
} catch(err) {/* debugger */} | |
if (edited) { | |
elem.classList.add("edited"); | |
} | |
elem.setAttribute("data-id", message.id); | |
elem.children[1].onclick = ev => { | |
ev.stopPropagation(); | |
this.navigator.transitionTo(ZLibrary.DiscordModules.DiscordConstants.Routes.MESSAGE(channel.guild_id, channel.id, message.id)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment