-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
65 lines (55 loc) · 2.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const { Plugin } = require('powercord/entities');
const Settings = require("./Settings");
const { inject, uninject } = require("powercord/injector");
const generateEmojipasta = require("./generateEmojiPasta");
const { getModule, getModuleByDisplayName, React } = require('powercord/webpack');
const getSettings = require("./getSettings");
module.exports = class Emojifier extends Plugin {
async startPlugin() {
// set the config if none is set
if (!window.localStorage.getItem("excluded-server"))
window.localStorage.setItem("excluded-server", "[]");
if (!window.localStorage.getItem("excluded-channel"))
window.localStorage.setItem("excluded-channel", "[]");
if (!window.localStorage.getItem("max-emoji-per-word"))
window.localStorage.setItem("max-emoji-per-word", "2");
this.loadStylesheet("style.scss");
powercord.api.settings.registerSettings("emojify", {
category: this.entityID,
label: "Emojifier",
render: Settings
});
setImmediate(async () => {
const messageEvents = await getModule(["sendMessage"], true);
if (!messageEvents)
throw new ReferenceError("Failed to load message events");
inject("emojifier-injection-id", messageEvents, "sendMessage", function (args) {
const { getChannel } = getModule(["getChannel"], false);
const emojiPasta = generateEmojipasta(args[1].content);
const channel = getChannel(args[0]);
const { exludedChannel, exludedServer } = getSettings();
const excludedChannel = exludedChannel.map(e => e.split(/(\d+)/)[1]);
const excludedServer = exludedServer.map(s => s.split(/(\d+)/)[1]);
const isUserChannel = channel.type === 1;
if (excludedChannel.includes(channel.id) || excludedServer.includes(channel.guild_id))
return args;
// block emote from dm
for (const exclChannel of excludedChannel) {
if (channel.recipients.includes(exclChannel))
return args;
}
for (const server of excludedServer) {
if (channel.recipients.includes(server))
return args;
}
args[1].content = emojiPasta;
return args;
});
});
}
pluginWillUnload() {
powercord.api.settings.unregisterSettings("emojify");
powercord.api.settings.unregisterCommand("emojify");
uninject("emojifier-injection-id");
}
};