Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.12 KB | None | 0 0
  1. 'use strict';
  2.  
  3. const color = require('../config/color');
  4. if (!global.nightclubs) global.nightclubs = {};
  5. let nightclubs = global.nightclubs;
  6.  
  7. function getColor() {
  8. let color = '#';
  9. for (let i = 0; i < 6; i++) {
  10. color += 'ABCDE'[Math.floor(Math.random() * 5)];
  11. }
  12. return color;
  13. }
  14.  
  15. function colorify(message) {
  16. let total = '';
  17. for (let i = 0; i < message.length; i++) {
  18. if (message[i] === ' ') {
  19. total += ' ';
  20. continue;
  21. }
  22. total += '<span style = "color: ' + getColor() + '">' + message[i] + '</span>';
  23. }
  24. return total;
  25. }
  26.  
  27. function formatHTML(message) {
  28. let escapes = ['&amp;', '&lt;', '&gt;', '&gt;', '&quot;', '&apos;', '&#x2f;'];
  29. if (!message) return '';
  30. let total = '';
  31. for (let i = 0; i < message.length; i++) {
  32. if (message[i] === '&') {
  33. let sub = message.substr(i);
  34. let part = sub.substr(0, sub.indexOf(';') + 1);
  35. if (escapes.indexOf(part) > -1) {
  36. i += part.length - 1;
  37. total += '<span style = "color: ' + getColor() + '">' + part + '</span>';
  38. continue;
  39. }
  40. }
  41. if (message[i] === '<') {
  42. let sub = message.substr(i).match(/<(span|b|a|i|code|s)[^]+<\/(span|b|a|i|code|s)>/);
  43. if (sub) {
  44. if (/<(a|b|i|s)>/.test(sub[0].substr(0, 3))) {
  45. total += sub[0].substr(0, 3) + colorify(sub[0].substr(3, sub[0].length - 7)) + sub[0].substr(sub[0].length - 4);
  46. } else {
  47. total += sub[0];
  48. }
  49. i += sub[0].length - 1;
  50. continue;
  51. }
  52. }
  53. total += '<span style = "color: ' + getColor() + '">' + Chat.escapeHTML(message[i])+ '</span>';
  54. }
  55. return total;
  56. }
  57.  
  58. function formatMessage(message) {
  59. message = message.replace(/\_\_([^ ](?:[^]*?[^ ])?)\_\_(?![^]*?<\/a)/g, '<i>$1</i>') //italics
  60. .replace(/\*\*([^ ](?:[^]*?[^ ])?)\*\*/g, '<b>$1</b>') //bold
  61. .replace(/\~\~([^ ](?:[^]*?[^ ])?)\~\~/g, '<s>$1</s>') //strikethrough
  62. .replace(/\`\`([^ ](?:[^]*?[^ ])?)\`\`/g, '<code>$1</code>') //code
  63. //urls
  64. .replace(/(https?\:\/\/[a-z0-9-.]+(\/([^\s]*[^\s?.,])?)?|[a-z0-9]([a-z0-9-\.]*[a-z0-9])?\.(com|org|net|edu|tk|us)((\/([^\s]*[^\s?.,])?)?|\b))/ig, '<a href="$1" target="_blank">$1</a>')
  65. .replace(/<a href="([a-z]*[^a-z:])/g, '<a href="http://$1')
  66. .replace(/(\bgoogle ?\[([^\]<]+)\])/ig, '<a href="http://www.google.com/search?ie=UTF-8&q=$2" target="_blank">$1</a>')
  67. .replace(/(\bgl ?\[([^\]<]+)\])/ig, '<a href="http://www.google.com/search?ie=UTF-8&btnI&q=$2" target="_blank">$1</a>')
  68. .replace(/(\bwiki ?\[([^\]<]+)\])/ig, '<a href="http://en.wikipedia.org/w/index.php?title=Special:Search&search=$2" target="_blank">$1</a>')
  69. .replace(/\[\[([^< ]([^<`]*?[^< ])?)\]\]/ig, '<a href="http://www.google.com/search?ie=UTF-8&btnI&q=$1" target="_blank">$1</a>')
  70. .replace(/spoiler:([^]+)/i, 'spoiler: <span class = "spoiler" style = "text-shadow: none;">$1</span>');
  71. return formatHTML(message);
  72. }
  73.  
  74. function nightclubify(message) {
  75. let rank = '', rankIndex = (toId(message[0]) ? 0 : 1);
  76. if (rankIndex) rank = message[0];
  77. let user = message.substring(rankIndex, (~message.indexOf('|') ? message.indexOf('|') : message.length));
  78. if (!toId(user)) return '|c:|' + (~~(Date.now() / 1000)) + '|' + message;
  79. message = (~message.indexOf('|') ? message.substring(message.indexOf('|') + 1) : '');
  80. return '|raw|<div style = "font-size: 11pt; margin: -3px; padding: 1px; background: black; color: white; text-shadow: 0px 0px 10px, 0px 0px 10px, 0px 0px 10px;">' +
  81. '<small style = "color: white">' + rank + '</small>' +
  82. '<button name = "parseCommand" value = "/user ' + user + '" style = "outline: none; cursor: pointer; font-size: inherit; text-shadow: inherit; font-family: inherit; background: none; padding: 0px; border: none; display: inline-block; color: ' + color(toId(user)) + ';"><b>' + user + ':</b></button>' +
  83. '<span style = "text-shadow: 0px 0px 10px, 0px 0px 10px;"> ' + formatMessage(Chat.escapeHTML(message)) + '</span></div>';
  84. }
  85.  
  86. Rooms.Room.prototype.add = function (message) {
  87. if (typeof message !== 'string') throw new Error("Deprecated message type");
  88. this.logEntry(message);
  89. if (this.logTimes && message.substr(0, 3) === '|c|') {
  90. if (nightclubs[this.id]) {
  91. message = nightclubify(message.substr(3));
  92. } else {
  93. message = '|c:|' + (~~(Date.now() / 1000)) + '|' + message.substr(3);
  94. }
  95. } else if (nightclubs[this.id]) {
  96. let style = '|raw|<div style = "color: white; text-shadow: 0px 0px 6px, 0px 0px 6px; background: black; padding: 2px; margin: -3px,">';
  97. if (message.match(/^\|html\||^\|raw\|/m) && !message.match(/\|\~\|/m)) {
  98. message = style + message.replace(/^\|html\||^\|raw\|/m, '') + '</div>';
  99. } else if (!message.match(/^\|[a-z]+\|/) && !message.match(/^\|\|/)) {
  100. message = style + message + '</div>';
  101. }
  102. }
  103. this.log.push(message);
  104. return this;
  105. };
  106.  
  107. Users.Connection.prototype.sendTo = function (roomid, data) {
  108. if (roomid && nightclubs[roomid.id]) {
  109. let style = '|html|<div style = "color: white; text-shadow: 0px 0px 6px, 0px 0px 6px; background: black; padding: 2px; margin: -3px">';
  110. if (data.match(/^\|html\||^\|raw\|/m) && !data.match(/\|\~\|/m)) {
  111. if (data.split('\n').length > 1) {
  112. style = '|html|<div style = "border: 5px solid black; margin: -3px">';
  113. let parts = data.split('\n');
  114. if (parts[parts.length - 1].match(/^\|html\||^\|raw\|/m)) parts[parts.length - 1] = style + parts[parts.length - 1].replace(/^\|html\||^\|raw\|/m, '') + '</div>';
  115. data = parts.join('\n');
  116. } else {
  117. data = style + data.replace(/^\|html\||^\|raw\|/m, '') + '</div>';
  118. }
  119. } else if (!data.match(/^\|[a-z]+\|/) && !data.match(/^\|\|/)) {
  120. data = style + data + '</div>';
  121. }
  122. }
  123. if (roomid && roomid.id) roomid = roomid.id;
  124. if (roomid && roomid !== 'lobby') data = '>' + roomid + '\n' + data;
  125. Sockets.socketSend(this.worker, this.socketid, data);
  126. Monitor.countNetworkUse(data.length);
  127. };
  128. let cmds = {
  129. '': function (target, room, user) {
  130. if (nightclubs[room.id]) return this.parse('/nightclub off');
  131. this.parse('/nightclub on');
  132. },
  133. on: function (target, room, user) {
  134. if (!this.can('ban', null, room)) return this.sendReply('You must be ranked @ or higher to toggle this room\'s nightclub mode.');
  135. if (nightclubs[room.id]) return this.sendReply('This room\'s already in nightclub mode!');
  136.  
  137. this.privateModCommand("(" + user.name + " has turned nightclub mode on in this room.)");
  138. nightclubs[room.id] = true;
  139. room.add('<center><b><span style = "font-size: 40px; text-shadow: 0px 0px 5px, 0px 0px 10px, 0px 0px 15px;">' + colorify('LET\'S GET FITZY! NIGHTCLUB MODE: ON!') + '</span></b></center>');
  140. },
  141. off: function (target, room, user) {
  142. if (!this.can('ban', null, room)) return this.sendReply('You must be ranked % or higher to toggle this room\'s nightclub mode.');
  143. if (!nightclubs[room.id]) return this.sendReply('This room isn\'t in nightclub mode yet...');
  144.  
  145. this.privateModCommand("(" + user.name + " has turned nightclub mode off in this room.)");
  146. room.add('<center><b><span style = "font-size: 40px; text-shadow: 0px 0px 5px, 0px 0px 10px, 0px 0px 15px;">' + colorify('Sizzle down now... Nightclub mode: OFF!') + '</span></b></center>');
  147. delete nightclubs[room.id];
  148. },
  149. };
  150. exports.commands = {
  151. nc: 'nightclub',
  152. nightclub: cmds,
  153. dayclub: cmds.off,
  154. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement