Making WordPress.org


Ignore:
Timestamp:
07/14/2015 03:49:50 AM (9 years ago)
Author:
nacin
Message:

Slack: Add /here support to the /announce command library.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/common/includes/slack/announce/lib.php

    r1191 r1738  
    4040    $channels = get_whitelisted_channels_for_user( $user ) ;
    4141    if ( $channel === 'privategroup' ) {
    42         echo "Any private group members can use /announce in this group.";
     42        echo "Any private group members can use /announce and /here in this group.";
    4343        return;
    4444    } elseif ( empty( $channels ) ) {
    45         echo "You are not allowed to use /announce.";
     45        echo "You are not allowed to use /announce or /here.";
    4646    } elseif ( in_array( $channel, $channels ) ) {
    4747        $channels = array_filter( $channels, function( $c ) use ( $channel ) { return $c !== $channel; } );
    4848        if ( $channels ) {
    49             printf( "You are allowed to use /announce in #%s (also %s).", $channel, '#' . implode( ' #', $channels ) );
     49            printf( "You are allowed to use /announce and /here in #%s (also %s).", $channel, '#' . implode( ' #', $channels ) );
    5050        } else {
    51             echo "You are allowed to use /announce in #$channel.";
     51            echo "You are allowed to use /announce and /here in #$channel.";
    5252        }
    5353    } else {
    54         printf( "You are not allowed to use /announce in #%s, but you are in #%s.", $channel, implode( ' #', $channels ) );
     54        printf( "You are not allowed to use /announce or /here in #%s, but you are in #%s.", $channel, implode( ' #', $channels ) );
    5555    }
    5656
     
    7373    $send = new Send( \Dotorg\Slack\Send\WEBHOOK );
    7474    $send->set_username( $user );
    75     $send->set_text( sprintf( "<!channel> %s", $data['text'] ) );
     75
     76    $command = 'channel';
     77    if ( $data['command'] === '/here' ) {
     78        $command = 'here';
     79    } elseif ( $channel === 'privategroup' ) {
     80        // @channel and @group are interchangeable, but still.
     81        $command = 'group';
     82    }
     83
     84    $send->set_text( sprintf( "<!%s> %s", $command, $data['text'] ) );
    7685
    7786    $get_avatar = __NAMESPACE__ . '\\' . 'get_avatar';
Note: See TracChangeset for help on using the changeset viewer.