Skip to content

Commit 4acac2f

Browse files
committed
irc
1 parent 180b998 commit 4acac2f

File tree

4 files changed

+106
-3
lines changed

4 files changed

+106
-3
lines changed

config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ class Settings {
1414
})
1515
enabled = true;
1616

17+
@SwitchProperty({
18+
name: "IRC",
19+
description: "IRC for meowing",
20+
category: "General"
21+
})
22+
ircEnabled = true;
23+
1724
@SwitchProperty({
1825
name: "Hide lobby join messages",
1926
description: "Hide join messages that spam your chat in lobby",

features/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Settings from "../config";
2+
import irc from "./irc";
23
import bloodHelper from "./bloodHelper";
34
import hideLobbyJoinMessages from "./hideLobbyJoinMessages";
45
import partyInviteNotification from "./partyInviteNotification";
@@ -27,7 +28,7 @@ import itemHighlight from "./itemHighlight";
2728
import padTickTimer from "./padTickTimer";
2829
import showTerminalClicks from "./showTerminalClicks";
2930

30-
export const features = { bloodHelper, hideLobbyJoinMessages, partyInviteNotification, catSounds, mute, betterPartyFinder, melodyAlert, deathAlert, mimicRelay, sbeBloodFix, p3StartTimer, i4Helper, shadowAssassinAlert, partyFinderNote, partyFinderAutoKick, invincibilityTimer, goldorTickTimer, deathTickTimer, leapHelper, positionalMessages, rightClickAnimation, partyCommands, terminals, wardrobeHelper, itemHighlight, padTickTimer, showTerminalClicks };
31+
export const features = { irc, bloodHelper, hideLobbyJoinMessages, partyInviteNotification, catSounds, mute, betterPartyFinder, melodyAlert, deathAlert, mimicRelay, sbeBloodFix, p3StartTimer, i4Helper, shadowAssassinAlert, partyFinderNote, partyFinderAutoKick, invincibilityTimer, goldorTickTimer, deathTickTimer, leapHelper, positionalMessages, rightClickAnimation, partyCommands, terminals, wardrobeHelper, itemHighlight, padTickTimer, showTerminalClicks };
3132

3233
const featureState = {};
3334
Object.keys(features).forEach(featureName => featureState[featureName] = false);

features/irc/index.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import WebSocket from "../../../WebSocket";
2+
import request from "../../../requestV2";
3+
import Async from "../../../Async";
4+
5+
const UUID = Java.type("java.util.UUID");
6+
const C01PacketChatMessage = Java.type("net.minecraft.network.play.client.C01PacketChatMessage");
7+
const ChatComponentText = Java.type("net.minecraft.util.ChatComponentText");
8+
9+
let enabled = false;
10+
let reconnecting = false;
11+
let ws;
12+
13+
const trigger = register("packetSent", (packet, event) => {
14+
const message = packet.func_149439_c();
15+
if (!message.startsWith("#")) return;
16+
try {
17+
ws.send(message.substring(1).replaceAll(/&([0-9a-fk-o])/g, "§$1"));
18+
} catch (error) {
19+
ChatLib.chat("§8[§bIRC§8] §7Failed to send message.");
20+
}
21+
cancel(event);
22+
}).setFilteredClass(C01PacketChatMessage).unregister();
23+
24+
const unloadTrigger = register("gameUnload", () => {
25+
enabled = false;
26+
ws?.close();
27+
}).unregister();
28+
29+
function reset() {
30+
ws = new WebSocket("wss://sa-irc.p-e.kr/ws");
31+
32+
ws.onOpen = () => {
33+
reconnecting = false;
34+
ChatLib.chat("§8[§bIRC§8] §7Connected.");
35+
auth();
36+
};
37+
38+
ws.onClose = () => {
39+
if (!reconnecting) ChatLib.chat("§8[§bIRC§8] §7Disconnected.");
40+
if (enabled) {
41+
if (reconnecting) Async.schedule(reset, 10000);
42+
else reset();
43+
reconnecting = true;
44+
}
45+
};
46+
47+
ws.onError = () => {
48+
if (enabled) Async.schedule(reset, 10000);
49+
}
50+
51+
ws.onMessage = message => {
52+
Client.getMinecraft().field_71439_g.func_145747_a(new ChatComponentText("§8[§bIRC§8] §f" + message));
53+
};
54+
55+
ws.connect();
56+
}
57+
58+
function auth() {
59+
ChatLib.chat("§8[§bIRC§8] §7Authenticating...");
60+
const token = Client.getMinecraft().func_110432_I().func_148254_d();
61+
const uuid = Player.getUUID().replaceAll("-", "");
62+
const svid = UUID.randomUUID().toString().replaceAll("-", "");
63+
request({
64+
url: "https://sessionserver.mojang.com/session/minecraft/join",
65+
method: "POST",
66+
body: {
67+
accessToken: token,
68+
selectedProfile: uuid,
69+
serverId: svid
70+
},
71+
resolveWithFullResponse: true
72+
}).then(response => {
73+
if (response.statusCode === 204) ws.send("/auth " + Player.getName() + " " + svid);
74+
else ChatLib.chat("§8[§bIRC§8] §7Failed to authenticate.");
75+
}).catch(() => {
76+
ChatLib.chat("§8[§bIRC§8] §7Failed to authenticate.");
77+
});
78+
}
79+
80+
export function enable() {
81+
enabled = true;
82+
trigger.register();
83+
unloadTrigger.register();
84+
reset();
85+
ChatLib.chat("§8[§bIRC§8] §7Connecting...");
86+
}
87+
88+
export function disable() {
89+
enabled = false;
90+
trigger.unregister();
91+
unloadTrigger.unregister();
92+
ws.close();
93+
}
94+
95+
export default { enable, disable };

metadata.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "soshimeeaddons",
33
"description": "F7 on top",
44
"creator": "soshimee",
5-
"version": "2.7.0",
5+
"version": "2.8.0",
66
"entry": "index.js",
7-
"requires": ["PromiseV2", "BloomCore", "fparser", "requestV2", "Vigilance", "PogData", "RenderLib"]
7+
"requires": ["PromiseV2", "BloomCore", "fparser", "requestV2", "Vigilance", "PogData", "RenderLib", "WebSocket", "Async"]
88
}

0 commit comments

Comments
 (0)