class Ruboty::Handlers::Attendance
Constants
- NAMESPACE
- ROLE
Public Instance Methods
absent_user(message)
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 95 def absent_user(message) begin message.reply(divide_user(:absent, message)) rescue => e message.reply(e.message) end end
all_attendance(message)
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 75 def all_attendance(message) begin result_message = "All channel event is here\n" attend_ch.keys.each do |ch_num| result_message += current_message(ch_num) end message.reply(result_message) rescue => e message.reply(e.message) end end
attend_status(message)
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 54 def attend_status(message) begin current_ch = message[:ch].to_i message.reply(current_message(current_ch)) rescue => e message.reply(e.message) end end
attend_user(message)
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 87 def attend_user(message) begin message.reply(divide_user(:attend, message)) rescue => e message.reply(e.message) end end
close_attendance(message)
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 63 def close_attendance(message) begin current_ch = message[:ch].to_i result_message = current_message(current_ch) attend_table.delete(current_ch) attend_ch.delete(current_ch) message.reply(result_message) rescue => e message.reply(e.message) end end
create_attendance(message)
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 43 def create_attendance(message) begin new_ch_num = create_new_chx attend_table[new_ch_num] = {} attend_ch[new_ch_num] = message[:desc] message.reply("Create new channel event!\n Ch.No. -> #{new_ch_num}, Detail -> #{attend_ch[new_ch_num]}") rescue => e message.reply(e.message) end end
Private Instance Methods
attend_ch()
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 139 def attend_ch robot.brain.data[NAMESPACE + "_ch"] ||= {} end
attend_table()
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 135 def attend_table robot.brain.data[NAMESPACE + "_table"] ||= {} end
ch_exist?(ch_num)
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 116 def ch_exist?(ch_num) attend_table[ch_num].nil? end
create_new_ch()
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 143 def create_new_ch (1..100).to_a.select {|num| !attend_ch.keys.include?(num)}.first end
current_message(current_ch)
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 120 def current_message(current_ch) if ch_exist?(current_ch) return "Ch.#{current_ch} does not exist." end attend_counter = 0 ret_message = "[Ch.#{current_ch}, #{attend_ch[current_ch]}]\n" attend_table[current_ch].each do |key, val| ret_message += "#{key.to_s}: #{ROLE[val]}\n" attend_counter += 1 if val == :attend end ret_message + "num of attend user: #{attend_counter}\n" end
divide_user(state, message)
click to toggle source
# File lib/ruboty/handlers/attendance.rb, line 105 def divide_user(state, message) current_ch = message[:ch].to_i if ch_exist?(current_ch) return "Ch.#{current_ch} does not exist." end attend_table[current_ch].merge!({ message.from_name => state }) "#{attend_ch[current_ch]}に#{ROLE[state]}っ!" end