Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions lib/swimmy/command/attendance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ class Attendance < Swimmy::Command::Base
command 'hi', 'bye' do |client, data, match|

cmd = match[:command]
arg = match[:expression]
now = Time.now
user = client.web_client.users_info(user: data.user).user
user_id = user.id
user_name = user.profile.display_name

case parse_arg(arg)
when "do_current_user"
# if no argument
user_name = user.profile.display_name
when "do_specified_user"
# if the user specified in the argument is active
user_name = arg
when "not_active_user"
# if the user specified in the argument is not active
msg = "ユーザ #{arg}は現役メンバではありません."
client.say(channel: data.channel, text: msg)
next
end

# log to spreadsheet
now_s = now.strftime("%Y-%m-%d %H:%M:%S")
Expand All @@ -36,8 +50,27 @@ class Attendance < Swimmy::Command::Base
title "attendance"
desc "hi/bye で入退室をスプレッドシートに記録し,ドアプレートを更新します"
long_desc "attendance (hi|bye)\n" +
"もしくは,メンションで hi/bye だけでも OK です."
"もしくは,メンションで hi/bye だけでも OK です.\n" +
"attendance (hi|bye) [MEMBER]\n" +
"[MEMBER] を指定して,attendance コマンドを実行します"
end

def self.parse_arg(arg)
# judge if the user is specified in the argument
active_members = spreadsheet.sheet("members", Swimmy::Resource::Member).fetch.select {|m| m.active? }.map {|m| m.account }

case arg
in nil
# return "do_current_user" if arg is not specified
return "do_current_user"
in String => s if active_members.include?(s)
# return "do_specified_user" if the user specified in the argument is active
return "do_specified_user"
else
# return "not_active_user" if the user specified in the argument is not active
return "not_active_user"
end
end # method parse_arg
end # class Attendance
end # module Command
end # module Swimmy