From c7eaa8703bfb90554dfe119cb49afe6d8546975f Mon Sep 17 00:00:00 2001 From: Yoshida Shunsuke Date: Tue, 14 Aug 2018 19:15:23 +0900 Subject: [PATCH 1/5] ISSHA-1329 add members fanction add all bot help option mention name from real_name or display_name --- pyconjpbot/plugins/misc.py | 64 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) mode change 100644 => 100755 pyconjpbot/plugins/misc.py diff --git a/pyconjpbot/plugins/misc.py b/pyconjpbot/plugins/misc.py old mode 100644 new mode 100755 index 0d48b85..b613009 --- a/pyconjpbot/plugins/misc.py +++ b/pyconjpbot/plugins/misc.py @@ -139,3 +139,67 @@ def cal_help(message): - `$cal 9`: 今年の指定された月のカレンダーを返す - `$cal 9 2016`: 指定された年月のカレンダーを返す ''') + + +@respond_to('^members$') +@respond_to('^members\s+(all|bot|help)$') +def members_command(message, subcommand=None): + """ + チャンネル参加者のメンション名の一覧を返す + + - https://github.com/os/slacker + - https://api.slack.com/methods/channels.info + - https://api.slack.com/methods/users.getPresence + - https://api.slack.com/methods/users.info + """ + + if subcommand == 'help': + botsend(message, '''- `$members`: チャンネルにいる通常の参加者のメンション名の一覧を返す +- `$members all`:チャンネルにいる全ての参加者のメンション名の一覧を返す +- `$members bot`:チャンネルにいるbotの参加者メンション名の一覧を返す +''') + return + + if subcommand == 'all': + desc = '全ての' + elif subcommand == 'bot': + desc = 'botの' + else: + desc = '通常の' + + # チャンネルのメンバー一覧を取得 + channel = message.body['channel'] + webapi = slacker.Slacker(settings.API_TOKEN) + cinfo = webapi.channels.info(channel) + members = cinfo.body['channel']['members'] + + # 作業用リスト初期化 + nameall = [] + + # メンバ一覧から順次処理 + for member_id in members: + user_info = webapi.users.info(member_id) + # real_nameまたはdisplay_nameにメンション用文字列が入っている推測 + basename = user_info.body['user']['profile']['real_name'] + display_name = user_info.body['user']['profile']['display_name'] + + # display_nameが設定されていればそれが優先されている推測 + if display_name != "": + basename = display_name + + if subcommand == 'all': + nameall.append(basename) + elif subcommand == 'bot': + if user_info.body['user']['is_bot']: + nameall.append(basename) + else: + # サブコマンドでなにも指定されなければ通常(botでない)ユーザのみ + if not user_info.body['user']['is_bot']: + nameall.append(basename) + + # 探しやすいように大小文字区別なしアルファベット順 + nameall.sort(key=str.lower) + + # 処理概要、一覧、Countを出力 + botsend(message, 'このチャンネルの{0}参加者一覧は\n{1}\n{2}参加者です。'.format( + desc, '\n'.join(nameall), len(nameall))) From f2c21440a236247dc4bc8d0e72401133d9130411 Mon Sep 17 00:00:00 2001 From: Yoshida Shunsuke Date: Sat, 2 Feb 2019 04:51:30 +0000 Subject: [PATCH 2/5] ISSHA-1329 ommit warning new command undefined messages --- pyconjpbot/plugins/term.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 pyconjpbot/plugins/term.py diff --git a/pyconjpbot/plugins/term.py b/pyconjpbot/plugins/term.py old mode 100644 new mode 100755 index 2bdd557..5486ea5 --- a/pyconjpbot/plugins/term.py +++ b/pyconjpbot/plugins/term.py @@ -12,7 +12,7 @@ 'translate', '翻訳', 'weather', '天気', 'term', - 'shuffle', 'help', 'choice', 'ping', 'version', 'random', 'cal', + 'shuffle', 'help', 'choice', 'ping', 'version', 'random', 'cal', 'members', 'google', 'image', 'map', 'gadmin', 'github', 'suddendeath', From 75e854447af33f16ac0d0ad31510dcb6659e3838 Mon Sep 17 00:00:00 2001 From: Yoshida Shunsuke Date: Sat, 2 Feb 2019 04:52:25 +0000 Subject: [PATCH 3/5] ISSHA-1329 update README --- README.md | 3 +++ 1 file changed, 3 insertions(+) mode change 100644 => 100755 README.md diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 50dc9d8..c0422e1 --- a/README.md +++ b/README.md @@ -235,6 +235,9 @@ BOT: @takanory おはようございます - `$cal`: 今月のカレンダーを返す - `$cal 9`: 今年の指定された月のカレンダーを返す - `$cal 9 2016`: 指定された年月のカレンダーを返す +- `$members`: チャンネルにいる通常の参加者のメンション名の一覧を返す +- `$members bot`: チャンネルにいるbotの参加者のメンション名の一覧を返す +- `$members all`: チャンネルにいる全ての参加者のメンション名の一覧を返す - [misc.py](https://github.com/pyconjp/pyconjpbot/blob/master/pyconjpbot/plugins/misc.py) ## How to build From 5d1a4e56400f89c360f983ffe5f75ae9b62ba2bf Mon Sep 17 00:00:00 2001 From: Yoshida Shunsuke Date: Sat, 2 Feb 2019 04:57:24 +0000 Subject: [PATCH 4/5] ISSHA-1329 update ChangeLog --- ChangeLog.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index db90286..7a4cd62 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,10 @@ Unreleased ---------- +Release Notes - 2019-02-02 +-------------------------- +- [ISSHA-1329] add members command + Release Notes - 2019-01-20 -------------------------- - [ISSHA-967] update lgtm command for top and bottom text From 9b884bfc6648d8131343dc72726710e6140bd5db Mon Sep 17 00:00:00 2001 From: Yoshida Shunsuke Date: Sat, 2 Feb 2019 06:28:34 +0000 Subject: [PATCH 5/5] fix typo algorithm --- pyconjpbot/plugins/misc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyconjpbot/plugins/misc.py b/pyconjpbot/plugins/misc.py index b613009..bdd687a 100755 --- a/pyconjpbot/plugins/misc.py +++ b/pyconjpbot/plugins/misc.py @@ -197,8 +197,8 @@ def members_command(message, subcommand=None): if not user_info.body['user']['is_bot']: nameall.append(basename) - # 探しやすいように大小文字区別なしアルファベット順 - nameall.sort(key=str.lower) + # 探しやすいように大小文字区別なしアルファベット順 + nameall.sort(key=str.lower) # 処理概要、一覧、Countを出力 botsend(message, 'このチャンネルの{0}参加者一覧は\n{1}\n{2}参加者です。'.format(