Advertisement
penguinpal

chat parrot potato log test

Jun 10th, 2017
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function pad(n, len) {
  2.     n = String(n);
  3.     if (n.length < len) {
  4.         n = new Array(len - n.length + 1).join("0") + n;
  5.     }
  6.     return n;
  7. }
  8. function datify(timestamp, isEstimation) {
  9.     var d = new Date(timestamp),
  10.         c = isEstimation ? "~" : ":";
  11.     return "[" + d.getUTCFullYear() + "-" + pad(d.getUTCMonth() + 1, 2) + "-" + pad(d.getUTCDate() + 1, 2) + " " + pad(d.getUTCHours(), 2) + c + pad(d.getUTCMinutes(), 2) + c + pad(d.getUTCSeconds(), 2) + "]";
  12. }
  13. var logModels = mainRoom.viewDiscussion.model.chats.models;
  14. logModels.map(function(a, i) {
  15.     var b = a.attributes,
  16.         d,
  17.         isMsg = b.name.length > 0;
  18.     if (!isMsg) {
  19.         // since we cannot get the timestamp of an alredy-received inline alert, we can still go back to the previous message and get its timestamp (if any)
  20.         for (var j = i - 1; j >= 0; j--) {
  21.             if (logModels[j].attributes.name.length > 0) {
  22.                 d = datify(logModels[j].attributes.timeStamp, true);
  23.                 break;
  24.             }
  25.             if (j === 0) {
  26.                 // reached first message without finding any timestamp- no way of knowing the original timestamp
  27.                 d = "[????-??-?? ??:??:??]";
  28.             }
  29.         }
  30.     } else {
  31.         d = datify(b.timeStamp);
  32.     }
  33.     new Date(b.timeStamp);
  34.     return (
  35.         (d + " ") +
  36.         (isMsg ? "&lt;" + b.name + "&gt; " : "-!- ") +
  37.         b.text
  38.     );
  39. }).join("\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement