1 # -*- Mode: perl; tab-width: 4; indent-tabs-mode: nil; -*-
2 ################################
4 ################################
6 package BotModules::List;
11 # XXX Wipe entire list command
13 # RegisterConfig - Called when initialised, should call registerVariables
16 $self->SUPER::RegisterConfig(@_);
17 $self->registerVariables(
18 # [ name, save?, settable? ]
19 ['lists', 1, 1, {}], # user => 'list name|item 1|item 2||list name|item1|item 2'
20 ['preferredLineLength', 1, 1, 80], # the usual
21 ['maxItemsInChannel', 1, 1, 20], # max number of items to print in the channel (above this and direct messages are used)
29 '' => 'A personal list tracker. Store your lists here. You must be authenticated to use this (see \'newuser\'). Use the \'add\' command to add items to a list.',
30 'add' => 'Add an item to a personal list. List names shouldn\'t contain the word \'to\' otherwise things will be too ambiguous. Syntax: \'add <thing to add> to <list name> list\', e.g. \'add bug 5693 to critical bug list\'.',
31 'remove' => 'Remove an item from a personal list. Syntax: \'remove <thing to add> from <list name> list\', e.g. \'remove bug 5693 from critical bug list\'.',
32 'list' => 'List the items in your list. Syntax: \'list items in <name of list> list\', e.g. \'list items in critical bug list\' or just \'critical bug list\'.',
33 'lists' => 'Tells you what lists you have set up.',
39 my ($event, $message) = @_;
40 if ($message =~ /^\s*add\s+(\S(?:.*\S)?)\s+to\s+(?:my\s+)?(\S(?:.*\S)?)\s+list[\s!.]*$/osi and $message !~ /\|/o and $event->{'userName'}) {
41 $self->AddItem($event, $1, $2);
42 } elsif ($message =~ /^\s*remove\s+(\S(?:.*\S)?)\s+from\s+(?:my\s+)?(\S(?:.*\S)?)\s+list[\s!.]*$/osi and $message !~ /\|/o and $event->{'userName'}) {
43 $self->RemoveItem($event, $1, $2);
44 } elsif ($message =~ /^\s* (?:examine \s+ |
45 list \s+ items \s+ in \s+ |
46 what (?:\s+is|'s) \s+ (?:in\s+)? )
47 (?: my \s+ | the \s+ )?
49 \s+ list [\s!?.]* $/osix
50 and $message !~ /\|/o and $event->{'userName'}) {
51 $self->ListItems($event, $1);
52 } elsif ($message =~ /^\s*lists[?\s.!]*$/osi and $event->{'userName'}) {
53 $self->ListLists($event, $1);
55 return $self->SUPER::Told(@_);
57 return 0; # dealt with it...
62 my ($event, $message) = @_;
63 if ($message =~ /^\s*(\S(?:.*\S)?)\s+list[\s!?.]*$/osi and $message !~ /\|/o and $event->{'userName'}) {
64 $self->ListItems($event, $1);
66 return $self->SUPER::Baffled(@_);
68 return 0; # dealt with it...
73 my ($event, $message) = @_;
74 if ($message =~ /^\s*add\s+(\S(?:.*\S)?)\s+to\s+(?:my\s+)?(\S(?:.*\S)?)\s+list[\s!.]*$/osi and $message !~ /\|/o and $event->{'userName'}) {
75 $self->AddItem($event, $1, $2);
76 } elsif ($message =~ /^\s*remove\s+(\S(?:.*\S)?)\s+from\s+(?:my\s+)?(\S(?:.*\S)?)\s+list[\s!.]*$/osi and $message !~ /\|/o and $event->{'userName'}) {
77 $self->RemoveItem($event, $1, $2);
79 return $self->SUPER::Told(@_);
81 return 0; # dealt with it...
86 my ($event, $what, $list) = @_;
87 my @lists = split(/\|\|/o, $self->{'lists'}->{$event->{'userName'}});
90 foreach my $sublist (@lists) {
91 my @items = split(/\|/o, $sublist);
92 $lists{shift @items} = \@items;
94 push(@{$lists{lc $list}}, $what);
96 my $compoundLists = '';
97 foreach my $list (keys(%lists)) {
98 if ($compoundLists ne '') {
99 $compoundLists .= '||';
101 $compoundLists .= "$list|@{$lists{$list}}";
103 $self->{'lists'}->{$event->{'userName'}} = $compoundLists;
105 $self->say($event, "$event->{'from'}: stored '$what' in '$list' list");
110 my ($event, $what, $list) = @_;
111 my @lists = split(/\|\|/o, $self->{'lists'}->{$event->{'userName'}});
115 foreach my $sublist (@lists) {
116 my @items = split(/\|/o, $sublist);
117 if (lc $list eq $items[0]) {
118 my $listName = shift @items;
119 foreach my $item (@items) {
120 if (lc $what ne lc $item) {
121 push(@{$lists{$listName}}, $item);
127 $lists{shift @items} = \@items;
131 my $compoundLists = '';
132 foreach my $list (keys(%lists)) {
133 if ($compoundLists ne '') {
134 $compoundLists .= '||';
136 $compoundLists .= "$list|@{$lists{$list}}";
138 $self->{'lists'}->{$event->{'userName'}} = $compoundLists;
141 $self->say($event, "$event->{'from'}: removed '$what' from '$list' list");
143 $self->say($event, "$event->{'from'}: could not find '$what' in '$list' list");
149 my ($event, $list) = @_;
150 my @lists = split(/\|\|/o, $self->{'lists'}->{$event->{'userName'}});
152 foreach my $list (@lists) {
153 my @items = split(/\|/o, $list);
154 $lists{lc shift @items} = \@items;
156 if (defined(@{$lists{lc $list}})) {
157 my $size = scalar(@{$lists{lc $list}});
158 if ($size > $self->{'maxItemsInChannel'}) {
159 $self->channelSay($event, "$event->{'from'}: Your $list list contains $size items, which I am /msg'ing you.");
160 $self->directSay($event, $self->prettyPrint($self->{'preferredLineLength'}, "Your $list list contains: ", '', ', ', @{$lists{lc $list}}));
162 $self->say($event, $self->prettyPrint($self->{'preferredLineLength'}, "Your $list list contains: ", $event->{'channel'} eq '' ? '' : "$event->{'from'}: ", ', ', @{$lists{lc $list}}));
165 $self->say($event, "You don't have a $list list, sorry.");
172 my @lists = split(/\|\|/o, $self->{'lists'}->{$event->{'userName'}});
174 foreach my $list (@lists) {
175 my @items = split(/\|/o, $list);
176 push(@listNames, $items[0]);
178 $self->say($event, $self->prettyPrint($self->{'preferredLineLength'}, "Your lists are: ", $event->{'channel'} eq '' ? '' : "$event->{'from'}: ", ', ', @listNames));