Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // === Single-Line Chat Display (with full clear + username fix + double-line border) ===
- // --- Constants ---
- const CHAT_START_X = cursor.x;
- const CHAT_START_Y = cursor.y;
- const CHAT_LINE_LENGTH = 180;
- const BORDER_TOP_Y = CHAT_START_Y - 1;
- const BORDER_MID_Y = CHAT_START_Y;
- const BORDER_BOTTOM_Y = CHAT_START_Y + 1;
- const INNER_WIDTH = CHAT_LINE_LENGTH;
- const BLANK_LINE = " ".repeat(INNER_WIDTH);
- let lastDrawn = "";
- let scheduledFrame = false;
- let nextText = "";
- // Cursor helper
- function setCursor(x, y) {
- cursor.x = x;
- cursor.y = y;
- }
- // Write string via writeChar()
- function writeString(str) {
- for (let i = 0; i < str.length; i++) {
- writeChar(str[i], 1); // keep attribute
- }
- }
- // === Draw static DOUBLE-LINE border ===
- function drawBorder() {
- // Top: ╔══════════╗
- setCursor(CHAT_START_X, BORDER_TOP_Y);
- writeString("╔" + "═".repeat(INNER_WIDTH) + "╗");
- // Middle empty line: ║ ║
- setCursor(CHAT_START_X, BORDER_MID_Y);
- writeString("║" + " ".repeat(INNER_WIDTH) + "║");
- // Bottom: ╚══════════╝
- setCursor(CHAT_START_X, BORDER_BOTTOM_Y);
- writeString("╚" + "═".repeat(INNER_WIDTH) + "╝");
- }
- // Clear inside the double-line border
- function clearInner() {
- setCursor(CHAT_START_X + 1, BORDER_MID_Y);
- writeString(BLANK_LINE);
- }
- // Draw updated chat text
- function drawSingleLine() {
- const newText = nextText.slice(0, INNER_WIDTH);
- clearInner();
- setCursor(CHAT_START_X + 1, BORDER_MID_Y);
- writeString(newText);
- lastDrawn = newText;
- scheduledFrame = false;
- }
- // Schedule a single-frame redraw
- function scheduleDraw(text) {
- nextText = text;
- if (!scheduledFrame) {
- scheduledFrame = true;
- requestAnimationFrame(drawSingleLine);
- }
- }
- // === Chat listener ===
- w.on("msg", (data) => {
- const nick =
- data?.nick?.trim() ||
- data?.user?.name?.trim() ||
- data?.username?.trim() ||
- "Unknown";
- const line = `${nick}: ${data.msg}`;
- scheduleDraw(line);
- // Original save logic
- if (data.msg.startsWith("save ") && nick === "CalculatorBot") {
- save = Number(data.msg.substring(5)) - b;
- }
- });
- // Draw border once at startup
- drawBorder();
- // Startup message
Advertisement
Comments
-
- If you don't want to have the chatbox always spawn at your cursor's position,
- replace cursor.x and cursor.y with regular coords in the following line:
- // --- Constants ---
- const CHAT_START_X = cursor.x;
- const CHAT_START_Y = cursor.y;
Add Comment
Please, Sign In to add comment