]> www.dxcluster.org Git - spider.git/blob - cmd/show/groups.pl
part of making rcmd work again for async cmds
[spider.git] / cmd / show / groups.pl
1 #
2 # show recently used groups
3 #
4 # by Tommy SM3OSM
5 #
6 #
7 #
8
9 use Time::Local;
10
11 sub handle
12 {
13         my $self = shift;
14         my $to = shift;
15
16         if ($to =~ /\D/) {
17                 return (1, "try sh/chatgroups xxx where xxx is the number of chat messages to search.");
18         }
19
20         my @out;
21         $to = 500 unless $to;
22
23         @out = $self->spawn_cmd("show/groups $to", \&DXLog::print, 
24                                                         args => [0, $to, $main::systime, 'chat', undef], 
25                                                         cb => sub {
26                                                                 my $self = shift;
27                                                                 my @chatlog = @_;
28
29                                                                 my $g= {};
30                                                                 my @out;
31                                                                 my $row;
32                                                                 my ($time, $call, $group);
33                                                                 my $found;
34                                                                 my %month = (
35                                                                                          Jan => 0,
36                                                                                          Feb => 1,
37                                                                                          Mar => 2,
38                                                                                          Apr => 3,
39                                                                                          May => 4,
40                                                                                          Jun => 5,
41                                                                                          Jul => 6,
42                                                                                          Aug => 7,
43                                                                                          Sep => 8,
44                                                                                          Oct => 9,
45                                                                                          Nov => 10,
46                                                                                          Dec => 11,
47                                                                                         );
48
49                                                                 @chatlog = reverse @chatlog;
50                                                                 foreach $row(@chatlog) {
51                                                                         ($time, $call, $group) = ($row =~ m/^(\S+) (\S+) -> (\S+) /o);
52                                                                         if (!exists $g->{$group}) {
53                                                                                 $time =~ m/^(\d\d)(\w{3})(\d{4})\@(\d\d):(\d\d):(\d\d)/o;
54                                                                                 $g->{$group}->{sec} = timegm($6, $5, $4, $1, $month{$2}, $3-1900);
55                                                                                 $time =~ s/\@/ at /;
56                                                                                 $g->{$group}->{last} = $time;
57                                                                                 push @{ $g->{$group}->{calls} }, $call;
58                                                                         }
59                                                                         else {
60                                                                                 $found = 0;
61                                                                                 foreach (@{ $g->{$group}->{calls} }) {
62                                                                                         if (/$call/) {
63                                                                                                 $found = 1;
64                                                                                                 last;
65                                                                                         }
66                                                                                 }
67                                                                                 push @{ $g->{$group}->{calls} }, $call unless $found;
68                                                                         }
69                                                                         $g->{$group}->{msgcount}++;
70                                                                 }
71
72                                                                 push (@out, "Chat groups recently used:");
73                                                                 push (@out, "($to messages searched)");
74                                                                 push (@out, "--------------------------");
75                                                                 my @calls;
76                                                                 my @l;
77                                                                 my $max = 6;
78                                                                 my $mtext;
79                                                                 foreach $group (sort { $g->{$b}->{sec}  <=> $g->{$a}->{sec} } keys %$g) {
80                                                                         @calls = sort( @{ $g->{$group}->{calls} } );
81                                                                         $mtext = "  " . $g->{$group}->{msgcount} . " messages by:";
82                                                                         push (@out, "$group: Last active " . $g->{$group}->{last});
83                                                                         if (@calls <= $max) {
84                                                                                 push (@out, "$mtext @calls");
85                                                                         }
86                                                                         else {
87                                                                                 foreach $call(@calls) {
88                                                                                         push @l, $call;
89                                                                                         if (@l >= $max) {
90                                                                                                 if ($max == 6) {
91                                                                                                         push (@out, "$mtext @l");
92                                                                                                 }
93                                                                                                 else {
94                                                                                                         push (@out, "  @l");
95                                                                                                 }
96                                                                                                 @l = ();
97                                                                                                 $max = 8;
98                                                                                         }
99                                                                                 }
100                                                                                 push (@out, "  @l") if (@l);
101                                                                                 $max = 6;
102                                                                                 @l = ();
103                                                                         }
104                                                                         push (@out, "-");
105                                                                 }
106                                                                 return @out;
107                                                         });
108         
109         #       my @chatlog = DXLog::print(undef, $to, $main::systime, 'chat', undef);
110         return (1, @out);
111 }