From 39624c885da4d7903c7e685e4fcb50dafb4698d1 Mon Sep 17 00:00:00 2001 From: hirata Date: Thu, 12 Jun 2025 21:39:08 +0900 Subject: [PATCH] Update attendance command to be able to execute with a user name. --- lib/swimmy/command/attendance.rb | 37 ++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/swimmy/command/attendance.rb b/lib/swimmy/command/attendance.rb index 5ea8a94..c323fde 100644 --- a/lib/swimmy/command/attendance.rb +++ b/lib/swimmy/command/attendance.rb @@ -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") @@ -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