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