Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

refs #56 slackbot バージョンアップ #200

Merged
merged 5 commits into from
Sep 9, 2020
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ $ (cd beproudbot/deployment && ~/venv_ansible/bin/ansible-playbook -i hosts --co

- `$water count`: 現在の残数を返す
- `$water num`: 水を取り替えた時に使用。指定した数だけ残数を減らす(numが負数の場合、増やす)
- `$water hitsory <num>`: 指定した件数分の履歴を返す(default=10)
- `$water history <num>`: 指定した件数分の履歴を返す(default=10)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[typo]

typo 修正

- `$water help`: このコマンドの使い方を返す

### kintai コマンド
Expand Down
4 changes: 2 additions & 2 deletions src/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ python-dateutil==2.6.1
python-editor==1.0.3
requests==2.18.4
six==1.11.0
slackbot==0.5.1
slacker==0.9.60
slackbot==1.0.0
slacker==0.14.0
Comment on lines +17 to +18
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[変更]

廃止予定のAPI channelsgroups の代わりに新しいほうのAPI conversations を使えるようにするため、バージョンアップしました

[参考]

https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api

SQLAlchemy==1.2.2
urllib3==1.22
websocket-client==0.44.0
Expand Down
18 changes: 8 additions & 10 deletions src/haro/plugins/random.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import random

from slackbot.bot import respond_to
Expand All @@ -13,14 +14,16 @@
- `$random help`: randomコマンドの使い方を返す
'''

logger = logging.getLogger(__name__)


@respond_to('^random$')
@respond_to('^random\s+(active|help)$')
def random_command(message, subcommand=None):
"""
チャンネルにいるメンバーからランダムに一人を選んで返す
- https://github.com/os/slacker
- https://api.slack.com/methods/channels.info
- https://api.slack.com/methods/conversations.members
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[変更]

channels.info => conversations.members に変更

[参考]

https://api.slack.com/methods/conversations.members

- https://api.slack.com/methods/users.getPresence
- https://api.slack.com/methods/users.info
"""
Expand All @@ -33,16 +36,11 @@ def random_command(message, subcommand=None):
channel = message.body['channel']
webapi = slacker.Slacker(settings.API_TOKEN)
try:
cinfo = webapi.channels.info(channel)
members = cinfo.body['channel']['members']
cinfo = webapi.conversations.members(channel)
Copy link
Contributor Author

@fumi232323 fumi232323 Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conversations.info だと、メンバー情報は取得できないため、 conversations. members を使用します

[参考]

https://api.slack.com/methods/conversations.info

members = cinfo.body['members']
except slacker.Error:
try:
cinfo = webapi.groups.info(channel)
members = cinfo.body['group']['members']
Copy link
Contributor Author

@fumi232323 fumi232323 Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conversations.members で private チャンネルのメンバーも取得できるので、こちらのくだりは削除

  • conversations.members は public, private, shared チャンネルのメンバーが取得できる。
  • 動作確認済み

except slacker.Error:
# TODO: 例外で判定しないように修正する
# チャンネルに紐付かない場合はreturn
return
logger.exception('An error occurred while fetching members: channel=%s', channel)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

エラー発生時は、ログを出力するようにしました。

return

# bot の id は除く
bot_id = message._client.login_data['self']['id']
Expand Down