Skip to content

Commit

Permalink
Add command line to specify max lines of chat.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Oct 22, 2009
1 parent 3a6e2c3 commit 9e581fc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions last_chats.pl
Expand Up @@ -20,6 +20,7 @@
my $dbinfo = undef;
my $xmppuser = undef;
my $maildir = undef;
my $maxlines = undef;
my $cmdok = 1;

my $debug = 0;
Expand All @@ -28,7 +29,7 @@ sub dbgprint {
}

sub usage {
die("USAGE: $0 <dbinfo> <xmppuser> <maildir>\n");
die("USAGE: $0 <dbinfo> <xmppuser> <maildir> <maxlines>\n");
}

# localize to current timezone and return as unix epoch format.
Expand Down Expand Up @@ -93,8 +94,10 @@ sub signal_catcher {
$dbinfo = $_, next if (not defined $dbinfo);
$xmppuser = $_, next if (not defined $xmppuser);
$maildir = $_, next if (not defined $maildir);
$maxlines = int($_), next if not (defined $maxlines);
usage();
}
$maxlines = 10 if (not defined $maxlines);
usage() if (not defined $dbinfo);
usage() if (not defined $xmppuser);
usage() if (not defined $maildir);
Expand Down Expand Up @@ -129,7 +132,7 @@ sub signal_catcher {
' inner join archive_collections as c on (m.coll_id = c.id)' .
" where (c.us = '$xmppuser')" .
' and m.utc between DATE_SUB(UTC_TIMESTAMP(), interval 1 day) and UTC_TIMESTAMP()' .
' order by m.id desc limit 10) as A order by A.msgid';
" order by m.id desc limit $maxlines) as A order by A.msgid";
dbgprint("sql = '$sql'\n");
my $sth = $link->prepare($sql);
$sth->execute() or fail "can't execute the query: ${sth->errstr}";
Expand Down

0 comments on commit 9e581fc

Please sign in to comment.