+sub cmd_add_search {
+ my ( $data, $server, $win ) = @_;
+
+ unless ( $twit and $twit->can('search') ) {
+ ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
+ . "doesn't support searches." );
+ return;
+ }
+
+ $data =~ s/^\s+|\s+$//;
+ $data = lc $data;
+
+ unless ($data) {
+ ¬ice("Usage: /twitter_subscribe <topic>");
+ return;
+ }
+
+ if ( exists $id_map{__searches}{$user}{$data} ) {
+ ¬ice("Already had a subscription for '$data'");
+ return;
+ }
+
+ $id_map{__searches}{$user}{$data} = 1;
+ ¬ice("Added subscription for '$data'");
+}
+
+sub cmd_del_search {
+ my ( $data, $server, $win ) = @_;
+
+ unless ( $twit and $twit->can('search') ) {
+ ¬ice("ERROR: Your version of Net::Twitter ($Net::Twitter::VERSION) "
+ . "doesn't support searches." );
+ return;
+ }
+ $data =~ s/^\s+|\s+$//;
+ $data = lc $data;
+
+ unless ($data) {
+ ¬ice("Usage: /twitter_unsubscribe <topic>");
+ return;
+ }
+
+ unless ( exists $id_map{__searches}{$user}{$data} ) {
+ ¬ice("No subscription found for '$data'");
+ return;
+ }
+
+ delete $id_map{__searches}{$user}{$data};
+ ¬ice("Removed subscription for '$data'");
+}
+
+sub cmd_list_search {
+ my ( $data, $server, $win ) = @_;
+
+ my $found = 0;
+ foreach my $suser ( sort keys %{ $id_map{__searches} } ) {
+ my $topics;
+ foreach my $topic ( sort keys %{ $id_map{__searches}{$suser} } ) {
+ $topics = $topics ? "$topics, $topic" : $topic;
+ }
+ if ($topics) {
+ $found = 1;
+ ¬ice("Search subscriptions for \@$suser: $topics");
+ }
+ }
+
+ unless ($found) {
+ ¬ice("No search subscriptions set up");
+ }
+}
+