Changeset 10823
- Timestamp:
- 03/17/2021 12:52:21 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/api.wordpress.org/public_html/dotorg/slack/subgroup.php
r2989 r10823 33 33 34 34 // Get a list of all groups @wordpressdotorg is in. 35 $groups = api_call( 'groups.list' )['groups']; 35 $groups = api_call( 36 // https://api.slack.com/methods/conversations.list 37 'conversations.list', 38 [ 39 'exclude_archived' => true, 40 'types' => 'private_channel', 41 'limit' => 999, 42 ] 43 ); 36 44 37 45 // Find the group that we are in right now. 38 foreach ( $groups as $group ) {46 foreach ( $groups['channels'] as $group ) { 39 47 if ( $group['id'] === $current_group_id ) { 40 48 $found = true; … … 66 74 die( "Must create a group that starts with `{$group['name']}-`." ); 67 75 } 68 69 $new_group = api_call( 'groups.create', array( 'name' => $subcommand ) ); 76 77 // Create the new private channel. 78 $new_group = api_call( 79 'conversations.create', 80 [ 81 'name' => $subcommand, 82 'is_private' => true, 83 ] 84 ); 70 85 if ( empty( $new_group['ok'] ) ) { 71 86 die( "Group creation failed. Does it already exist?" ); 72 87 } 73 74 foreach ( $group['members'] as $member ) { 75 api_call( 'groups.invite', array( 'channel' => $new_group['group']['id'], 'user' => $member ) ); 88 89 // Post a message to the parent channel about this channels creation. 90 api_call( 91 // https://api.slack.com/methods/chat.postMessage 92 'chat.postMessage', 93 [ 94 'channel' => $group['id'], 95 'text' => sprintf( 96 'Group %s created by <@%s>.', 97 $new_group['group']['name'], 98 $_POST['user_id'] 99 ), 100 'as_user' => true, 101 ] 102 ); 103 104 // Invite all current parent channel members to the new channel. 105 $members = api_call( 106 // https://api.slack.com/methods/conversations.members 107 'conversations.members', 108 [ 109 'channel' => 'CMYKV0D7B', 110 'limit' => 999, 111 ] 112 ); 113 if ( empty( $members['members'] ) ) { 114 die( sprintf( "Group %s created, but could not invite members.", $new_group['group']['name'] ) ); 76 115 } 77 78 api_call( 'chat.postMessage', array( 79 'channel' => $group['id'], 80 'text' => sprintf( 'Group %s created by <@%s>.', $new_group['group']['name'], $_POST['user_id'] ), 81 'as_user' => true, 82 ) ); 116 117 api_call( 118 // https://api.slack.com/methods/conversations.invite 119 'conversations.invite', 120 [ 121 'channel' => $new_group['group']['id'], 122 'users' => implode( ',', $members['members'] ), 123 ] 124 ); 83 125 84 126 die( sprintf( "Group %s created.", $new_group['group']['name'] ) ); … … 88 130 foreach ( $groups as $group ) { 89 131 if ( $group['name'] === $subcommand ) { 90 api_call( 'groups.invite', array( 'channel' => $group['id'], 'user' => $_POST['user_id'] ) ); 132 api_call( 133 // https://api.slack.com/methods/conversations.invite 134 'conversations.invite', 135 [ 136 'channel' => $group['id'], 137 'users' => $_POST['user_id'], 138 ] 139 ); 140 91 141 die( "Invited to {$group['name']}." ); 92 142 } 93 143 } 94 144 95 145 die( "$subcommand group not found." ); 96 146 97 147 case 'list': 98 148 default: 99 149 $groups_to_add = array(); 100 150 101 151 $parent_group = $group; 102 152 foreach ( $groups as $group ) { … … 107 157 } 108 158 } 109 159 110 160 if ( $groups_to_add ) { 111 161 echo "You may join any of these groups:\n -- `" . implode( "`\n -- `", $groups_to_add ) . "`\n\n\n"; … … 113 163 echo "You are in all {$parent_group['name']} subgroups that the @wordpressdotorg user knows about.\n\n"; 114 164 } 115 165 116 166 die( "*Help:*\n`/subgroup list` - display this message\n`/subgroup join {name}` - join a subgroup\n`/subgroup create {name}` - create a subgroup" ); 117 167 } 118 168
Note: See TracChangeset
for help on using the changeset viewer.