Advertisement
Guest User

Untitled

a guest
May 29th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. function similar_text(first, second, percent) {
  2. if (first === null || second === null || typeof first === 'undefined' || typeof second === 'undefined') {
  3. return 0;
  4. }
  5.  
  6. first += '';
  7. second += '';
  8.  
  9. var pos1 = 0,
  10. pos2 = 0,
  11. max = 0,
  12. firstLength = first.length,
  13. secondLength = second.length,
  14. p, q, l, sum;
  15.  
  16. max = 0;
  17.  
  18. for (p = 0; p < firstLength; p++) {
  19. for (q = 0; q < secondLength; q++) {
  20. for (l = 0;
  21. (p + l < firstLength) && (q + l < secondLength) && (first.charAt(p + l) === second.charAt(q + l)); l++)
  22. ;
  23. if (l > max) {
  24. max = l;
  25. pos1 = p;
  26. pos2 = q;
  27. }
  28. }
  29. }
  30.  
  31. sum = max;
  32.  
  33. if (sum) {
  34. if (pos1 && pos2) {
  35. sum += this.similar_text(first.substr(0, pos1), second.substr(0, pos2));
  36. }
  37.  
  38. if ((pos1 + max < firstLength) && (pos2 + max < secondLength)) {
  39. sum += this.similar_text(first.substr(pos1 + max, firstLength - pos1 - max), second.substr(pos2 + max,
  40. secondLength - pos2 - max));
  41. }
  42. }
  43.  
  44. if (!percent) {
  45. return sum;
  46. } else {
  47. return (sum * 200) / (firstLength + secondLength);
  48. }
  49. }
  50. MPP.client.on("a", function(msg) {
  51.  
  52. function sendChat(msg) {
  53. setTimeout(function() {
  54. MPP.chat.send(msg);
  55. }, 1500);
  56. }
  57.  
  58. function getUser(target) {
  59. for (var id in MPP.client.ppl) {
  60. if (!MPP.client.ppl.hasOwnProperty(id)) continue;
  61. var part = MPP.client.ppl[id];
  62. if (similar_text(part.name.toLowerCase(), target) >= 7) {
  63. return part;
  64. break;
  65. } else if (part.name.toLowerCase().indexOf(target) !== -1) {
  66. return part;
  67. break;
  68. }
  69. }
  70. }
  71. var args = msg.a.split(" ");
  72. var cmd = args[0].toLowerCase();
  73. args = args.slice(1);
  74. var argcat = function(start, end) {
  75. args = message.split(" ");
  76. args = args.slice(1);
  77. var parts = args.slice(start || 0, end || undefined);
  78. var result = "";
  79. for (var i = 0; i < parts.length; i++) {
  80. result += parts[i];
  81. if (i + 1 < parts.length) {
  82. result += " ";
  83. }
  84. }
  85. return result;
  86. };
  87.  
  88. if (cmd == "/help") {
  89. sendChat("Commands: /find, /command");
  90. if (msg.p._id == MPP.client.getOwnParticipant()._id) {
  91. sendChat("Op commands: /rename")
  92. }
  93. }
  94.  
  95. if (cmd === "/find") {
  96. var target = msg.a.substring(cmd.length).trim();
  97. var part = getUser(target.toLowerCase());
  98. if (target == "") {
  99. sendChat("Usage /find [person]");
  100. return;
  101. }
  102. if (part) {
  103. if (part.name == msg.p.name) {
  104. sendChat("You found yourself");
  105. return;
  106. }
  107. sendChat("Found: " + part.name);
  108. } else {
  109. sendChat("User not found");
  110. }
  111. }
  112. if (cmd == "/rename") {
  113. if (msg.p._id == MPP.client.getOwnParticipant()._id) {
  114. MPP.client.sendArray([{
  115. m: "userset",
  116. set: {
  117. name: msg.a.substring(cmd.length).trim()
  118. }
  119. }]);
  120. }
  121. }
  122.  
  123. if (cmd == "/command") {
  124. sendChat("stuff");
  125. }
  126. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement