-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIRC.php
More file actions
197 lines (164 loc) · 4.74 KB
/
IRC.php
File metadata and controls
197 lines (164 loc) · 4.74 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
// ---------------------------------------------------------------- //
// Made by: ErringPaladin10 (ErringPaladin10@VTILServer.com)
// Creation Date: 09/19/2025
// Last Updated: 09/20/2025
// ---------------------------------------------------------------- //
$apiKey = "F0BA8E63-1CC5-4709-8D30-C2089B5A46E9"; // The key for the main endpoint
$sessionId = uniqid("IRC.", true); // Unique per visitor (new session each load)
$defaultChannel = "Place2";
?>
<!DOCTYPE html>
<html lang="en">
<head data-session-id="<?php echo $sessionId?>">
<meta charset="UTF-8">
<title>Void Script Builder IRC</title>
<style>
body {
font-family: Arial, sans-serif;
background: #f7f7f7;
margin: 0;
padding: 0;
}
#chat-container {
display: flex;
flex-direction: column;
height: 100vh;
margin: auto;
border: 1px solid #ccc;
background: white;
}
#messages {
flex: 1;
overflow-y: auto;
padding: 10px;
}
.msg {
padding: 6px 8px;
margin: 4px 0;
border-radius: 6px;
background: #f1f1f1;
}
.msg .icon {
font-weight: bold;
margin-right: 6px;
}
.msg .user {
font-weight: bold;
color: #0074D9;
}
#input-bar {
display: flex;
border-top: 1px solid #ccc;
padding: 8px;
}
#input-bar input[type=text] {
flex: 1;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}
#input-bar button {
margin-left: 8px;
padding: 8px 14px;
border: none;
border-radius: 4px;
background: #0074D9;
color: white;
cursor: pointer;
}
#input-bar button:hover {
background: #005fa3;
}
#channel-select {
margin: 8px;
}
</style>
</head>
<body>
<div id="chat-container">
<div id="channel-select">
Channel:
<select id="channel">
<option value="Place1" selected>Place1</option>
<option value="Place2" selected>Place2</option>
</select>
</div>
<div id="messages"></div>
<div id="input-bar">
<input type="text" id="msgInput" placeholder="Type a message...">
<button id="sendBtn">Send</button>
</div>
</div>
<script>
const apiUrl = "PHP.php"; // the endpoint
const apiKey = "<?php echo $apiKey; ?>";
const sessionId = "<?php echo $sessionId; ?>";
let channelId = "<?php echo $defaultChannel; ?>";
let lastMessageCount = 0;
async function fetchMessages() {
try {
let form = new FormData();
form.append("ApiKey", apiKey);
form.append("SessionId", sessionId);
form.append("ChannelId", channelId);
form.append("Messages", ""); // No new messages, just fetch!
form.append("RequestEmojis", "true");
let res = await fetch(apiUrl, { method: "POST", body: form });
let data = await res.json();
if (data.messages) {
renderMessages(data.messages);
}
} catch (err) {
console.error("Fetch error:", err);
}
}
function renderMessages(messages) {
const box = document.getElementById("messages");
box.innerHTML = "";
messages.forEach(m => {
const div = document.createElement("div");
div.className = "msg";
div.innerHTML = `<span class="icon">${m.icon}</span>
<span class="user">${m.speaker}:</span>
<span class="text">${escapeHtml(m.message)}</span>`;
box.appendChild(div);
});
box.scrollTop = box.scrollHeight;
}
function escapeHtml(str) {
return str.replace(/[&<>"']/g, c =>
({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])
);
}
async function sendMessage() {
const input = document.getElementById("msgInput");
let msg = input.value.trim();
if (!msg) return;
input.value = "";
let form = new FormData();
form.append("ApiKey", apiKey);
form.append("SessionId", sessionId);
form.append("ChannelId", channelId);
form.append("Messages", msg);
form.append("RequestEmojis", "true");
let res = await fetch(apiUrl, { method: "POST", body: form });
let data = await res.json();
if (data.messages) {
renderMessages(data.messages);
}
}
document.getElementById("sendBtn").addEventListener("click", sendMessage);
document.getElementById("msgInput").addEventListener("keypress", e => {
if (e.key === "Enter") sendMessage();
});
document.getElementById("channel").addEventListener("change", e => {
channelId = e.target.value;
fetchMessages();
});
// Poll messages every 2s
setInterval(fetchMessages, 2000);
fetchMessages();
</script>
</body>
</html>