Advertisement
Guest User

Untitled

a guest
Jan 12th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. require 'socket'
  2.  
  3. TWITCH_HOST = "irc.twitch.tv"
  4. TWITCH_PORT = 6667
  5.  
  6. class TwitchBot
  7.  
  8. def initialize
  9. @nickname = "James200024bot"
  10. @password = "oauth:jkffmog2xf0zj1smj3ie3tj7us9i3d"
  11. @channel = "James200024"
  12. @socket = TCPSocket.open(TWITCH_HOST, TWITCH_PORT)
  13.  
  14. write_to_system "PASS #{@password}"
  15. write_to_system "NICK #{@nickname}"
  16. write_to_system "USER #{@nickname} 0 * #{@nickname}"
  17. write_to_system "JOIN ##{@channel}"
  18. end
  19.  
  20. def write_to_system(message)
  21. @socket.puts message
  22. end
  23.  
  24. def write_to_chat(message)
  25. write_to_system "PRIVMSG ##{@channel} :#{message}"
  26. end
  27.  
  28. def run
  29. until @socket.eof? do
  30. message = @socket.gets
  31. puts message
  32.  
  33. if message.match(/^PING :(.*)$/)
  34. write_to_system "PONG #{$~[1]}"
  35. next
  36. end
  37.  
  38. if message.match(/PRIVMSG ##{@channel} :(.*)$/)
  39. content = $~[1]
  40. username = message.match(/@(.*).tmi.twitch.tv/)[1]
  41.  
  42. # if content.include? "!James"
  43. # write_to_chat("James is a plank")
  44. # if content.include? "!Discord"
  45. # write_to_chat("https://discord.gg/egtPeTP Join the discord today , and enjoy the fun ;)")
  46. # if content.include? "!Twitter"
  47. # write_to_chat("James200024 Go and follow him on Twitter for all the latest updates!")
  48. # if content.include? "!Instagram"
  49. # write_to_chat("James200024 Go and follow him on Instagram for all the latest posts!")
  50. # if content.include? "!Steam"
  51. # write_to_chat("James200024 Go and him on Steam for all the mp fun")
  52. # if content.include? "!YouTube"
  53. # write_to_chat("James200024 is the youtube <> go and subscribe and join in the fun by watching the videos")
  54. # end
  55.  
  56. command = <<-OSASCRIPT
  57. osascript -e 'display notification "#{content}" with title "#{username}"'
  58. OSASCRIPT
  59.  
  60. system(command)
  61. end
  62. end
  63. end
  64.  
  65. def quit
  66. write_to_chat "James200024bot is out"
  67. write_to_system "PART ##{@channel}"
  68. write_to_system "QUIT"
  69. end
  70.  
  71. end
  72.  
  73. bot = TwitchBot.new
  74. trap("INT") { bot.quit }
  75. bot.run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement