Archive for February, 2008

Gmail Signup Form. 1

gmail1.jpg

Saw this today while signing up for an account for Orkut. That’s a rather strange way of checking password complexity. Google probably goes the extra mile to rate password at server side instead of client side. Also the audio captcha was really horrible, it sounded more like two voices at the same time.

Writing an IRC Bot 1

I had always been intrigued about IRC Bots and always thought it was quite cool to be able to write one, esp when i would see loads of script kiddies downloading stuff and setting it up on free shell accounts. recently at work it was suddenly a season for writing bots, it seemed like everyone was writing one, for a useful purpose ofcourse so i though i would jump it and give it a shot.

So as it turned out to be a fairly straight forward job to do. Since I was happy writing stuff in Perl i decided to write the bot in perl like most of my hack are.

Setting up the development/deployment environment:
Install the Bot::BasicBot from cpan
#sudo perl -MCPAN -e ‘install Bot::BasicBot’
This would go out for you and get all the required modules and its dependencies.

Writing the actual bot:
The API for the pm is pretty well documented and has a good enough example to get you started. Writing the bot using this PERL module was pretty much like writing a SAX parser where you would override methods.

So lets get started with the basic bot:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl
use warnings;
use strict;
 
package MyBot;
use base qw(Bot::BasicBot);
 
# Create an instance of the bot and start it running. Connect
# to the main perl IRC server, and join some channels.
MyBot->new(
  server => 'irc.freenode.net',
  channels => ['#testbot'],
  nick => 'blabot'
  )->run();

Now do a chmod a+x on this bot and run it, this will cause the bot to come to life, connect to the server and join the channel as specified in the MyBot’s constructor. You can find other interesting attributes to assign in the constructor here

This is a pretty boring bot, it doesnt do much it just joins the channel and sits there doing nothing. To make it do something, you need to override interesting ‘events’ for the bot to do something. Some of the interesting events are

  • chanjoin: This is called everytime someone joins the channel
  • said: this function is called everytime someone says something
  • help: this is called when someone calls the bot with the message help
  • Other interesting events can be found on the API page

So continuing to write something more useful we go ahead and update the code with some new overridden methods.

1
2
3
4
5
6
sub chanjoin {
    my ($self, $message) = @_;
    if ($message->{who} eq 'rajat') {
        return 'Hello Rajat, how are you doing!!';
    }
}

This is a clever one, it greets me everytime I join the channel, ok maybe not so much.

Ok so to make the bot do something useful, I get to make a search query on yahoo.com everytime one calls it with a search term. So i go ahead and install the Yahoo::Search module as well.

1
2
3
4
5
6
7
8
9
10
#sudo perl -MCPAN -e 'install Yahoo::Search'
</code>
Which does all the installation magic  for you.
 
Loads the Module in the perl script we are writing.
<pre lang="perl" line="1">
#!/usr/bin/perl
use warnings;
use strict;
use Yahoo::Search;

and then override the said method:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
sub said {
  my ($self, $message) = @_;
  my $out;
  my $address;
  $address  = $message->{address};
  if (!$address) {
      $address = "";
  }
  if ($address eq 'blabot') {
      my @results = Yahoo::Search->Results(
          Doc =&gt; $message->{body},
          AppId => "YahooDemo",
          Mode =>'all',
          Start => 0,
          Count =>5,
          Type =>'any',
          AllowAdult => 0,
          AllowSimilar => 0,
          Language => undef);      
 
      for my $result(@results) {
          $out = $out . ' ' . $result->Url . "\n";
      }
 
  }
  return $out;
}

and that’s all that is required. Running the script will get it to connect to the irc server and join the channel, to test the bot you can either type to message in the mains on in private by send the command.
blabot, yahoo developer

it will cause the bot to return the top five search results for the term ‘yahoo developer’. You can download the script here.

A couple of useful links:
http://search.cpan.org/dist/Bot-BasicBot/lib/Bot/BasicBot.pm
Writing an IRC Bot in Perl

yui - custom event 0

Note to self on how to setup custom even.
Step 1: Define a custom event

1
var onCustomEvent1 = new YAHOO.util.CustomEvent('onCustomEvent');

Step 2: Make methods subscribe to the event

1
2
onCustomEvent1.subscribe(method1);
onCustomEvent1.subscribe(method2);

etc.You can also pass arguments to the subscribe method, which can be accessed by the subscribed method, as explained below.

Step 3: Whenever that event is supposed to be triggerd, cause the event to be executed

onCustomEvent1.fire();

You can also pass arguments to the fire method, these arguments can then be accessed in the subscribe method explained below.

1
2
onCustomEvent1.fire({action:'fire'});
function method1(event, arguments, obj) {}
  • event returns the name of the custom event
  • arguments is the set of arguments that are passed in the fire event
  • obj is the argument that is passed in the subscribe method.

Calling the fire() method causes all the listener methods to get fired. Simple stuff, amazing uses as well, maybe its just me but i am sure i wont remember this the second time i have look at it.

0

Though i am not a believer of non standard stuff, but recently was asked this question on IRC on how to launch applications via a hyperlink, it was probably alright to do that in the users case, since this was for an Intranet and everyone had that software installed and were running windows.  The call:// link on skype gave me the idea that its got something to do with the windows registry (or atleast on the windows platform).

Found an article on MSDN that talks about this:

http://msdn2.microsoft.com/en-us/library/aa767914.aspx

Code Quality Measurement 1