File: snap_bot

package info (click to toggle)
snap 0.08-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 440 kB
  • ctags: 473
  • sloc: perl: 7,033; makefile: 117; sh: 70
file content (35 lines) | stat: -rw-r--r-- 744 bytes parent folder | download
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
28
29
30
31
32
33
34
35
#
# This is an incredibly annoying example of a simple bot in Snap. :)
#
# As you can see, it hooks into the system initialization to log itself
# into a specific channel, where it greets people who join the channel.
#

push @extensions, "DemoBot";

push @{ $code_hash{&MSG_LOGIN_ACK} }, \&bot_init;
push @{ $code_hash{&MSG_JOIN_MSG} }, \&greet_user;

sub greet_user
{
  my ($sock, $text) = @_; 
  my ($channel, $user, $sharing, $speed);
  my %user_entry;

  $$text =~ /(.+?) (.+?) (\d+?) (\d+)/;

  $channel = $1; $user = $2; $sharing = $3; $speed = $4;

  return if ($user eq $username);

  do_send_public($sock, "Greetbot: Welcome to this channel $user!");
}

sub bot_init
{
  my ($sock, $text) = @_; 

  do_chan_join($sock, "opennap");
}