Chat formatting

This commit is contained in:
AlexKvazos
2015-04-28 10:49:49 -05:00
parent 16da80bf5a
commit 542ae1f549
9 changed files with 85 additions and 7 deletions
+20
View File
@@ -0,0 +1,20 @@
/**
* Connect Controller
*/
module.exports = function($scope, socket) {
$scope.chat = '';
$scope.send = function() {
if ($scope.chat.trim().length > 0) {
socket.emit('chat', {
message: $scope.chat.trim()
});
$scope.chat = '';
}
}
};
+1
View File
@@ -6,5 +6,6 @@ exports.register = function(app) {
app.controller('connectController', require('./connectController'));
app.controller('bufferController', require('./bufferController'));
app.controller('chatController', require('./chatController'));
};
+3 -3
View File
@@ -5,17 +5,17 @@
module.exports = function(socket) {
socket.on('buffer:info', function(string) {
$('#buffer').append('<span style="color:#2976A9;">&gt; ' + string + '</span><br>\n');
$('#buffer').append('<span style="color:#2976A9;">[i] ' + string + '</span><br>\n');
$('#buffer').scrollTop($('#buffer').prop('scrollHeight'));
});
socket.on('buffer:success', function(string) {
$('#buffer').append('<span style="color:#4AA937;">&gt; ' + string + '</span><br>\n');
$('#buffer').append('<span style="color:#4AA937;">[i] ' + string + '</span><br>\n');
$('#buffer').scrollTop($('#buffer').prop('scrollHeight'));
});
socket.on('buffer:error', function(string) {
$('#buffer').append('<span style="color:#D62D18;">&gt; ' + error + '</span><br>')
$('#buffer').append('<span style="color:#D62D18;">[i] ' + error + '</span><br>')
$('#buffer').scrollTop($('#buffer').prop('scrollHeight'));
});
+26 -2
View File
@@ -1,3 +1,28 @@
function stringToCode(string) {
var dictionary = {
'black': 0,
'dark_blue': 1,
'dark_green': 2,
'dark_aqua': 3,
'dark_red': 4,
'dark_purple': 5,
'gold': 6,
'gray': 7,
'dark_gray': 8,
'indigo': 9,
'green': 'a',
'aqua': 'b',
'red': 'c',
'light_purple': 'd',
'yellow': 'e',
'white': 'f'
};
return dictionary[string] || string;
}
module.exports = function(socket) {
var bot = socket.mcbot;
@@ -28,7 +53,7 @@ module.exports = function(socket) {
if (text) { // if text is available
text = text.replace(/§k/ig, ''); // remove crazy format
text = text.replace(/§l/ig, ''); // remove bold format
buffer += text; // add the text to the buffer
buffer += '§' + stringToCode(data.color) + text; // add the text to the buffer
}
});
@@ -49,7 +74,6 @@ module.exports = function(socket) {
// send line back to the client
socket.emit('bot:message', buffer);
console.log(buffer);
});
+6
View File
@@ -36,3 +36,9 @@ app.use('/', express.static(path.join(__dirname, '../../public')));
server.listen(3000, function() {
console.log('\033c> Server running on port 3000\n');
});
// handle exceptions
process.on('uncaughtException', function(ex) {
console.error(ex);
});
+9
View File
@@ -0,0 +1,9 @@
module.exports = function(socket) {
socket.on('chat', function(data) {
if (socket.mcbot) {
socket.mcbot.chat(data.message);
}
});
};
+1
View File
@@ -8,6 +8,7 @@ module.exports = function(io) {
// bind all events to the socket
require('./events/connection')(socket);
require('./events/disconnection')(socket);
require('./events/chat')(socket);
});
+17
View File
@@ -60,3 +60,20 @@ body {
#send input:focus {
outline: none;
}
.color-a { color: #50FF38; }
.color-b { color: #5BFFFF; }
.color-c { color: #EA3A3F; }
.color-d { color: #EF1DFF; }
.color-e { color: #FAFF34; }
.color-f { color: #111111; }
.color-0 { color: #000000; }
.color-1 { color: #19009C; }
.color-2 { color: #30A000; }
.color-3 { color: #379C9A; }
.color-4 { color: #9A0000; }
.color-5 { color: #99009C; }
.color-6 { color: #EF9B00; }
.color-7 { color: #9A9A9A; }
.color-8 { color: #43443E; }
.color-9 { color: #412BFF; }
+1 -1
View File
@@ -1,6 +1,6 @@
<div id="buffer" ng-controller="bufferController"></div>
<form>
<form ng-submit="send()" ng-controller="chatController">
<div id="chat">
<input type="text" ng-model="chat" placeholder="Type to chat...">
</div>