Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function similar_text(first, second, percent) {
- if (first === null || second === null || typeof first === 'undefined' || typeof second === 'undefined') {
- return 0;
- }
- first += '';
- second += '';
- var pos1 = 0,
- pos2 = 0,
- max = 0,
- firstLength = first.length,
- secondLength = second.length,
- p, q, l, sum;
- max = 0;
- for (p = 0; p < firstLength; p++) {
- for (q = 0; q < secondLength; q++) {
- for (l = 0;
- (p + l < firstLength) && (q + l < secondLength) && (first.charAt(p + l) === second.charAt(q + l)); l++)
- ;
- if (l > max) {
- max = l;
- pos1 = p;
- pos2 = q;
- }
- }
- }
- sum = max;
- if (sum) {
- if (pos1 && pos2) {
- sum += this.similar_text(first.substr(0, pos1), second.substr(0, pos2));
- }
- if ((pos1 + max < firstLength) && (pos2 + max < secondLength)) {
- sum += this.similar_text(first.substr(pos1 + max, firstLength - pos1 - max), second.substr(pos2 + max,
- secondLength - pos2 - max));
- }
- }
- if (!percent) {
- return sum;
- } else {
- return (sum * 200) / (firstLength + secondLength);
- }
- }
- MPP.client.on("a", function(msg) {
- function sendChat(msg) {
- setTimeout(function() {
- MPP.chat.send(msg);
- }, 1500);
- }
- function getUser(target) {
- for (var id in MPP.client.ppl) {
- if (!MPP.client.ppl.hasOwnProperty(id)) continue;
- var part = MPP.client.ppl[id];
- if (similar_text(part.name.toLowerCase(), target) >= 7) {
- return part;
- break;
- } else if (part.name.toLowerCase().indexOf(target) !== -1) {
- return part;
- break;
- }
- }
- }
- var args = msg.a.split(" ");
- var cmd = args[0].toLowerCase();
- args = args.slice(1);
- var argcat = function(start, end) {
- args = message.split(" ");
- args = args.slice(1);
- var parts = args.slice(start || 0, end || undefined);
- var result = "";
- for (var i = 0; i < parts.length; i++) {
- result += parts[i];
- if (i + 1 < parts.length) {
- result += " ";
- }
- }
- return result;
- };
- if (cmd == "/help") {
- sendChat("Commands: /find, /command");
- if (msg.p._id == MPP.client.getOwnParticipant()._id) {
- sendChat("Op commands: /rename")
- }
- }
- if (cmd === "/find") {
- var target = msg.a.substring(cmd.length).trim();
- var part = getUser(target.toLowerCase());
- if (target == "") {
- sendChat("Usage /find [person]");
- return;
- }
- if (part) {
- if (part.name == msg.p.name) {
- sendChat("You found yourself");
- return;
- }
- sendChat("Found: " + part.name);
- } else {
- sendChat("User not found");
- }
- }
- if (cmd == "/rename") {
- if (msg.p._id == MPP.client.getOwnParticipant()._id) {
- MPP.client.sendArray([{
- m: "userset",
- set: {
- name: msg.a.substring(cmd.length).trim()
- }
- }]);
- }
- }
- if (cmd == "/command") {
- sendChat("stuff");
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement