Class | Ui::Qt4::Widgets::IrcBot |
In: |
ui/qt/widgets/chatwidget.rb
|
Parent: | Qt::Widget |
browser | [RW] | TODO: fix this |
users | [RW] | TODO: fix this |
# File ui/qt/widgets/chatwidget.rb, line 30 def initialize super @port = 6667 @host = 'localhost' @nick = 'etd' @irc = Qt::TcpSocket.new connect(@irc, SIGNAL('connected()'), self, SLOT('connected()')) connect(@irc, SIGNAL('bytesWritten(qint64)'), self, SLOT('outbound(qint64)')) connect(@irc, SIGNAL('readyRead()'), self, SLOT('inbound()')) connect(@irc, SIGNAL('error(QAbstractSocket::SocketError)'), self, SLOT('displayError(QAbstractSocket::SocketError)')) end
# File ui/qt/widgets/chatwidget.rb, line 124 def change_nick(new_nick) msg = "NICK #{new_nick}\r\n" @irc.write(msg, msg.size) end
# File ui/qt/widgets/chatwidget.rb, line 51 def connected() puts '[ircbot] connected to the server' @just_logged_in = true end
# File ui/qt/widgets/chatwidget.rb, line 129 def displayError(socketError) case socketError when Qt::AbstractSocket::RemoteHostClosedError: ; when Qt::AbstractSocket::HostNotFoundError: Qt::MessageBox.information(self, tr("chat widget"), tr("The host was not found. Please check the " + "host name and port settings.")) when Qt::AbstractSocket::ConnectionRefusedError: Qt::MessageBox.information(self, tr("chat widget"), tr("The connection was refused by the peer. " + "Make sure the server is running, " + "and check that the host name and port " + "settings are correct.")) else Qt::MessageBox.information(self, tr("chat widget"), tr("The following error occurred: %s." % @irc.errorString)) end end
# File ui/qt/widgets/chatwidget.rb, line 47 def exec @irc.abort @irc.connectToHost(@host, @port) end
# File ui/qt/widgets/chatwidget.rb, line 72 def handle_server_input(server_message) msg = nil case server_message.strip when /^PING :(.+)$/i @browser.append "[ Server ping ]" msg = "PONG :#{$1}" when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s.+\s:[\001]PING (.+)[\001]$/i @browser.append "[ CTCP PING from #{$1}!#{$2}@#{$3} ]" msg = "NOTICE #{$1} :\001PING #{$4}\001" when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s.+\s:[\001]VERSION[\001]$/i @browser.append "[ CTCP VERSION from #{$1}!#{$2}@#{$3} ]" msg = "NOTICE #{$1} :\001VERSION Ruby-irc v0.042\001" when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(.+)\s:EVAL (.+)$/i @browser.append "[ EVAL #{$5} from #{$1}!#{$2}@#{$3} ]" msg = "PRIVMSG #{(($4==@nick)?$1:$4)} :#{$5}" when /^:(.+?)!(.+?)@(.+?)\sNICK\s:(.+)$/i if $1 == @nick @nick = $4 end @browser.append "<b>#{$1}</b> is now known as: #{$4}." self.update_user_list($1, $4) when /^:(.+?)!(.+?)@(.+?)\sPRIVMSG\s(.+)\s:(.+)$/i @browser.append "#{$1}> #{$5}" when /^:(.+)!(.+?)@(.+?)\sJOIN\s:(.+)\r\n:(.+)\s(.+)\s(.+)\s@\s(.+)\s:(.+)\r\n:(.+)\s(.+)\s(.+)\s(.+)\s:End\sof\s\/NAMES\slist.$/i nicks = $9.split nicks.each do |pj| @users.addItem(pj) end when /^:(.+?)!(.+?)@(.+?)\sJOIN\s:(.+)$/i @users.addItem($1) #TODO> :etd!n=etd@5ac0b06d.bb.sky.com QUIT :"Saliendo" else @browser.append server_message end return if msg.nil? @irc.write(msg, msg.size) end
# File ui/qt/widgets/chatwidget.rb, line 107 def inbound() msg = @irc.readAll #@browser.append "---------\n" + msg.to_s + "\n---------" handle_server_input(msg.to_s) if @just_logged_in init_msg = [ "USER blah blah blah :blah blah\n", "NICK #{@nick}\n", "JOIN #dradis\n" ] init_msg.each do |msg| @irc.write(msg, msg.size) end @just_logged_in = false end end
# File ui/qt/widgets/chatwidget.rb, line 56 def outbound(size) puts '[ircbot] enviados ' + size.to_s end