#!/usr/bin/perl # by Alberto Simões package List; use MLDBM qw(DB_File Storable); use Fcntl; use cybot; my %lists = (); my $clist = ""; sub RC { register_command(@_); } my $obj = tie %lists, 'MLDBM', "data/lists.db", O_CREAT|O_RDWR, 0644; RC("lists",sub { my ($bot,$chan,$nick,$mask, @commands) = @_; for (keys %lists) { $bot->message ($chan, $_); } }, "Returns a list of lists"); RC("list", sub { my ($bot,$chan,$nick,$mask, @commands) = @_; my $command = shift @commands || $clist; if ($command eq "new") { $clist = shift @commands; $lists{$clist} = []; $bot->message ($chan, "list $clist created"); } elsif ($command =~ m!^del!) { delete($lists{shift @commands}); $clist = undef; $bot->message ($chan, "list deleted"); } elsif ($command eq "add") { if ($clist) { $lists{$clist} = [@{$lists{$clist}}, join(" ",@commands)]; $bot->message ($chan, "added to list $clist"); } else { $bot->message($chan, "no default list selected"); } } elsif ($command eq "set") { my $x = shift @commands; if (exists($lists{$x})) { $bot->message($chan, "default list changed"); $clist = $x; } else { $bot->message($chan, "no such list"); } } elsif ($command eq "search") { my $regexp = shift @commands || "*"; for (@{$lists{$clist}}) { eval{$bot->message($chan, $_) if m!$regexp!}; } } else { if (exists($lists{$command})) { #$bot->message($chan, "listing $command"); for (@{$lists{$command}}) { $bot->message($chan, $_); } } else { $bot->message($chan, "no such list"); } } $obj->sync; },"list: lists current list list new : creates a new list, and makes it the default one list set : sets the list named the default list list del : deletes the list names list search : searches the list for entries matching the perl pattern "); 1;