Guest User

Untitled

a guest
Jul 18th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. var SpeakTo = function(opts) {
  2. for(var x in opts) {
  3. this[x] = opts[x]
  4. }
  5. this.timeout = this.timeout || 1000
  6. this.callback = this.callback || function() {}
  7. }
  8. SpeakTo.prototype.speak_array = function(target,messages) {
  9. if (messages.length != 0) {
  10. var msgs = messages.splice(0,3)
  11. for(var x in msgs) {
  12. this.irc.say(target,JSON.stringify(msgs[x]))
  13. }
  14. this.callback(this)
  15. if (this.timeout > 0) {
  16. var that = this
  17. setTimeout(function() {
  18. that.speak_array(target,messages)
  19. },this.timeout)
  20. }
  21. }
  22. }
  23.  
  24. SpeakTo.prototype.speak_to = function(target,messages) {
  25. if (target && messages) {
  26. if (messages instanceof Array) {
  27. this.speak_array(target,messages)
  28. }
  29. }
  30. return this;
  31. }
  32. exports.create = function(_irc,_timeout,_callback) {
  33. var speaker = new SpeakTo({irc:_irc,timeout:_timeout,callback:_callback});
  34. return speaker
  35. }
  36. exports.bang_speaker = function(_irc,_bang,_timeout,_callback) {
  37. var speaker = exports.create(_irc,_timeout,_callback)
  38. var bang = _bang
  39. return function(from,maybe_bang_message) {
  40. speaker.speak_to(from,
  41. bang.run(maybe_bang_message))
  42. return speaker
  43. }
  44. }
Add Comment
Please, Sign In to add comment