From b6a9efe6340d75eef76748421fe94029068127e4 Mon Sep 17 00:00:00 2001 From: Lewis Goddard Date: Thu, 25 Jul 2024 15:06:58 +0100 Subject: [PATCH] Delete _backend/Service/Slack.php (#3603) --- _backend/Service/Slack.php | 230 ------------------------------------- 1 file changed, 230 deletions(-) delete mode 100644 _backend/Service/Slack.php diff --git a/_backend/Service/Slack.php b/_backend/Service/Slack.php deleted file mode 100644 index 1635447ea6..0000000000 --- a/_backend/Service/Slack.php +++ /dev/null @@ -1,230 +0,0 @@ -$2'; - - $member['profile']['title'] = preg_replace($linkRegex, $linkReplace, $member['profile']['title']); - } - - return $member; - } - - /** - * Filters users based on having properties and being defined lists. - * - * @param array $members - * - * @return array - */ - protected static function filterUsers(array $members) - { - return array_filter($members, function ($member) { - if ($member['deleted'] === true) { - return false; - } - - if ($member['is_bot'] === true) { - return false; - } - - if (in_array($member['id'], static::$filterHiddenUsers)) { - return false; - } - - if (isset($member['profile']['title']) === false || trim($member['profile']['title']) == '') { - return false; - } - - return true; - }); - } - - /** - * Sorts users based on activity and name. - * - * @param array $members - * - * @return array - */ - protected static function sortUsers(array $members) - { - usort($members, function ($a, $b) { - // "I'm #1!" ~ Dan - if ($a['id'] == 'U029601AF') { - return -1; - } - if ($b['id'] == 'U029601AF') { - return 1; - } - - // Admin's first - if ($a['is_admin'] && ! $b['is_admin']) { - return -1; - } - if ($b['is_admin'] && ! $a['is_admin']) { - return 1; - } - - // Sort alphabetically - return strcasecmp($a['name'], $b['name']); - }); - - return $members; - } - - /** - * Creates a new Slack service class. - * - * @param string $key The API key to use - */ - public function __construct($key) - { - $this->key = $key; - } - - /** - * Grabs the API response. - * - * @param string $url - * - * @return array - */ - public function response($url) - { - $fullUrl = static::$url.$url.(strpos($url, '?') ? '&' : '?').'token='.$this->key; - - $apiContent = file_get_contents($fullUrl); - $apiResponse = json_decode($apiContent, true); - - if ($apiResponse['ok'] !== true) { - // TODO: Log some error here - } - - return $apiResponse; - } - - /** - * Returns a list of all non-blacklisted members in slack. - * - * @return array - */ - public function members() - { - $res = $this->response('/users.list'); - - if (isset($res['members']) === false) { - return array(); - } - - $members = $res['members']; - $members = array_map(array(static::class, 'sanatizeMember'), $members); - $members = static::filterUsers($members); - $members = static::sortUsers($members); - - return $members; - } - - /** - * Returns a list of users in the slack channel. - * - * @return array - */ - public function users() - { - return array_filter($this->members(), function ($member) { - return in_array($member['id'], static::$filterCommunityUsers) === false; - }); - } - - /** - * Returns a list of community members in the slack channel. - * - * @return array - */ - public function community() - { - return array_filter($this->members(), function ($member) { - return in_array($member['id'], static::$filterCommunityUsers); - }); - } -}