-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (63 loc) · 1.88 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
66
67
68
69
70
71
72
73
74
75
76
77
"use strict";
const { decode } = require("html-entities");
module.exports = function logChat(mod) {
const chatChannels = {
"say": 0,
"party": 1,
"guild": 2,
"area": 3,
"trade": 4,
"greet": 9,
"private": [11, 12, 13, 14, 15, 16, 17, 18],
"p-notice": 21,
"emote": 26,
"global": 27,
"r-notice": 25,
"raid": 32,
"megaphone": 213,
"guild-adv": 214
};
mod.command.add("lc", {
"$none": () => {
mod.settings.enabled = !mod.settings.enabled;
mod.command.message(`Module ${mod.settings.enabled ? "enabled" : "disabled"}`);
},
"$default": arg => {
if (mod.settings[arg] === undefined) {
return mod.command.message("Invalid chat section.");
}
mod.settings[arg] = !mod.settings[arg];
mod.command.message(`Type ${arg}: ${mod.settings[arg] ? "enabled" : "disabled"}`);
}
});
mod.hook("S_WHISPER", "*", { "filter": { "fake": null } }, sChat);
mod.hook("S_CHAT", "*", { "filter": { "fake": null } }, sChat);
mod.hook("S_PRIVATE_CHAT", "*", { "filter": { "fake": true } }, sChat);
function sChat(event) {
if (!mod.settings.enabled) return;
let type = "whisper";
if (event.authorID !== undefined && event.authorName !== undefined && event.authorID === 0n && event.authorName === "") {
type = "toolbox";
}
if (event.channel !== undefined) {
type = getChannelType(event.channel);
}
if (mod.settings[type] === undefined || mod.settings[type] === false) {
return;
}
const message = `[${type}]${event.name ? ` ${event.name}` : ""}: ${decode(event.message.replace(/<[^>]*>?/gm, ""))}`;
if (mod.game.me.is(event.gameId)) {
console.log(">>>", message);
} else {
console.log("<<<", message);
}
}
function getChannelType(channel) {
for (const [type, channels] of Object.entries(chatChannels)) {
if ((Array.isArray(channels) && channels.includes(channel)) || channel == channels) {
return type;
}
}
return false;
}
};