Advertisement
based_3d

Untitled

Jun 26th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. 'use strict';
  2. let receiveMail = function (user) {
  3. let myMail = Db("mail").get(user.userid, []);
  4. if (!myMail.length) return false;
  5. myMail.forEach(function(m) {
  6. user.sendTo("[" + getEST(m.date) + " EST] " + m.from + ": " + m.message);
  7. });
  8. Db("mail").set(user.userid, []);
  9. return true;
  10. }
  11.  
  12. let sendMail = function (user, targetuserid, message) {
  13. //count mail
  14. let targetMail = Db("mail").get(targetuserid, []);
  15. //parse patterns
  16. let patternCount = 0
  17. targetMail.forEach(function(m) {
  18. if (Tools.matchText(m.message, message) > 90) patternCount++;
  19. if (patternCount >= 3 && !user.isStaff) {
  20. Monitor.mute(user.userid, 30);
  21. log("monitor", user.name + " was caught for suspected mail spam.");
  22. }
  23. });
  24.  
  25. targetMail.push({
  26. "from": user.name,
  27. "date": Date.now(),
  28. "message": message
  29. });
  30. Db("mail").set(targetuserid, targetMail);
  31.  
  32. user.mailCount++;
  33. setTimeout(function() {
  34. user.mailCount--;
  35. if (user.mailCount < 0) user.mailCount === 0;
  36. }.bind(this), 60000);
  37. }
  38.  
  39. Plugins.mail = {
  40. "receive": receiveMail,
  41. "send": sendMail,
  42. }
  43.  
  44. exports.commands = {
  45. mail: function(target, room, user) {
  46. if (!target) return this.parse("/help mail");
  47. let message = target.split(",").slice(1).join(",");
  48. if (!message || message.length > 250) return this.parse("/help mail");
  49. if(!user.mailCount) user.mailCount = 0;
  50. if (user.mailCount > 5 && !user.isStaff) return false;
  51. try {
  52. sendMail(user, this.targetUser.userid || this.targetUser, message.trim());
  53. }
  54. catch (e) {
  55. user.sendTo("ERROR: unable to send mail.");
  56. }
  57. user.sendTo("Swish, mail has been sent to " + (this.targetUser.name || this.targetUser));
  58. },
  59. checkmail: function(target, room, user) {
  60. let mail = receiveMail(user);
  61. if (!mail) return user.sendTo("You have no mail!");
  62. }
  63. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement