target_time = {hour=hour, min=minute, sec=second} function get_total_day_seconds (time_table) return (((time_table.hour * 60) + (time_table.min)) * 60) + time_table.sec end SECONDS_PER_DAY = get_total_day_seconds({hour=24, min=0, sec=0}) function get_sleep_duration_sec () current_time = os.time() current_time_table = os.date("*t", current_time) current_day_seconds = get_total_day_seconds(current_time_table) target_day_seconds = get_total_day_seconds(target_time) difference = target_day_seconds - current_day_seconds if difference > 0 then return difference else return SECONDS_PER_DAY + difference end end function get_weekday () return os.date("%a", current_time) end function sleep (sec) return os.execute("sleep " .. tonumber(sec)) end while true do sleep_duration = get_sleep_duration_sec() print("sleep for " .. sleep_duration) if not sleep(sleep_duration) then print("sleep exited abnormally - break") break end if get_weekday() == weekday then print("send message " .. message) sender:send({type = "message", channel = channel, message = message}) end end