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

Commit

Permalink
Merge pull request #200 from beproud/t56-upgrade-slackbot
Browse files Browse the repository at this point in the history
refs #56 slackbot バージョンアップ
  • Loading branch information
fumi232323 authored Sep 9, 2020
2 parents 4326492 + 4104416 commit 2b3d713
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
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)
- `$water help`: このコマンドの使い方を返す

### kintai コマンド
Expand Down
6 changes: 3 additions & 3 deletions src/constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ geopy==1.11.0
idna==2.6
kml2geojson==4.0.2
Mako==1.0.7
MarkupSafe==1.0
MarkupSafe==1.1.1
Pillow==5.2.0
prettytable==0.7.2
PyMySQL==0.7.11
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
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
- 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)
members = cinfo.body['members']
except slacker.Error:
try:
cinfo = webapi.groups.info(channel)
members = cinfo.body['group']['members']
except slacker.Error:
# TODO: 例外で判定しないように修正する
# チャンネルに紐付かない場合はreturn
return
logger.exception('An error occurred while fetching members: channel=%s', channel)
return

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

0 comments on commit 2b3d713

Please sign in to comment.