Changeset 10828
- Timestamp:
- 03/18/2021 03:11:43 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/slack/subgroup.php
r10824 r10828 21 21 } 22 22 23 // WARNING: Can only be called FIVE times per request. 24 function update_text( $text ) { 25 if ( empty( $_POST['response_url'] ) ) { 26 die( "response_url missing." ); 27 } 28 29 $payload = [ 30 'response_type' => 'ephemeral', 31 'replace_original' => 'true', // Doesn't work. 32 'text' => $text, 33 ]; 34 35 $context = stream_context_create( [ 'http' => [ 36 'method' => 'POST', 37 'header' => 'Content-Type: application/json', 38 'content' => json_encode( $payload ), 39 ] ] ); 40 41 file_get_contents( $_POST['response_url'], false, $context ); 42 } 43 44 function die_text( $text ) { 45 update_text( $text ); 46 die(); 47 } 48 23 49 // Confirm it came from Slack. 24 50 if ( $_POST['token'] !== WEBHOOK_TOKEN ) { 25 51 die( "Invalid Token" ); 26 52 } 53 54 // This API needs to return a successful 200 ASAP, within 3 seconds, and most of the API calls below will take longer than. 55 header( 'HTTP/1.0 200 OK' ); 56 flush(); 57 if ( function_exists( 'fastcgi_finish_request' ) ) { 58 fastcgi_finish_request(); 59 } 60 61 update_text( 'Please wait.. This could take a moment..' ); 27 62 28 63 $current_group_id = $_POST['channel_id']; … … 52 87 // Sorry - @wordpressdotorg isn't in this group. 53 88 if ( empty( $found ) ) { 54 die ( "@wordpressdotorg isn't here." );89 die_text( "@wordpressdotorg isn't here." ); 55 90 } 56 91 57 92 // Can't call this from a subgroup. 58 93 if ( $pos = strpos( $group['name'], '-' ) ) { 59 die ( sprintf( 'Call this from the main `%s` group.', substr( $group['name'], 0, $pos ) ) );94 die_text( sprintf( 'Call this from the main `%s` group.', substr( $group['name'], 0, $pos ) ) ); 60 95 } 61 96 … … 72 107 // Ensure the calling user is in the main group. 73 108 if ( ! in_array( $_POST['user_id'], $members, true ) ) { 74 die ;109 die_text( 'Unauthorized' ); 75 110 } 76 111 … … 81 116 case 'create': 82 117 if ( 0 !== strpos( $subcommand, $group['name'] . '-' ) ) { 83 die ( "Must create a group that starts with `{$group['name']}-`." );118 die_text( "Must create a group that starts with `{$group['name']}-`." ); 84 119 } 85 120 … … 93 128 ); 94 129 if ( empty( $new_group['ok'] ) ) { 95 die ( "Group creation failed. Does it already exist?" );130 die_text( "Group creation failed. Does it already exist?" ); 96 131 } 97 132 … … 122 157 ); 123 158 124 die ( sprintf( "Group %s created.", $new_group['group']['name'] ) );159 die_text( sprintf( "Group %s created.", $new_group['group']['name'] ) ); 125 160 126 161 case 'invite': … … 137 172 ); 138 173 139 die ( "Invited to {$group['name']}." );174 die_text( "Invited to {$group['name']}." ); 140 175 } 141 176 } 142 177 143 die ( "$subcommand group not found." );178 die_text( "$subcommand group not found." ); 144 179 145 180 case 'list': … … 167 202 168 203 if ( $groups_to_add ) { 169 echo"You may join any of these groups:\n -- `" . implode( "`\n -- `", $groups_to_add ) . "`\n\n\n";204 $text = "You may join any of these groups:\n -- `" . implode( "`\n -- `", $groups_to_add ) . "`\n\n\n"; 170 205 } else { 171 echo"You are in all {$parent_group['name']} subgroups that the @wordpressdotorg user knows about.\n\n";172 } 173 174 die ("*Help:*\n`/subgroup list` - display this message\n`/subgroup join {name}` - join a subgroup\n`/subgroup create {name}` - create a subgroup" );175 } 176 206 $text = "You are in all {$parent_group['name']} subgroups that the @wordpressdotorg user knows about.\n\n"; 207 } 208 209 die_text( $text . "*Help:*\n`/subgroup list` - display this message\n`/subgroup join {name}` - join a subgroup\n`/subgroup create {name}` - create a subgroup" ); 210 } 211
Note: See TracChangeset
for help on using the changeset viewer.