… | |
… | |
3 | # statistics-package |
3 | # statistics-package |
4 | |
4 | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
7 | |
7 | |
8 | our $UPDATE_LOGINS = EV::idle sub { |
8 | our $UPDATE_LOGINS = AE::idle sub { |
9 | $_[0]->stop; |
9 | $_[0]->stop; |
10 | |
10 | |
11 | cf::async { |
11 | cf::async { |
12 | my ($status, @pl) = ext::commands::who_listing; |
12 | my ($status, @pl) = ext::commands::who_listing; |
13 | |
13 | |
… | |
… | |
48 | $pl->ob->kv_set (schmorplog_last_login => time); |
48 | $pl->ob->kv_set (schmorplog_last_login => time); |
49 | |
49 | |
50 | $pl->ob->kv_set (schmorplog_login_count => |
50 | $pl->ob->kv_set (schmorplog_login_count => |
51 | 1 + $pl->ob->kv_get ("schmorplog_login_count")); |
51 | 1 + $pl->ob->kv_get ("schmorplog_login_count")); |
52 | |
52 | |
53 | (my $client = $pl->ns->version) =~ s/\n/\\n/g; |
|
|
54 | |
|
|
55 | $pl->ob->kv_set (schmorplog_client => $client); |
53 | $pl->ob->kv_set (schmorplog_client => $pl->ns->{who_version}); |
56 | |
54 | |
57 | ext::irc::do_notice (sprintf "%s logged in", $pl->ob->name); |
55 | ext::irc::do_notice (sprintf "%s logged in", $pl->ob->name); |
58 | |
56 | |
59 | $UPDATE_LOGINS->start; |
57 | $UPDATE_LOGINS->start; |
60 | |
58 | |
… | |
… | |
119 | or return $who->reply ($npc, "I don't know any person named '$args'."); |
117 | or return $who->reply ($npc, "I don't know any person named '$args'."); |
120 | |
118 | |
121 | my $s = $pl->ob->{stats_death} |
119 | my $s = $pl->ob->{stats_death} |
122 | or return $who->reply ($npc, "$args didn't die even once."); |
120 | or return $who->reply ($npc, "$args didn't die even once."); |
123 | |
121 | |
124 | my $rep = "$args died a total of " . $pl->ob->kv_get ("schmorplog_death_count") . " times, among them:\n\n\n\n"; |
122 | my $rep = "$args died a total of " . $pl->ob->kv_get ("schmorplog_death_count") . " times, among them:\n\n"; |
125 | |
123 | |
126 | for (sort { $s->{$b} <=> $s->{$a} } keys %$s) { |
124 | for (sort { $s->{$b} <=> $s->{$a} } keys %$s) { |
127 | $rep .= "$s->{$_} time(s) due to $_.\n\n"; |
125 | $rep .= sprintf " C<%4d> time(s) due to %s.\n", $s->{$_}, $_; |
128 | } |
126 | } |
129 | |
127 | |
130 | $who->reply ($npc, $rep); |
128 | $who->reply ($npc, $rep); |
131 | }; |
129 | }; |
132 | } elsif ($cmd eq "kills") { |
130 | } elsif ($cmd eq "kills") { |
… | |
… | |
135 | or return $who->reply ($npc, "I don't know any person named '$args'."); |
133 | or return $who->reply ($npc, "I don't know any person named '$args'."); |
136 | |
134 | |
137 | my $s = $pl->ob->{stats_kill} |
135 | my $s = $pl->ob->{stats_kill} |
138 | or return $who->reply ($npc, "I don't know of I<anything> that $args has killed so far."); |
136 | or return $who->reply ($npc, "I don't know of I<anything> that $args has killed so far."); |
139 | |
137 | |
140 | my $rep = sprintf "\n\nC<%6s> %s\n\n", "Kills", "Name"; |
138 | my $rep = sprintf "Here is a list of all the kills I know about:\n\n"; |
141 | for (sort { $s->{$a} <=> $s->{$b} } keys %$s) { |
139 | for (sort { $s->{$b} <=> $s->{$a} } keys %$s) { |
142 | $rep .= sprintf "C<%6s> %s\n\n", $s->{$_}, $_; |
140 | $rep .= sprintf " C<%6s> %s\n", $s->{$_}, $_; |
143 | } |
141 | } |
144 | |
142 | |
145 | $who->reply ($npc, $rep); |
143 | $who->reply ($npc, $rep); |
146 | }; |
144 | }; |
147 | } elsif ($cmd eq "hi") { |
145 | } elsif ($cmd eq "hi") { |
148 | $who->reply ($npc, "Hello!\n\n" |
146 | $who->reply ($npc, "Hello!\n\n" |
149 | . "I am a statistician, I keep statistics about all people here.\n\n" |
147 | . "I am a statistician, I keep statistics about all people here.\n\n" |
150 | . "To know how often somebody died, ask C<deaths> I<playername>\n\n" |
148 | . " - To know how often somebody died, ask C<deaths> I<playername>\n" |
151 | . "To know how many kills somebody scored, ask C<kills> I<playername>"); |
149 | . " - To know how many kills somebody scored, ask C<kills> I<playername>"); |
152 | } else { |
150 | } else { |
153 | $who->reply ($npc, "No idea what you want of me, how about saying 'hi' first?"); |
151 | $who->reply ($npc, "No idea what you want of me, how about saying 'hi' first?"); |
154 | } |
152 | } |
155 | |
153 | |
156 | $cmd = lc $cmd; |
154 | $cmd = lc $cmd; |