Advertisement
XZTablets

Untitled

Jan 27th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. this.on("a", msg => {
  2.  
  3. // Showing chat in console
  4. console.log("> " + msg.p.name + " in " + self.proxy.client.channel._id + ": ");
  5. console.log(msg.a);
  6. console.log("");
  7.  
  8. // Chat buffer
  9. if(msg.p._id == self.proxy.client.getOwnParticipant()._id){
  10. let found = false;
  11. for(let i=0; i<self.proxy.outbox.length; i++){
  12. if(self.proxy.outbox[i].message.replace(/[^\x00-\x7F\\]+| /gm, "").includes(msg.a.replace(/[^\x00-\x7F]+| /gm, ""))){
  13. self.proxy.outbox.splice(i, 1);
  14. found = true;
  15. break;
  16. }
  17. }
  18. if(!found) self.proxy.outbox = []; // Fixing spamming message
  19. else return; // The bot can't toggle commands
  20. }
  21.  
  22. // Chat buffer checking loop
  23. setInterval(() => {
  24. for(let i=0; i<self.proxy.outbox.length; i++){
  25. if(Date.now() - self.proxy.outbox[i].time >= 500){
  26. let message = self.proxy.outbox[i].message;
  27. self.proxy.outbox.splice(i, 1);
  28. self.say(message);
  29. }else if(self.proxy.outbox[i].message.length == 0){
  30. self.proxy.outbox.splice(i, 1);
  31. }
  32. }
  33. }, 500);
  34.  
  35. say(string){
  36. if(typeof string == "string"){
  37. if(string.length > 512){
  38. let self = this;
  39. let messages = [];
  40. string.match(/.{0,512}/g).forEach((str, i) => {
  41. if(str.length > 0) messages.push(str);
  42. });
  43. for(let msg of messages) self.say(msg);
  44. }else{
  45. this.outbox.push({"message": string, "time": Date.now()});
  46. this.client.sendArray([{ m:'a', message:string }]);
  47. }
  48. }else{
  49. this.say("Error: Argument given is not a string.");
  50. }
  51. }
  52.  
  53. this.outbox = [];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement