mirror of
https://github.com/Threnklyn/MinecraftChat.git
synced 2026-05-18 20:33:28 +02:00
Chat formatting
This commit is contained in:
@@ -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 = '';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@@ -6,5 +6,6 @@ exports.register = function(app) {
|
||||
|
||||
app.controller('connectController', require('./connectController'));
|
||||
app.controller('bufferController', require('./bufferController'));
|
||||
app.controller('chatController', require('./chatController'));
|
||||
|
||||
};
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
module.exports = function(socket) {
|
||||
|
||||
socket.on('buffer:info', function(string) {
|
||||
$('#buffer').append('<span style="color:#2976A9;">> ' + 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;">> ' + 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;">> ' + error + '</span><br>')
|
||||
$('#buffer').append('<span style="color:#D62D18;">[i] ' + error + '</span><br>')
|
||||
$('#buffer').scrollTop($('#buffer').prop('scrollHeight'));
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
@@ -0,0 +1,9 @@
|
||||
module.exports = function(socket) {
|
||||
|
||||
socket.on('chat', function(data) {
|
||||
if (socket.mcbot) {
|
||||
socket.mcbot.chat(data.message);
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
@@ -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);
|
||||
|
||||
});
|
||||
|
||||
|
||||
+18
-1
@@ -59,4 +59,21 @@ 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,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>
|
||||
|
||||
Reference in New Issue
Block a user