Guest User

Untitled

a guest
Jul 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #!/usr/bin/ruby
  2.  
  3. require 'socket'
  4.  
  5. $server = 'irc.tddirc.net'
  6. $port = 6667
  7. $nick = $user = $real = 'scamper'
  8. $channels = ['#bots']
  9.  
  10. $sock = TCPSocket.open($server, $port)
  11.  
  12. def send(msg)
  13. begin
  14. puts "send> #{msg}"
  15. $sock.send "#{msg}\n", 0
  16. rescue
  17. puts "## Message failed to send ##"
  18. end
  19. end
  20.  
  21. def server_input(s)
  22. puts s
  23. case s.strip
  24. when /^ping /i
  25. puts "recv> PING {$'}"
  26. send "PONG #{$'}"
  27. end
  28. end
  29.  
  30. def command(s)
  31. s.chomp!
  32. case s.strip
  33. when /^msg /i
  34. privmsg $'
  35. when /^join /i
  36. unless $channels.include? $'
  37. send "JOIN #{$'}"
  38. $channels.push $'
  39. end
  40. when /^part /i
  41. if $channels.include? $'
  42. send "PART #{$'}"
  43. $channels.delete $'
  44. end
  45. end
  46. end
  47.  
  48. send "USER #{$user} #{$server} #{$server} :#{$real}"
  49. send "NICK #{$nick}"
  50. $channels.each { |chan| send "JOIN #{chan}" }
  51.  
  52. loop do
  53. input = select([$sock, $stdin], nil, nil, 60)
  54. next unless input
  55. puts "Past next statement"
  56.  
  57. input[0].each do |inp|
  58. if inp == $stdin
  59. return if $stdin.eof?
  60. inp = $stdin.gets
  61. command inp
  62. elsif inp == $sock
  63. return if $sock.eof?
  64. inp = $sock.gets
  65. server_input inp
  66. puts inp
  67. end
  68. end
  69.  
  70. puts "Reached end of the loop."
  71. end
Add Comment
Please, Sign In to add comment