Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: Beginners Programming Challenge #21

  1. #11
    Join Date
    Jul 2007
    Location
    Austin, TX
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Beginners Programming Challenge #21

    I'm thinking this challenge could use another weekend for people to work on things, since that's when I see people connecting the most into #ufpc. So let's have the last day for submissions be on Tuesday, the 18th, and then I'll judge shortly thereafter.

    Does that sound good?

  2. #12
    Join Date
    Dec 2007
    Location
    Behind you!!
    Beans
    977
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Beginners Programming Challenge #21

    Yep, more time please. Still working on my submission.

    Bodsda

    EDIT: Not gonna get mine finished soon
    Last edited by Bodsda; July 20th, 2011 at 03:01 PM.
    computer-howto
    Linux is not windows
    Fluxbox & Flux menu how to
    Programming is an art. Learn it, Live it, Love it!


  3. #13
    Join Date
    Jul 2007
    Location
    Austin, TX
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Beginners Programming Challenge #21

    So this challenge has been open for a while... I'll judge what's here next Monday, August 8.

  4. #14
    Join Date
    Nov 2009
    Location
    Ukraine
    Beans
    11

    Re: Beginners Programming Challenge #21

    Written in Ruby. You also can read the source code on GitHub (for more convenience).

    PHP Code:
    require 'socket'
    require 'open-uri'

    =begin

      Really infirm IRC bot implementation
    .

    =
    end

    class IRCBot

      
    # Initialize required parameters.
      #
      
    def initialize(hostportnickreal_nameidentchannels)
        @
    host host
        
    @port port
        
    @nick nick
        
    @real_name real_name
        
    @ident ident
        
    @channels channels # An array of channels, which should be visited by a bot.
      
    end

      
    # Connect to server with given parameters.
      #
      
    def connect
        
    @server TCPSocket.new(@host, @port)
        
    # First two messages, that every client should send to a server.
        # For more details see RFC2812.
        
    send "NICK #{@nick}"
        
    send "USER #{@ident} 0 * :#{@real_name}"

        
    # Join every provided channel.
        
    @channels.each do |channel|
          
    send "JOIN #{channel}"
          
    say channel"#{@nick} arrived." # Welcome message.
        
    end
      end

      
    # Message interchange between client and server.
      #
      
    def main_loop
        loop 
    do
          
    recieved_message = @server.gets
          puts recieved_message

          
    # Capture a channel's name, where the keywords were
          # said, to address a response to the proper channel.
          
    recieved_message.match(/(#\w+)/)
          
    channel = $1

          recieved_message
    .match(/:(\w+)!/) # Extract the applicant's nick.
          
    applicant = $1

          
    # Keywords handling.
          
    case recieved_message

            
    # '!help' message.
            
    when /:!helpthen say channel"No way!"

            
    # If someone would try to talk to the bot, the latter will
            # respond to the applicant with a one of the predefined phrases.
            #
            # Example:
            #
            #   <Bob> Glitch, how are you?
            #   <Glitch> La-la-la!
            #   <Bob> Glitch: Are you stupid?
            #   <Glitch> WHAAAAT?!
            #   <Bob> Whoa! Okay-okay, could you forgive me, Glitch?
            #   <Glitch> Sure.
            #
            
    when /:.+[,\s]?#{@nick}[:|,|\.]/
              # Predefined replies.
              
    replies = ["WHAAAAT?!""Sure.""Yes, I know, my name is #{@nick}.",
                         
    "Nice to meet you. My name is #{@real_name}.""La-la-la!",
                         
    "Are you sure about that, #{applicant}?"]
              
    # On every call, throw a random reply.
              
    say channelreplies.sample

            
    # Display some information about author of this program.
            
    when /:!author/
              
    say channel"My master is Kirill Silin <curacaothe@gmail.com>."

            
    # Ability to throw something at someoglitchne.
            # 
            # Example:
            #
            #   <Bob> !throw a stone Hexadecimal
            #   <Glitch> Bob threw a stone at Hexadecimal.
            #   <Bob> !throw an egg Megabyte
            #   <Glitch> Bob threw an egg at Megabyte.
            #
            
    when /:!throw ((a|an) \w+) (\w+)/i
              say channel
    "#{applicant} threw #{$1} at #{$3}."

            
    # Required for persistent connection to server.
            
    when /^PING :(.+)$/ then send "PONG #{$1}"
            
            
    # URL handling.
            #
            # Example:
            #
            #   <Bob> Guys, there is an article about us!
            #   <Bob> Check this out: http://en.wikipedia.org/wiki/ReBoot
            #   <Glitch> Title: ReBoot - Wikipedia, the free encyclopedia
            #
            
    when /PRIVMSG #\w+ :.*(https?:\/\/[\S]+)/
              
    begin
                url 
    open($1)
              
    rescue OpenURI::HTTPError => err
                puts 
    "--> Error: #{err}"
              
    end

              title 
    url.readlines.join.match(/<title>(.+)<\/title>/)[1rescue nil

              unless title
    .nil?
                
    message "Title: #{title}"
                
    say channelmessage
              end
          end
        end
      end

      
    # Quit from server.
      #
      
    def quit
        
    @server.close
      end

      
    private

      
    # A wrapper around existing 'send' method for more convenience.
      # 
      
    def send(msg)
        @
    server.send("#{msg}\r\n"0)
      
    end

      
    # Say something on channel. Visible to all channel participants.
      #
      
    def say(channeltext)
        
    send "PRIVMSG #{channel} :#{text}\r\n"
      
    end

    end

    channels 
    = %w#ufpc ]
    bot IRCBot.new("chat.freenode.net"6667,
                     
    "GlitchIRCbot""Unnamed Unit",
                     
    "Mainframe"channels)
    begin
      bot
    .connect
      bot
    .main_loop
    rescue Exception 
    => err
      puts 
    "--> Error: #{err}"
    ensure
      bot
    .quit
    end 
    Last edited by CuracaoThe; August 6th, 2011 at 02:44 AM. Reason: Typo.

  5. #15
    Join Date
    Jul 2007
    Location
    Austin, TX
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Beginners Programming Challenge #21

    Alright, so I finally got around to judging these, and I hereby declare the winner to be.... ziekfiguur! and his bot, botz0r.

    I know this was a difficult challenge, but I am quite grateful that you guys all participated. I got all the bots working with just a tweak here and there (for compatibility issues), and it was fun experimenting with clojure and ruby, as I've never used those languages before. ziekfiguur's bot stood out in particular with solid design some pretty awesome regex matching and grouping, so congratulations!

    Looking forward to the next challenge!

  6. #16
    Join Date
    Nov 2009
    Location
    Ukraine
    Beans
    11

    Re: Beginners Programming Challenge #21

    Congratulations, ziekfiguur!

    It was fun to code IRC bot. Thank you, Queue29 for cool programming task.

  7. #17
    Join Date
    Nov 2009
    Location
    The Netherlands
    Beans
    239
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Beginners Programming Challenge #21

    @CuracaoThe Thank you!

    I will try to post the next challenge somewhere this week, and i'll try to make it a bit easier than this one

  8. #18
    Join Date
    Aug 2011
    Location
    India
    Beans
    34
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Beginners Programming Challenge #21

    Hi ziekfiguur,
    Waiting for the next challenge from you.
    Thanks.

  9. #19
    Join Date
    Dec 2007
    Location
    Behind you!!
    Beans
    977
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Beginners Programming Challenge #21

    Quote Originally Posted by kunal00731 View Post
    Hi ziekfiguur,
    Waiting for the next challenge from you.
    Thanks.
    The new challenge has been up for a while
    http://ubuntuforums.org/showthread.php?t=1828128

    Bodsda
    computer-howto
    Linux is not windows
    Fluxbox & Flux menu how to
    Programming is an art. Learn it, Live it, Love it!


Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •