From bc35ef577652ca9c044b035013626c27fa8fc173 Mon Sep 17 00:00:00 2001 From: Fluffy Jenkins Date: Wed, 15 Jan 2020 21:17:17 +0000 Subject: [PATCH 1/4] Add goto json support (defaults to darlings goto), gotos (gotosudo) which bypasses the popup window and added history to the main chatbar so you can press up/down on there --- scripts/communityModules/chat/FloofChat.js | 72 +++++++++++++++++---- scripts/communityModules/chat/FloofChat.qml | 32 ++++++++- 2 files changed, 88 insertions(+), 16 deletions(-) diff --git a/scripts/communityModules/chat/FloofChat.js b/scripts/communityModules/chat/FloofChat.js index 438adb662d..d4accdd736 100644 --- a/scripts/communityModules/chat/FloofChat.js +++ b/scripts/communityModules/chat/FloofChat.js @@ -28,13 +28,18 @@ var appUUID = Uuid.generate(); var chatBar; var chatHistory; +var chatBarHistoryLimit = Settings.getValue(settingsRoot + "/chatBarHistoryLimit", 256); +var chatHistoryLimit = Settings.getValue(settingsRoot + "/chatHistoryLimit", 500); +var chatBarHistory = Settings.getValue(settingsRoot + "/chatBarHistory", ["Meow :3"]); var historyLog = []; - var visible = false; var historyVisible = false; var settingsRoot = "FloofChat"; +var darlingGotoUrl = "http://metaverse.darlingvr.club:8081/goto.json"; +var gotoJSONUrl = Settings.getValue(settingsRoot + "/gotoJSONUrl", darlingGotoUrl); + var muted = Settings.getValue(settingsRoot + "/muted", {"Local": false, "Domain": false, "Grid": false}); var ws; @@ -69,7 +74,7 @@ function init() { button.clicked.connect(toggleChatHistory); chatBar.fromQml.connect(fromQml); - chatBar.sendToQml(JSON.stringify({visible: false})); + chatBar.sendToQml(JSON.stringify({visible: false, history: chatBarHistory})); Controller.keyPressEvent.connect(keyPressEvent); Messages.messageReceived.connect(messageReceived); @@ -172,42 +177,72 @@ function chatColour(tab) { var chatBarChannel = "Local"; +function go2(msg) { + var dest = false; + var domainsList = Script.require("http://metaverse.darlingvr.club:8081/goto.json"); + domainsList.forEach(function (domain) { + if (domain["Domain Name"].toLowerCase().indexOf(msg.toLowerCase()) !== -1) { + dest = {"name": domain["Domain Name"], "url": domain["Visit"]}; + return; + } + }); + return dest; +} -function gotoConfirm(url) { - var result = Window.confirm("Do you want to go to '" + ((url.indexOf("/") !== -1) ? url.split("/")[2] : url) + "'?"); +function gotoConfirm(url, name, confirm) { + confirm = confirm === undefined ? true : confirm; + name = name === undefined ? url : name; + var result = true; + if (confirm) { + result = Window.confirm("Do you want to go to '" + ((name.indexOf("/") !== -1) ? url.split("/")[2] : name) + "'?"); + } if (result) { location = url; } } function processChat(cmd) { + + function commandResult() { + msg = ""; + setVisible(false); + } + var msg = cmd.message; if (msg.indexOf("/") === 0) { msg = msg.substring(1); var commandList = msg.split(" "); + var tempList = commandList.join(";'#[]").split(";'#[]"); + tempList.shift(); + var restOfMsg = tempList.join(" "); + + msg = "/" + msg; var cmd1 = commandList[0].toLowerCase(); if (cmd1 === "l") { chatBarChannel = "Local"; - msg = ""; + commandResult(); } if (cmd1 === "d") { chatBarChannel = "Domain"; - msg = ""; + commandResult(); } if (cmd1 === "g") { chatBarChannel = "Grid"; - msg = ""; + commandResult(); } - if (cmd1 === "goto") { - gotoConfirm(commandList[1]); - msg = ""; + if (cmd1 === "goto" || cmd1 === "gotos") { + var result = go2(restOfMsg); + if (result) { + gotoConfirm(result.url, result.name, (cmd1 === "goto")); + } else { + gotoConfirm(commandList[1], undefined, (cmd1 === "goto")); + } + commandResult(); } if (cmd1 === "me") { - var tempList = commandList; - tempList.shift(); - msg = cmd.avatarName + " " + tempList.join(" "); + msg = cmd.avatarName + " " + restOfMsg; cmd.avatarName = ""; } } @@ -415,12 +450,20 @@ function time() { function addToLog(msg, dp, colour, tab) { historyLog.push([time(), msg, dp, colour, tab]); chatHistory.emitScriptEvent(JSON.stringify({type: "MSG", data: [[time(), msg, dp, colour, tab]]})); - while (historyLog.length > 500) { + while (historyLog.length > chatHistoryLimit) { historyLog.shift(); } Settings.setValue(settingsRoot + "/HistoryLog", JSON.stringify(historyLog)) } +function addToChatBarHistory(msg) { + chatBarHistory.unshift(cmd.message); + while (chatBarHistory.length > chatBarHistoryLimit) { + chatBarHistory.pop(); + } + Settings.setValue(settingsRoot + "/chatBarHistory", chatBarHistory); +} + function fromQml(message) { var cmd = {FAILED: true}; try { @@ -431,6 +474,7 @@ function fromQml(message) { if (!cmd.FAILED) { if (cmd.type === "MSG") { if (cmd.message !== "") { + addToChatBarHistory(cmd.message); if (cmd.event.modifiers === CONTROL_KEY) { cmd.avatarName = MyAvatar.displayName; cmd = processChat(cmd); diff --git a/scripts/communityModules/chat/FloofChat.qml b/scripts/communityModules/chat/FloofChat.qml index ef72b4886f..cfc0b43abc 100644 --- a/scripts/communityModules/chat/FloofChat.qml +++ b/scripts/communityModules/chat/FloofChat.qml @@ -11,6 +11,8 @@ Rectangle { Binding { target: window; property: 'shown'; value: false; when: Boolean(window) } Component.onDestruction: thing && thing.destroy() + property var hist : -1; + property var history : []; signal sendToScript(var message); color: "#00000000" @@ -40,6 +42,9 @@ Rectangle { thing.visible = false; textArea.focus = false; } + if(data.history){ + history = data.history; + } } } @@ -64,13 +69,36 @@ Rectangle { clip: false font.pointSize: 20 - function _onEnterPressed(event) - { + function _onEnterPressed(event){ sendMessage(JSON.stringify({type:"MSG",message:text,event:event})); + history.unshift(text); text = ""; + hist = -1; } + + function upPressed(event){ + hist++; + if(hist > history.length-1){ + hist = history.length-1; + } + text = history[hist]; + } + function downPressed(event){ + hist--; + if(hist<-1){ + hist = -1; + } + if(hist===-1){ + text = ""; + } else{ + text = history[hist]; + } + } + Keys.onReturnPressed: { _onEnterPressed(event) } Keys.onEnterPressed: { _onEnterPressed(event) } + Keys.onUpPressed: { upPressed(event) } + Keys.onDownPressed: { downPressed(event) } } MouseArea { From 81f8c5bab893a58cc16e5c7f4be6704591886f27 Mon Sep 17 00:00:00 2001 From: Fluffy Jenkins Date: Wed, 15 Jan 2020 21:20:23 +0000 Subject: [PATCH 2/4] fixed json support if invalid json --- scripts/communityModules/chat/FloofChat.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/communityModules/chat/FloofChat.js b/scripts/communityModules/chat/FloofChat.js index d4accdd736..304ad728d7 100644 --- a/scripts/communityModules/chat/FloofChat.js +++ b/scripts/communityModules/chat/FloofChat.js @@ -179,11 +179,16 @@ var chatBarChannel = "Local"; function go2(msg) { var dest = false; - var domainsList = Script.require("http://metaverse.darlingvr.club:8081/goto.json"); + var domainsList = []; + try { + domainsList = Script.require("http://metaverse.darlingvr.club:8081/goto.json"); + } catch (e) { + // + } domainsList.forEach(function (domain) { - if (domain["Domain Name"].toLowerCase().indexOf(msg.toLowerCase()) !== -1) { + if (domain["Domain Name"].toLowerCase().indexOf(msg.toLowerCase()) !== -1 && !dest) { dest = {"name": domain["Domain Name"], "url": domain["Visit"]}; - return; + } }); return dest; From 1e4716530309a30dfde54703765928234ec799d2 Mon Sep 17 00:00:00 2001 From: Fluffy Jenkins Date: Wed, 15 Jan 2020 21:38:25 +0000 Subject: [PATCH 3/4] fixed minor bug, whoops --- scripts/communityModules/chat/FloofChat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/communityModules/chat/FloofChat.js b/scripts/communityModules/chat/FloofChat.js index 304ad728d7..7859d95090 100644 --- a/scripts/communityModules/chat/FloofChat.js +++ b/scripts/communityModules/chat/FloofChat.js @@ -462,7 +462,7 @@ function addToLog(msg, dp, colour, tab) { } function addToChatBarHistory(msg) { - chatBarHistory.unshift(cmd.message); + chatBarHistory.unshift(msg); while (chatBarHistory.length > chatBarHistoryLimit) { chatBarHistory.pop(); } From 6bed25ee27c8fb5a111df5a5804ef3bcf48bffbf Mon Sep 17 00:00:00 2001 From: Fluffy Jenkins Date: Thu, 16 Jan 2020 19:44:34 +0000 Subject: [PATCH 4/4] Formatting (bloody ide not doing qml) --- scripts/communityModules/chat/FloofChat.js | 3 +- scripts/communityModules/chat/FloofChat.qml | 32 ++++++++++----------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/scripts/communityModules/chat/FloofChat.js b/scripts/communityModules/chat/FloofChat.js index 7859d95090..2e9a08f241 100644 --- a/scripts/communityModules/chat/FloofChat.js +++ b/scripts/communityModules/chat/FloofChat.js @@ -188,7 +188,6 @@ function go2(msg) { domainsList.forEach(function (domain) { if (domain["Domain Name"].toLowerCase().indexOf(msg.toLowerCase()) !== -1 && !dest) { dest = {"name": domain["Domain Name"], "url": domain["Visit"]}; - } }); return dest; @@ -217,7 +216,7 @@ function processChat(cmd) { if (msg.indexOf("/") === 0) { msg = msg.substring(1); var commandList = msg.split(" "); - var tempList = commandList.join(";'#[]").split(";'#[]"); + var tempList = commandList.concat(); tempList.shift(); var restOfMsg = tempList.join(" "); diff --git a/scripts/communityModules/chat/FloofChat.qml b/scripts/communityModules/chat/FloofChat.qml index cfc0b43abc..8d96bf7e42 100644 --- a/scripts/communityModules/chat/FloofChat.qml +++ b/scripts/communityModules/chat/FloofChat.qml @@ -30,19 +30,19 @@ Rectangle { } catch(e){ // } - if(!data.failed){ - if(data.cmd){ + if (!data.failed) { + if (data.cmd) { JSConsole.executeCommand(data.msg); } console.log(data.visible); - if(data.visible){ + if (data.visible) { thing.visible = true; textArea.focus = true; - } else if(!data.visible){ + } else if (!data.visible) { thing.visible = false; textArea.focus = false; } - if(data.history){ + if (data.history) { history = data.history; } } @@ -69,36 +69,36 @@ Rectangle { clip: false font.pointSize: 20 - function _onEnterPressed(event){ - sendMessage(JSON.stringify({type:"MSG",message:text,event:event})); + function _onEnterPressed(event) { + sendMessage(JSON.stringify({type:"MSG", message:text, event:event})); history.unshift(text); text = ""; hist = -1; } - function upPressed(event){ + function upPressed(event) { hist++; - if(hist > history.length-1){ + if (hist > history.length-1) { hist = history.length-1; } text = history[hist]; } - function downPressed(event){ + function downPressed(event) { hist--; - if(hist<-1){ + if (hist < -1) { hist = -1; } - if(hist===-1){ + if (hist === -1) { text = ""; } else{ text = history[hist]; } } - Keys.onReturnPressed: { _onEnterPressed(event) } - Keys.onEnterPressed: { _onEnterPressed(event) } - Keys.onUpPressed: { upPressed(event) } - Keys.onDownPressed: { downPressed(event) } + Keys.onReturnPressed: { _onEnterPressed(event); } + Keys.onEnterPressed: { _onEnterPressed(event); } + Keys.onUpPressed: { upPressed(event); } + Keys.onDownPressed: { downPressed(event); } } MouseArea {