]> git.sesse.net Git - skvidarsync/commitdiff
Add a reaction log for HKS.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Apr 2024 23:14:24 +0000 (01:14 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 20 Apr 2024 23:14:24 +0000 (01:14 +0200)
bin/sync.pl

index b8483eef69994a43a7534b560f24ead3230df67e..d84a33ea7f1fc81d190d3d396c03df6be06bf4a2 100644 (file)
@@ -348,10 +348,10 @@ sub best_name_for_log {
 # for each user; earlier ones are irrelevant and don't count. But it
 # doesn't deduplicate across reactions. Meh.)
 sub create_reaction_log {
-       my ($dbh, $invitation_ts, $slack_userid_to_real_name, $slack_userid_to_slack_name) = @_;
+       my ($dbh, $channel, $invitation_ts, $interval, $slack_userid_to_real_name, $slack_userid_to_slack_name) = @_;
 
-       my $q = $dbh->prepare('select userid,event_type,reaction,to_char(event_ts,\'YYYY-mm-dd HH24:MI\') as event_ts from ( select distinct on (channel,ts,userid,reaction) userid,event_type,reaction,timestamptz \'1970-01-01 utc\' + event_ts::float * interval \'1 second\' as event_ts from reaction_log where channel=? and ts=? and reaction in (\'heart\',\'open_mouth\',\'blue_heart\',\'orange_heart\') order by channel,ts,userid,reaction,event_ts desc ) t1 where event_ts > current_timestamp - interval \'8 hours\' order by event_ts desc limit 50');
-       $q->execute($config::invitation_channel, $invitation_ts);
+       my $q = $dbh->prepare('select userid,event_type,reaction,to_char(event_ts,\'YYYY-mm-dd HH24:MI\') as event_ts from ( select distinct on (channel,ts,userid,reaction) userid,event_type,reaction,timestamptz \'1970-01-01 utc\' + event_ts::float * interval \'1 second\' as event_ts from reaction_log where channel=? and ts=? and reaction in (\'heart\',\'open_mouth\',\'blue_heart\',\'orange_heart\') order by channel,ts,userid,reaction,event_ts desc ) t1 where event_ts > current_timestamp - ?::interval order by event_ts desc limit 50');
+       $q->execute($channel, $invitation_ts, $interval);
        my @recent_changes = ();
        while (my $ref = $q->fetchrow_hashref) {
                my $msg = $ref->{'event_ts'};
@@ -840,15 +840,15 @@ sub run {
                }
        }
 
-       my @recent_changes = create_reaction_log($dbh, $invitation_ts, \%slack_userid_to_real_name, \%slack_userid_to_slack_name);
+       my @recent_changes = create_reaction_log($dbh, $config::invitation_channel, $invitation_ts, '8 hours', \%slack_userid_to_real_name, \%slack_userid_to_slack_name);
        push @yellow_updates, {
                updateCells => {
                        rows => \@recent_changes,
                        fields => 'userEnteredValue.stringValue',
                        range => {
                                sheetId => $config::log_tab_id,
-                               startRowIndex => 4,
-                               endRowIndex => 4 + scalar @recent_changes,
+                               startRowIndex => 3,
+                               endRowIndex => 3 + scalar @recent_changes,
                                startColumnIndex => 0,
                                endColumnIndex => 1
                        }
@@ -884,6 +884,21 @@ sub run {
                        }
                }
        };
+
+       my @hks_recent_changes = create_reaction_log($dbh, 'C06C34L2R6G', '1712686401.430939', '30 days', \%slack_userid_to_real_name, \%slack_userid_to_slack_name);
+       push @yellow_updates, {
+               updateCells => {
+                       rows => \@hks_recent_changes,
+                       fields => 'userEnteredValue.stringValue',
+                       range => {
+                               sheetId => $config::hks_tab_id,
+                               startRowIndex => 1,
+                               endRowIndex => 1 + scalar @hks_recent_changes,
+                               startColumnIndex => 3,
+                               endColumnIndex => 4
+                       }
+               }
+       };
        # END LOCAL CHANGE FOR HKS 2024
 
        # Push the final set of updates (including the log).